Moq.Dapper icon indicating copy to clipboard operation
Moq.Dapper copied to clipboard

Do not support for multimapping

Open RajuIpl opened this issue 6 years ago • 10 comments

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);

RajuIpl avatar May 27 '18 00:05 RajuIpl

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

WesJones127 avatar Sep 16 '18 22:09 WesJones127

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

DMEvans avatar Dec 10 '18 12:12 DMEvans

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

debslord avatar Dec 10 '18 12:12 debslord

I have same problem. Have anyone solved this issue?

imad-mn avatar Feb 09 '21 20:02 imad-mn

Same issue, any updates?

Same issue

upatel-eml avatar Sep 02 '22 00:09 upatel-eml

I have same problem. Have anyone solved this issue?

satyarth1111 avatar Sep 05 '22 12:09 satyarth1111

This project seems to be dead. Any alternative guys ?

Enissay avatar Oct 22 '22 16:10 Enissay

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

MeaningOfLights avatar Nov 09 '22 06:11 MeaningOfLights

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");

v-bafa avatar Apr 25 '23 04:04 v-bafa