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

NullReferenceException when using .Callback

Open oskaremil opened this issue 5 years ago • 6 comments

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

oskaremil avatar Nov 22 '19 13:11 oskaremil

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.

KurtKroeker avatar Apr 29 '20 12:04 KurtKroeker

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

dnovhorodov avatar Oct 05 '20 09:10 dnovhorodov

Issue still appears

dubstepadii avatar Mar 19 '21 12:03 dubstepadii

Still the same issue

akrasp avatar Apr 19 '22 19:04 akrasp

Nothing changed.

leontyl avatar Jan 31 '23 20:01 leontyl