Пример #1
0
        public void ValidInvocation()
        {        /*
                  *     Target target = new Target();
                  * MockRepository repository = new MockRepository();
                  * IMethodInterceptor interceptor = (IMethodInterceptor) repository.CreateMock(typeof (IMethodInterceptor));
                  * AbstractMethodInvocation join = CreateMethodInvocation(
                  * null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new object[] { interceptor });
                  * Expect.Call(interceptor.Invoke(join)).Return(target.BullseyeMethod().ToLower(CultureInfo.InvariantCulture));
                  * repository.ReplayAll();
                  * string score = (string) join.Proceed();
                  * Assert.AreEqual(target.BullseyeMethod().ToLower(CultureInfo.InvariantCulture) + Target.Suffix, score);
                  * repository.VerifyAll();
                  */
            Target                   target = new Target();
            IMethodInterceptor       mock   = (IMethodInterceptor)mocks.CreateMock(typeof(IMethodInterceptor));
            AbstractMethodInvocation join   = CreateMethodInvocation(
                null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new object[] { mock });

            Expect.Call(mock.Invoke(null)).IgnoreArguments().Return(target.BullseyeMethod().ToLower(CultureInfo.InvariantCulture));
            mocks.ReplayAll();

            string score = (string)join.Proceed();

            Assert.AreEqual(Target.DefaultScore.ToLower(CultureInfo.InvariantCulture) + Target.Suffix, score);

            mocks.VerifyAll();
        }
Пример #2
0
        public void ToStringWithArguments()
        {
            Target target = new Target();
            AbstractMethodInvocation join = CreateMethodInvocation(
                null, target, target.GetTargetMethod(), null, new string[] { "Five" }, target.GetType(), new ArrayList());

            CheckToStringDoesntThrowAnException(join);
        }
Пример #3
0
        public void ProceedWithEmptyInterceptorChain()
        {
            Target target = new Target();
            AbstractMethodInvocation join = CreateMethodInvocation(
                null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new ArrayList());
            string score = (string)join.Proceed();

            Assert.AreEqual(Target.DefaultScore + Target.Suffix, score);
        }
Пример #4
0
        public void ToStringMustNotInvokeToStringOnTarget()
        {
            Target target = new TargetWithBadToString();
            AbstractMethodInvocation join = CreateMethodInvocation(
                null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new ArrayList());

            // if it hits the target the test will fail with NotSupportedException...
            CheckToStringDoesntThrowAnException(join);
        }
Пример #5
0
        public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException()
        {
            BadCommand               target = new BadCommand();
            IMethodInterceptor       mock   = A.Fake <IMethodInterceptor>();
            AbstractMethodInvocation join   = CreateMethodInvocation(
                null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock });

            A.CallTo(() => mock.Invoke(null)).WithAnyArguments().Throws <NotImplementedException>();

            // we want this exception to bubble up...
            Assert.Throws <NotImplementedException>(() => join.Proceed());
        }
Пример #6
0
        public void UnwrapsTargetInvocationException_NoInterceptors()
        {
            BadCommand target             = new BadCommand();
            AbstractMethodInvocation join = CreateMethodInvocation(
                null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { });

            try
            {
                join.Proceed();
            }
            catch (NotImplementedException)
            {
                // this is good, we want this exception to bubble up...
            }
            catch (TargetInvocationException)
            {
                Assert.Fail("Must have unwrapped this.");
            }
        }
Пример #7
0
        public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException()
        {
            BadCommand               target = new BadCommand();
            IMethodInterceptor       mock   = (IMethodInterceptor)mocks.CreateMock(typeof(IMethodInterceptor));
            AbstractMethodInvocation join   = CreateMethodInvocation(
                null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock });

            Expect.Call(mock.Invoke(null)).IgnoreArguments().Throw(new NotImplementedException());
            mocks.ReplayAll();

            try
            {
                join.Proceed();
            }
            catch (NotImplementedException)
            {
                // this is good, we want this exception to bubble up...
            }
            catch (TargetInvocationException)
            {
                Assert.Fail("Must have unwrapped this.");
            }
            mocks.VerifyAll();
        }
Пример #8
0
 private static string CheckToStringDoesntThrowAnException(AbstractMethodInvocation join)
 {
     return(join.ToString());
 }
		private static string CheckToStringDoesntThrowAnException(AbstractMethodInvocation join)
		{
			return join.ToString();
		}