public void JustPassesAfterReturningAdviceExceptionUpWithoutAnyWrapping() { MockRepository repository = new MockRepository(); IMethodInvocation mockInvocation = (IMethodInvocation)repository.CreateMock(typeof(IMethodInvocation)); IAfterReturningAdvice mockAdvice = (IAfterReturningAdvice)repository.CreateMock(typeof(IAfterReturningAdvice)); mockAdvice.AfterReturning(null, null, null, null); LastCall.IgnoreArguments(); LastCall.Throw(new FormatException()); Expect.Call(mockInvocation.Method).Return(ReflectionUtils.GetMethod(typeof(object), "HashCode", new Type[] { })); Expect.Call(mockInvocation.Arguments).Return(null); Expect.Call(mockInvocation.This).Return(new object()); Expect.Call(mockInvocation.Proceed()).Return(null); repository.ReplayAll(); try { AfterReturningAdviceInterceptor interceptor = new AfterReturningAdviceInterceptor(mockAdvice); interceptor.Invoke(mockInvocation); Assert.Fail("Must have thrown a FormatException by this point."); } catch (FormatException) { } repository.VerifyAll(); }
/// <summary> /// Executes interceptor after the target method successfully returns. /// </summary> /// <param name="invocation"> /// The method invocation that is being intercepted. /// </param> /// <returns> /// The result of the call to the /// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/> method of /// the supplied <paramref name="invocation"/>; this return value may /// well have been intercepted by the interceptor. /// </returns> /// <exception cref="System.Exception"> /// If any of the interceptors in the chain or the target object itself /// throws an exception. /// </exception> public object Invoke(IMethodInvocation invocation) { object returnValue = invocation.Proceed(); advice.AfterReturning( returnValue, invocation.Method, invocation.Arguments, invocation.This); return(returnValue); }
public void JustPassesAfterReturningAdviceExceptionUpWithoutAnyWrapping() { IMethodInvocation mockInvocation = A.Fake <IMethodInvocation>(); IAfterReturningAdvice mockAdvice = A.Fake <IAfterReturningAdvice>(); A.CallTo(() => mockAdvice.AfterReturning(null, null, null, null)).WithAnyArguments().Throws <FormatException>(); A.CallTo(() => mockInvocation.Method).Returns(ReflectionUtils.GetMethod(typeof(object), "HashCode", new Type[] { })); A.CallTo(() => mockInvocation.Arguments).Returns(null); A.CallTo(() => mockInvocation.This).Returns(new object()); A.CallTo(() => mockInvocation.Proceed()).Returns(null); try { AfterReturningAdviceInterceptor interceptor = new AfterReturningAdviceInterceptor(mockAdvice); interceptor.Invoke(mockInvocation); Assert.Fail("Must have thrown a FormatException by this point."); } catch (FormatException) { } }