Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FakeItEasy Returns different value for subsequent calls to the mock method

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("")
like image 660
Muthaiah PL Avatar asked Oct 25 '25 00:10

Muthaiah PL


1 Answers

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();
like image 162
Blair Conrad Avatar answered Oct 26 '25 13:10

Blair Conrad