-
Notifications
You must be signed in to change notification settings - Fork 79
Ability to Mock Multiple Dapper Calls at a Time #28
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
Comments
Hi @steventmayer, I may have some time in December to look at this, from a first glance at the specs, I would check the behaviour of Moq in this case, I have a feeling that it overrides the previous setup, too. One way to get around this would be to add a |
Let me try playing around with |
Thanks, I'll do my best to find some time to look at the PR as soon as possible. |
Do you mind if I ask for a simple sample? |
@steventmayer @UnoSD @shahabganji Did this get resolved? |
@steventmayer @UnoSD would like an update on the status of this if possible. Thanks |
Is there a solution to this yet? |
I haven't ran into one myself and our unfortunate result so far is omitting the functions from code coverage. Looks as if this repo is finished as the owner hasn't been active here or on GitHub in a long time. |
[Test]
public void Callback()
{
var connection = new Mock<IDbConnection>();
int[] firstExpected = { 15 };
int[] secondExpected = { 20 };
IEnumerable<int> expected = firstExpected;
connection.SetupDapper(x => x.Query<int>(It.IsAny<string>(), null, null, true, null, null))
.Returns(() => expected)
.Callback(() => expected = secondExpected);
var firstActual = connection.Object.Query<int>("");
Assert.That(firstActual, Is.EquivalentTo(firstExpected));
var secondActual = connection.Object.Query<int>("");
Assert.That(secondActual, Is.EquivalentTo(secondExpected));
} this may work as a solution. getting it to work appears to be way more complicated than I thought; it's hard to get the previous return value from Moq even with reflection and the ugly alternative is to keep a dictionary of the mocks and return values. I'm going for the hack, but new problems are bubbling up |
Is there any update on this issue please?
When apply the second setup, it overrides the first mock setup, even if T is different |
@yogeshk97 at the moment I do not have the capacity for working on the repo, but I welcome PRs and I am happy to review. |
I am attempting to test a feature that relies on multiple QueryAsync; however, when apply the second setup, it overrides the first mock setup, even if T is different. I was hoping that it would work differently for different T's or by changing the SQL statement, but no luck. Code looks like this.
var mock = new Mock();
mock.SetupDapperAsync(c => c.QueryAsync(It.IsAny(), null, null, null, null)).ReturnsAsync(object1);
mock.SetupDapperAsync(c => c.QueryAsync(It.IsAny(), null, null, null, null)).ReturnsAsync(object2);
var expected = object1;
var actual = mock.Object.Query("", null, null, null, null).ToList(); // shows up as Object2.
I'll ask on SO to see if I'm missing something. Thanks for this great library.
The text was updated successfully, but these errors were encountered: