Пример #1
0
        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();
        }
Пример #2
0
        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)
            {
            }
        }
        /// <summary>
        /// Wraps the supplied <paramref name="advisor"/>'s
        /// <see cref="Spring.Aop.IAdvisor.Advice"/> within a
        /// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
        /// instance.
        /// </summary>
        /// <param name="advisor">
        /// The advisor exposing the <see cref="AopAlliance.Aop.IAdvice"/> that
        /// is to be wrapped.
        /// </param>
        /// <returns>
        /// The supplied <paramref name="advisor"/>'s
        /// <see cref="Spring.Aop.IAdvisor.Advice"/> wrapped within a
        /// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
        /// instance.
        /// </returns>
        public virtual IInterceptor GetInterceptor(IAdvisor advisor)
        {
            IAfterReturningAdvice advice = (IAfterReturningAdvice)advisor.Advice;

            return(new AfterReturningAdviceInterceptor(advice));
        }
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
 /// class.
 /// </summary>
 /// <param name="advice">
 /// The advice to be applied after a target method successfully
 /// returns.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// If the supplied <paramref name="advice"/> is <see langword="null"/>.
 /// </exception>
 public AfterReturningAdviceInterceptor(IAfterReturningAdvice advice)
 {
     AssertUtils.ArgumentNotNull(advice, "advice");
     this.advice = advice;
 }
		/// <summary>
		/// Creates a new instance of the
		/// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
		/// class.
		/// </summary>
		/// <param name="advice">
		/// The advice to be applied after a target method successfully
		/// returns.
		/// </param>
		/// <exception cref="System.ArgumentNullException">
		/// If the supplied <paramref name="advice"/> is <see langword="null"/>.
		/// </exception>
		public AfterReturningAdviceInterceptor(IAfterReturningAdvice advice)
		{
			AssertUtils.ArgumentNotNull(advice, "advice");
			this.advice = advice;
		}