예제 #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 ToStringWithoutArguments()
        {
            Target target = new Target();
            AbstractMethodInvocation join = CreateMethodInvocation(
                null, target, target.GetTargetMethodNoArgs(), null, null, 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_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.");
            }
        }
예제 #6
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();
        }
예제 #7
0
 private static string CheckToStringDoesntThrowAnException(AbstractMethodInvocation join)
 {
     return(join.ToString());
 }