UnoSD / Moq.Dapper

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

Doesn't support Moq verify #30

Open bmccord opened 5 years ago

bmccord commented 5 years ago

After doing something like this:

connection.SetupDapper(c => c.Query<int>(It.IsAny<string>(), It.IsAny<InvoiceLine>(), null, true, null, null)).Returns(new List<int>());

Then trying to do:

connection.Verify(s => s.Query<int>(It.IsAny<string>(), It.IsAny<InvoiceLine>(), null, true, null, null), Times.Exactly(invoice.InvoiceLines.Count()));

The verify fails with a hard error...it's understandable, because the Query method doesn't really exist. Is there any way to make a verify work?

davemcmanus commented 5 years ago

Verify( ) support is highly desired.

UnoSD commented 5 years ago

I won't happen soon as I find myself with less and less time and there are only two "active" (not really) contributors to this repo counting me as one; you are absolutely right though, there should be a way of verifying the calls and it shouldn't be that hard to implement, I will get to it as soon as I have the chance.

EricRohlfs commented 4 years ago

I would like to contribute and work on verify. Spent an hour looking around figured my first stab would be to create a VerifyDapper(exp) extension method that crawls the stack looking for the command object that matches the expression, then call verify. Is that the best way to tackle this issue?

cnn.VerifyDapper(x=>x.foo(It.IsAny<int>()),Times.Once);

UnoSD commented 4 years ago

@EricRohlfs thank you for your interest in contributing.

what do you mean by "crawling the stack"?

If I had to implement it, I would probably store the details of each call on the mock object and have the logic in "VerifyDapper" to parse the expression and try and find the details in the storage (dictionary or whatever in memory storage). Possibly it would help to see how Moq does it for other stuff.

RenFontes commented 2 months ago

We actually need this. Any idea of how to implement it? I can try to do it.