Ejemplo n.º 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();
        }
		public void IsNotInvokedIfServiceObjectThrowsException()
		{
            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();

		}
Ejemplo n.º 3
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)
            {
            }
        }