Reputation: 1499
I want to check that a specific method is called N times, first with arg x1, then x2, then x3, etc. and finally with arg xN. I know it could be done like this:
Received.InOrder(() => {
subst.MyMethod(x1);
subst.MyMethod(x2);
subst.MyMethod(x3);
// ...
subst.MyMethod(xN);
});
But can it be done in some way that simply lists the sequence of arguments?
Something like this (conceptual):
int[] args = {x1, x2, x3, /*...*/ xN};
subst.Received(N).MyMethod(Arg.Is(args));
Here's an implementation with InOrder
but I consider it a workaround:
int[] args = {x1, x2, x3, /*...*/ xN};
Received.InOrder(() => {
foreach (int i in args)
subst.MyMethod(i);
});
Upvotes: 2
Views: 1592
Reputation: 10464
From comment above:
The NSubstitute API does not have a method for doing this. To me the
foreach
method is clearest; it shows exactly what is expected for the test to succeed. You could write a method to package up this logic if you need it frequently, but while it may make it a bit more concise I don't think it will make it any clearer.
Upvotes: 1