I am using NSubstitute to write a unit test, and am trying to capture multiple method arguments passed in a method call.
I understand that I can capture a single argument using the Arg.Do<T>() matcher by doing something like this for SomeMethod which only accepts one parameter:
TArg? receivedArg = null;
SomeClass.SomeMethod(Arg.Do<TArg>(arg => receivedArg = arg));
However in my case, SomeMethod multiple arguments, and I want to capture all of them in each call.
Check the Callbacks, void calls and When..Do topic.
You can hook an
Action<CallInfo>callback to yourSomeMethodmethod; itsCallInfoargument has anArgsmethod that returns all passed arguments as anobject[]array. There's also anArgAt<T>(int position)method for strong typed access to a specific argument.