Reputation: 2228
I am trying to mock a method which takes two parameters int and out parameter of bool. I am able to set it up correctly for the first time invocation and it returns the right out value and return value. However, when trying to invoke the same method for the second time it is not invoking my delegate. Any idea what is wrong here:
What I tried:
mock.GetRows(Arg.Is<int>(10), out moreRows).Returns(x =>
{
if (first)
{
first = false;
x[1] = true;
return new object[][] { new object[] { null, "Collêction Namê" }, new object[] { null, "Collêction Name" }, new object[] { null, "COllection Name" } };
}
else
{
x[1] = false;
return new object[][] { new object[] { collectionId, "Collection Name" } };
}
});
I tried this as well:
mock.GetRows(Arg.Is<int>(10), out moreRows).Returns(
x =>
{
first = false;
x[1] = true;
return new object[][] { new object[] { null, "Collêction Namê" }, new object[] { null, "Collêction Name" }, new object[] { null, "COllection Name" } };
},
x=>
{
x[1] = false;
return new object[][] { new object[] { collectionId, "Collection Name" } };
});
This works however:
.ReturnsForAnyArgs(x =>
{
if (first)
{
first = false;
x[1] = true;
return new object[][] { new object[] { null, "Collêction Namê" }, new object[] { null, "Collêction Name" }, new object[] { null, "COllection Name" } };
}
else
{
x[1] = false;
return new object[][] { new object[] { collectionId, "Collection Name" } };
}
});
Upvotes: 0
Views: 220
Reputation: 10464
The problem with mocking out
parameters is that the value changes each call, so that the call initially stubbed with Returns
is no longer matched.
You have correctly identified the workaround of using ReturnsForAnyArgs
, as described in this answer.
Upvotes: 1