Return different objects from FakeItEasy A.CallTo()

fakeiteasy, unit-testing

Solution

Two ways to do it, one of them is the one you refer to in your own answer:

A.CallTo(() => foo.Bar()).ReturnsNextFromSequence(new[] { response1, response2 });

The other way is:

A.CallTo(() => foo.Bar()).Returns(response2);
A.CallTo(() => foo.Bar()).Returns(response1).Once();

Problem

For my test, I need the first call to a stub to return one object, and the next call to return a different object. I have seen this in other mock object frameworks in record() blocks, but I have not figured out how to do it in FakeItEasy. FakeItEasy is the mandated framework in our shop, and I am using AutoFixture to generate fakes. I looked at NextCall, but it doesn't look like I can specify a return value. Here is an idea of what I'd like to do: ``` ReceiveMessageResponse queueResponse1 = fixture.Create<ReceiveMessageResponse>(); ReceiveMessageResponse queueResponse2 = fixture.Create<ReceiveMessageResponse>(seed); A.CallTo(() => sqsClient.ReceiveMessage(null)).WithAnyArguments().Returns(queueResponse1); //The following should happen the second time... A.CallTo(() => sqsClient.ReceiveMessage(null)).WithAnyArguments().Returns(queueResponse2); ``` Any help is appreciated.

Original source