UnoSD / Moq.Dapper

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

NullReferenceException when using .Callback #52

Open oskaremil opened 4 years ago

oskaremil commented 4 years ago

I have tried to attach a callback method to assert generated SQL sent.

            connectionMock
                .SetupDapperAsync(x => x.QueryAsync<Instant StartTime, long SecondCount)>(
                    It.IsAny<string>(),
                    It.IsAny<Parameters>(),
                    null, null, null))
                .Callback(
                    (string sql, Parameters, IDbTransaction transaction, int? commandTimeOut, CommandType? commandType) =>
                    {
                        // Assert
                    })
                .ReturnsAsync(new (Instant StartTime, long SecondCount)[0]);

I get the message System.NullReferenceException : Object reference not set to an instance of an object. on the same line as connectionMock.SetupDapperAsync is called.

Is this supported ?

The other parts work, if I remove the .Callback function everything runs fine

KurtKroeker commented 4 years ago

We just started using Moq.Dapper in our code, and we're having the same issue. Everything works great for mocking the Dapper function calls, but unfortunately attaching the callback fails, making verification that the mock was called difficult.

dnovhorodov commented 4 years ago

Same issue here. Defined callback call with lambda after .SetupDapperAsync returns System.NullReferenceException

dubstepadii commented 3 years ago

Issue still appears

akrasp commented 2 years ago

Still the same issue

leontyl commented 1 year ago

Nothing changed.

heynineteen commented 1 month ago

This is still a problem. Any idea of when this can be looked at?