I've starting using the AAA API and I like it. One thing that I haven't been able to figure out is how to fake different overloads of the same method so that they return different results. In one case, I want the first overload to throw and exception and then verify that the second overload was called with specific parameters. I was trying to do it this way:
Isolate.WhenCalled(() => class.SomeMethod(parm1)).WillThrow(new Exception("Exception for test."));
Isolate.WhenCalled(() => class.SomeMethod(parm1, parm2)).WillReturn(fakeObject);
... execute code that calls class.SomeMethod(parm1) and, when the exception is caught, call class.SomeMethod(parm1, parm2)...
Verify.WasCalledWithExactArguments(() => class.SomeMethod(parm1, parm2));
What happens when I run this code is that the call to the first overload - SomeMethod(parm1) - returns the fakeObject that I specified as the expected return object for the second method.
I can do this with the Natural Mocks using the following code:
Exception expectedException = new Exception("Exception for test.");
using (RecordExpectations recorder = Record)
{
class.SomeMethod(parm1);
recorder.Throw(expectedException);
class.SomeMethod(parm1, parm2);
recorder.Return(fakeObject);
recorder.CheckArguments();
}
.. verification here.
Is there a way to do this with AAA?