chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Behavior sequencing is quite a good feature. But let's say I for a call, I need to return mock values for the first N calls, after that all the call must be original, is there anyway to do this?

public class MockSome
{
   public int ReturnTen()
{  
   return 10;
}

}

[Test, Isolated]
public void TestMockSome()
{
   MockSome ms= new MockSome();
   Isolate.WhenCalled(()=>ms.ReturnTen()).WillReturn(11));
  //how to mock so that subsequent calls are real call
  Assert.AreEqual(11, ms.ReturnTen());
  Assert.AreEqual(10, ms.ReturnTen());
}

________
Caodaism Forums
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Yes there is a way to make N calls with WillReturn and then CallOriginal:
[Test, Isolated]
public void TestMockSome()
{
   MockSome ms= new MockSome();
   Isolate.WhenCalled(()=>ms.ReturnTen()).WillReturn(11));

  //This is how to mock so that subsequent calls are real call
   Isolate.WhenCalled(()=>ms.ReturnTen()).CallOriginal());

  Assert.AreEqual(11, ms.ReturnTen());
  Assert.AreEqual(10, ms.ReturnTen());
}


And you can use WillReturnRecursiveFakes as well
answered by dhelper (11.9k points)
...