Search code examples
c#rhino-mocks

Rhino .OutRef incompatible with .Throw?


I have a method with out parameters and that may throw an exception. I want to test this behavior with a Rhino mock, so I do :

Expect.Call(() => mymethod(null, null, out integer1, out integer2))
                 .IgnoreArguments().OutRef(1, 2).Throw(new Exception());

But it appears pretty clearly that the exception is thrown before the out parameters are initialized.

Did I do something wrong or is it the normal rhino behavior ? How would you address this problem ?


Solution

  • It's probably a bug in Rhino.Mocks. I think using the .Throw() method says "when I call this method, throw this exception". That's all it does -- throws the exception.

    I would redesign the code so as not to expect out variables to be initialized AND an exception be thrown. When I wrap a method in a try/catch block and catch an exception, I assume the method could have died anywhere and I don't make any assumptions about what work may have been accomplished (or not accomplished).

    Maybe the code could be split into two methods?