UnoSD / Moq.Dapper

Moq extensions for Dapper methods.
GNU General Public License v2.0
173 stars 78 forks source link

Do not support for multimapping #20

Open RajuIpl opened 6 years ago

RajuIpl commented 6 years ago

Am trying to mock multimapping using this library and am not getting the support for the same. Here is the multi mapping query. `string sql = "SELECT * FROM Invoice AS A INNER JOIN InvoiceDetail AS B ON A.InvoiceID = B.InvoiceID;";

using (var connection = My.ConnectionFactory()) { connection.Open();

var invoices = connection.Query<Invoice, InvoiceDetail, Invoice>(
        sql,
        (invoice, invoiceDetail) =>
        {
            invoice.InvoiceDetail = invoiceDetail;
            return invoice;
        },
        splitOn: "InvoiceID")
    .Distinct()
    .ToList();

}`

Am trying to Mock this using the below code but am not able to achieve this? Can you resolve this as this methods everybody uses. mockConnection.SetupDapper(c => c.Query<Invoice, InvoiceDetail, Invoice>(It.IsAny<string>(), null, null, null, true, "", null)) .Returns(fakeInvoice);

WesJones127 commented 6 years ago

I'm having the same problem. Has anyone solved this?

DMEvans commented 5 years ago

I've come across this issue also. Has anyone found a workaround for this?

debslord commented 5 years ago

I am also having issues writing tests around this. Anyone else managed to get test this functionality?

imad-mn commented 3 years ago

I have same problem. Have anyone solved this issue?

samuel-sanchez-riseinteractive commented 3 years ago

Same issue, any updates?

upatel-eml commented 2 years ago

Same issue

satyarth1111 commented 2 years ago

I have same problem. Have anyone solved this issue?

Enissay commented 2 years ago

This project seems to be dead. Any alternative guys ?

MeaningOfLights commented 1 year ago

I've asked the same question here: https://stackoverflow.com/q/74370722/495455, hopefully in the future the solution is simple!

v-bafa commented 1 year ago

When trying to mock the multi-mapping query with following code, but did not get expected value.

connection.SetupDapper(c => c.Query<obj1, obj2, obj1>(
                It.IsAny<string>(),
                It.IsAny<Func<obj1, obj2, obj1>>(),
                It.IsAny<It.IsAnyType>(),
                It.IsAny<IDbTransaction>(), It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<CommandType>()))
              .Returns(expectedListOfObj1);

Only the int properties returns correctly, but string properties returns null.

var queryStr = "Select * from obj1 left join obj2 on obj2.obj2Id = obj1.obj2Id Where obj1value = @obj1value";

var actual= dbConnection.Query<obj1, obj2, obj1>(
              queryStr, 
             (a, t) => {
                a.obj2 = obj2; return obj1;
            }, 
            new { obj1value }, 
            splitOn: "obj2Id");