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

Unable to chain ReturnsAsync with Verifiable #67

Open
blake-mealey opened this issue Oct 9, 2020 · 3 comments
Open

Unable to chain ReturnsAsync with Verifiable #67

blake-mealey opened this issue Oct 9, 2020 · 3 comments

Comments

@blake-mealey
Copy link

Hey, I am having some difficulty with one of my mocks. I want to do this:

var dbConnectionMock = new Mock<DbConnection>(MockBehavior.Loose);
dbConnectionMock.SetupDapperAsync(m =>
        m.QueryAsync(It.IsAny<string>(), It.IsAny<object>(), null, null, CommandType.StoredProcedure))
        .ReturnsAsync(new List<dynamic>()).Verifiable();

But when I do, I get NullReferenceException because somehow ReturnsAsync is returning null. I also can't do .Verifiable().ReturnsAsync(...) because Verifiable is void. (This seems like it shouldn't be affected by Moq.Dapper since this method is from the core library, but I can only reproduce this issue when using Moq.Dapper)

I have been able to get it working like this:

var dbConnectionMock = new Mock<DbConnection>(MockBehavior.Loose);
var mock = dbConnectionMock.SetupDapperAsync(m =>
        m.QueryAsync(It.IsAny<string>(), It.IsAny<object>(), null, null, CommandType.StoredProcedure));
mock.ReturnsAsync(new List<dynamic>());
mock.Verifiable();

But I'd rather not have to spread it out like that since usually the setup is chainable.

Any suggestions?

@Myrnedraith
Copy link

I am also having this problem.

@harvzor
Copy link

harvzor commented Apr 20, 2023

Similar to #30.

@shanks92
Copy link

Hey, I am also having an issue when I use .verifiable(times."any count"). It always returns true no matter what the times count is set.

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

4 participants