I needed the same thing too, and I ended up writing this extension method that works for me:
public static class MoqExtensions { public static void Returns<TMock,TResult>(this ISetup<TMock, TResult> source, params TResult[] results) where TMock : class { int currentResultIndex = 0; source.Returns (() => { if(currentResultIndex >= results.Length) { currentResultIndex = 0; } return results [currentResultIndex++]; }); } }
And an example of use:
someMock.Setup(o => o.AMethodWithReturnTypeInt()).Returns(1, 2, 3, 4);
For this example, if you name a shrouded method - for example, 6 times, it will return 1, 2, 3, 4, 1, 2, respectively.
Hope this helps ...
source share