UnoSD / Moq.Dapper

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

Unable to chain ReturnsAsync with Verifiable #67

Open blake-mealey opened 4 years ago

blake-mealey commented 4 years ago

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 commented 3 years ago

I am also having this problem.

harvzor commented 1 year ago

Similar to https://github.com/UnoSD/Moq.Dapper/issues/30.

shanks92 commented 10 months ago

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.