print GetArgumentsForCallsMadeOne if assert failed in RhinoMock

80 views Asked by At

Let's say I have a test using RhinoMock. I'm using the AAA aproach, so it's usually ended with fooMock.AssertWasCalled(x=>x.Foo(bar))

If the assertion failed, I'd usually add a line looking like this fooMock.GetArgumentsForCallsMadeOn(x=>x.Foo(null)).PrintDump()

so I can see what calls was made on mock (it helps, because usually the problem is that mock is called with wrong arguments).

Is there any way I can automate the process? So, tell RhinoMock to print the calls was made on mock's method if an assertion failed?

1

There are 1 answers

0
Alexander Stepaniuk On

It seems there is no built-in mechanism to dump arguments for failed assertions.

I'd suggest to use an extension method like the following:

public static void AssertWasCalledAndDump<T>(this T self, Action<T> action)
{
    try
    {
        self.AssertWasCalled(action);
    }
    catch (Rhino.Mocks.Exceptions.ExpectationViolationException)
    {
        self
            .GetArgumentsForCallsMadeOn(action, options => options.IgnoreArguments())
            .PrintDump();
        throw;
    }
}

Then in the code you can just write:

fooMock.AssertWasCalledAndDump(x=>x.Foo(bar));

PS
I assume you already have an implementation of PrintDump() extension.