Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException when using .Callback #52

Open
oskaremil opened this issue Nov 22, 2019 · 5 comments
Open

NullReferenceException when using .Callback #52

oskaremil opened this issue Nov 22, 2019 · 5 comments

Comments

@oskaremil
Copy link

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
Copy link

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
Copy link

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

@dubstepadii
Copy link

Issue still appears

@akrasp
Copy link

akrasp commented Apr 19, 2022

Still the same issue

@leontyl
Copy link

leontyl commented Jan 31, 2023

Nothing changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants