Reputation: 11957
I'm looking for a way to mock a method so that when called multiple times, the result is different. More specifically what i'm after, is to mock a method so that the third time it is called, I want to assert against that result.
This syntax is not correct, but simulates what I want to accomplish:
var foo = Fixture.Freeze<IFoo>();
foo.Exists(Arg.Any<object>()).Returns("firstcall").SecondCall("secondcall").ThirdCall("thirdcall");
Can you do this in AutoFixture?
EDIT: As pointed out by Mark this is a question related to NSubstitute rather than AutoFixture itself. I've updated the title.
Upvotes: 2
Views: 1529
Reputation: 11957
I found out the answer before submitting the question, so I'll post the answer here:
Fixture.Freeze<IFoo>()
.Exists(Arg.Any<object>())
.Returns("default", "firstcall", "secondcall", "thirdcall");
Now when Exists()
is called three times, the response will be "firstcall"
then "secondcall"
then "thirdcall"
. Any call after this will receive "default"
.
Upvotes: 6