3

I have a function called GetNumber() in Math class. I would like to return 1 for the first call, 2 for the second call and so on. I have done this in Mockito something like this

when(mathObj.GetNumber()).thenReturn(1).thenReturn(2).thenReturn(3);

How can I do the same with FakeItEasy

A.CallTo( () => mathObj.GetNumber()).Returns("")
Muthaiah PL
  • 1,048
  • 3
  • 15
  • 26

1 Answers1

6

See Return Values Calculated at Call Time and Changing behavior between calls for a few examples. One option is

A.CallTo(() => mathObj.GetNumber()).ReturnsNextFromSequence(1, 2, 3);

another is

A.CallTo(() => mathObj.GetNumber())
    .Returns(1).Once()
    .Then
    .Returns(2).Once()
    .Then
    .Returns(3).Once();
Blair Conrad
  • 233,004
  • 25
  • 132
  • 111