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 #1057

Closed
blake-mealey opened this issue Sep 18, 2020 · 2 comments
Closed

Unable to chain ReturnsAsync with Verifiable #1057

blake-mealey opened this issue Sep 18, 2020 · 2 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. (Note I am using the Moq.Dapper library here, but this seems unrelated to me since the method causing my issue is from the core library)

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?

@stakx
Copy link
Contributor

stakx commented Sep 27, 2020

You definitely shouldn't have to spread out a setup like that. But it's hard to tell what's going wrong here since SetupDapperAsync isn't part of Moq. Can you please provide example repro code that does not use any Moq extensions? (If you can only reproduce the problem using some 3rd-party extension library, you probably need to ask at their repository.)

@blake-mealey
Copy link
Author

Sorry for the slow reply. I think you're right - it seems to be caused by the other library. I'll close this issue

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

No branches or pull requests

2 participants