c# - Setup two different return values for two invocations of the same method -


suppose have following scenario:

public interface ifoo {     int getnextnumber(); }  public class foo : ifoo {     public int getnextnumber()     {         // returns next number. logic of getting next number not importaint     } } 

now, method want test:

public void methodtotest(ifoo foo)     {         int first = foo.getnextnumber();         int second = foo.getnextnumber();     } 

how can setup mock, pass methodtotest, first call of method returns 1 , second call return 2, example. tricky part 2 calls of method indistinguishable, don't know how setup them in somesort of 'order of execution'

edit: using moq

you make class implements interface , increments value each time call method

public class testfoo : ifoo {     private static int i;     public int getnextnumber()     {         return i++;     } } 

Comments