I have a piece of logic I want to test and it uses dependency injected interface with one (or more) void methods, example:
interface IMyService
{
void MethodA (MyComplexObject arg1, int arg2);
}
What I would want is to create a stub for this IMyService
that would just record the method invocations of MethodA
and I would later be able to access it as a list, something like:
MyComplexObject actualParameter = serviceRecorder
.GetMethodRecordings("MethodA").GetRecord(10).GetInputParameter(0);
I need this to examine the contents of such a parameter for a certain invocation and make assertions on it. I know there are other was of doing it (like setting expectation calls with constraints), but this seems much easier to write for cases when you have a lot of invocations and you want to make assertions on the 51th one only, for example.
So is there some sort of mechanism in Rhino.Mocks for this or am I left to my own devices (writing dummy IMyService
implementation with recording capabilities)?
NOTE: (I'm aware this could lead to tests being fragile and I'm aware of the consequences).
UPDATE: here's what I found so far (thanks in part to Mark's help in naming this pattern as Test Spy):
- Advanced mocking: anonymous test spy
- Perhaps using Windsor Castle's interceptors?