public void HandlerMethodThrowsException() { Exception exception = new Exception(); MyThrowsHandler handler = new ThrowingMyHandler(exception); ThrowsAdviceInterceptor interceptor = new ThrowsAdviceInterceptor(handler); // extends RemotingException... RemotingTimeoutException ex = new RemotingTimeoutException(); MockRepository repository = new MockRepository(); IMethodInvocation mi = (IMethodInvocation)repository.CreateMock(typeof(IMethodInvocation)); Expect.Call(mi.Proceed()).Throw(ex); repository.ReplayAll(); try { interceptor.Invoke(mi); Assert.Fail("Should not have reached this point, should have thrown an exception."); } catch (Exception caught) { Assert.AreEqual(exception, caught); } Assert.AreEqual(1, handler.GetCalls()); Assert.AreEqual(1, handler.GetCalls("RemotingException")); repository.VerifyAll(); }
public void HandlerMethodThrowsException() { Exception exception = new Exception(); MyThrowsHandler handler = new ThrowingMyHandler(exception); ThrowsAdviceInterceptor interceptor = new ThrowsAdviceInterceptor(handler); IMethodInvocation mi = A.Fake <IMethodInvocation>(); A.CallTo(() => mi.Proceed()).Throws(new RemotingTimeoutException()); try { interceptor.Invoke(mi); Assert.Fail("Should not have reached this point, should have thrown an exception."); } catch (Exception caught) { Assert.AreEqual(exception, caught); } Assert.AreEqual(1, handler.GetCalls()); Assert.AreEqual(1, handler.GetCalls("RemotingException")); }