I've left some comments on Tim's post but they're
not approved yet so I'm not sure if others can see 'em.
Anyway, I think we could have two versions of this
method (either in the core or in a contrib project):
public static IReturnsResult<TMock>
ReturnsInOrder<TMock, TResult>(this ISetup<TMock, TResult> setup,
params Func<TResult>[] valueFunctions) where TMock :
class
{
var functionQueue = new
Queue<Func<TResult>>(valueFunctions);
return
setup.Returns(() => functionQueue.Dequeue()());
}
public static IReturnsResult<TMock>
ReturnsInOrder<TMock, TResult>(this ISetup<TMock, TResult> setup,
params TResult[] valuess) where TMock : class
{
var
functionQueue = new Queue<TResult>(values);
return
setup.Returns(() => functionQueue.Dequeue()());
}
In other words, a "lazy" one that takes an array of
functions, and an "immediate" one that takes an array of TResult.
Also note that you can just pass the array directly
into the Queue's constructor which saves a line of code and maybe some CLR
instructions.
Matt
ps. This code wouldn't actually compile for me so
I'm guessing it's for Moq 3.x (we're still using the older release). I've
ported it to Moq 2.x too, if anyone's interested.