0

I'm attempting to mock a method that takes an exception as a parameter and under certain circumstances may throw that exception. Is there a way to mock this such that the mocked method does that?

I'm figuring a syntax something like below.

myMock.Expects.One.Method(mo => mo.ProcessException(null)).With(<capture exception>).Will(new ThrowAction(<captured exception>));

Is there a way to do this? In this situation I actually know what type of exception I'm expecting, so in theory I could reconstruct it, but it seems better to throw the called exception.

rvv1980
  • 141
  • 7

1 Answers1

0

You need to use Collect.MethodArgument

mockPostalCodeChecker.Expects.One.Method(m => m.ProcessException(null)).With(<what you want>).Will(Collect.MethodArgument<Exception>(0, delegate(Exception excep) { throw excep; }));
Jérôme FLAMEN
  • 121
  • 1
  • 4