コード例 #1
0
 public void TestTestContainerBasicNamedService()
 {
     TestContainer container = new TestContainer(@"Concrete\Castle\AOP\HelperClasses\ConfigSample1.config");
     SomeClass sc = new SomeClass();
     Assert.AreNotEqual(sc, container.Resolve("someclass"));
     container.AddNamedServiceOverride("someclass", sc);
     Assert.AreEqual(sc, container.Resolve("someclass"));
 }
コード例 #2
0
 public void TestTestContainerBasic()
 {
     TestContainer container = new TestContainer(@"Concrete\Castle\AOP\HelperClasses\ConfigSample1.config");
     SomeClass sc = new SomeClass();
     ISomething smth = container.Resolve<ISomething>();
     Assert.AreNotEqual(sc, smth);
     container.AddServiceOverride(typeof(ISomething), sc);
     Assert.AreEqual(sc, container.Resolve<ISomething>());
 }
コード例 #3
0
        public void TestBasicInterceptionShouldNotProceed() {
            //Create and mock the interceptor.
            MockRepository mock = new MockRepository();
            IAspect hmock = mock.CreateMock<IAspect>();
            hmock.PreCall(null);
            LastCall.Return(MethodVoteOptions.Halt)
                .IgnoreArguments();
            mock.ReplayAll();

            using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample1.config")) {
                container.Kernel.RemoveComponent("interceptor");
                container.Kernel.AddComponentInstance("interceptor", hmock);
                container.Resolve<ISomething>().OtherMethod("test1", "test2");
            }

            mock.VerifyAll();
        }
コード例 #4
0
        public void TestTestContainerAop()
        {
            MockRepository mock = new MockRepository();
            IAspect hmock = mock.CreateMock<IAspect>();
            hmock.PostCall(null, null);
            LastCall.IgnoreArguments();
            hmock.PreCall(null);
            LastCall.Return(MethodVoteOptions.Continue)
                .IgnoreArguments();
            mock.ReplayAll();

            TestContainer container = new TestContainer(@"Concrete\Castle\AOP\HelperClasses\ConfigSample1.config");
            container.Kernel.RemoveComponent("interceptor");
            container.Kernel.AddComponentInstance("interceptor", hmock);
            container.Resolve<ISomething>().AMethod("test");
            mock.VerifyAll();
        }
コード例 #5
0
        public void TestBasicInterceptionExceptionThrow() {
            //Create and mock the interceptor.
            MockRepository mock = new MockRepository();
            IAspect hmock = mock.CreateMock<IAspect>();
            hmock.PreCall(null);
            LastCall.Return(MethodVoteOptions.Continue)
                .IgnoreArguments();

            hmock.OnException(null, null, null);
            LastCall.Constraints(
                new Rhino.Mocks.Constraints.Anything(),
                Rhino.Mocks.Constraints.Is.TypeOf(typeof(NullReferenceException)), 
                Rhino.Mocks.Constraints.Is.Anything());

            mock.ReplayAll();
            using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample1.config")) {
                container.Kernel.RemoveComponent("interceptor");
                container.Kernel.AddComponentInstance("interceptor", hmock);
                try {
                    container.Resolve<ISomething>().OtherMethod(null, null);
                    Assert.Fail("If reach here exception was not thrown");
                }
                catch (Exception) {
                }

            }

            mock.VerifyAll();
        }
コード例 #6
0
 public void TestWrongAopConfiguration() {
     using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\WrongConfig.config")) { }
 }
コード例 #7
0
        public void TestIgnoreExeptionReturnValue()
        { 
            //Create and mock the interceptor.
            MockRepository mock = new MockRepository();
            IAspect hmock = mock.StrictMock<IAspect>();
            Expect.Call(hmock.PreCall(null))
                .Return(MethodVoteOptions.Continue)
                .IgnoreArguments();
            Expect.Call(() => hmock.PostCall(null, null))
                .IgnoreArguments();
            Expect.Call(() => hmock.OnException(null, null, null))
                .Callback(delegate(CastleIInvocation ii, Exception e, AspectExceptionAction action)
                              {
                                  action.IgnoreException = true;
                                  return true;
                              });
            mock.ReplayAll();
            using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample2.config"))
            {
                //Set the mock into the kernel.
                container.Kernel.RemoveComponent("interceptor");
                container.Kernel.AddComponentInstance("interceptor", hmock);
                ISomething something = container.Resolve<ISomething>("throwclass");
                String retvalue = something.OtherMethod("1", "2");
                Assert.That(retvalue, Is.Null); //Default value is returned
            }

            mock.VerifyAll();
        }
コード例 #8
0
        public void TestOverrideReturnValue()
        {
            //Create and mock the interceptor.
            MockRepository mock = new MockRepository();
            IAspect hmock = mock.StrictMock<IAspect>();
            Expect.Call(hmock.PreCall(null))
                .Return(MethodVoteOptions.Continue)
                .IgnoreArguments();
            hmock.PostCall(null, null);
            LastCall.Callback(delegate(CastleIInvocation ii, AspectReturnValue retval)
                                  {
                                      retval.WrappedReturnValue = "1234567890";
                                      return retval.Original.Equals("12");
                                  });
             
            mock.ReplayAll();
            using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample2.config"))
            {
                //Set the mock into the kernel.
                container.Kernel.RemoveComponent("interceptor");
                container.Kernel.AddComponentInstance("interceptor", hmock);
                ISomething something = container.Resolve<ISomething>();
                String retvalue = something.OtherMethod("1", "2");
                Assert.That(retvalue, Is.EqualTo("1234567890"));
            }

            mock.VerifyAll();
        }
コード例 #9
0
        public void TestMultiplePointCut()
        {
            //Create and mock the interceptor.
            MockRepository mock = new MockRepository();
            IAspect hmock = mock.CreateMock<IAspect>();
            Expect.Call(hmock.PreCall(null))
                .Repeat.Twice()
                .Return(MethodVoteOptions.Continue)
                .IgnoreArguments();
            Expect.Call(() => hmock.PostCall(null, null))
                .Repeat.Twice()
                .IgnoreArguments();

            mock.ReplayAll();
            using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample3.config"))
            {
                //Set the mock into the kernel.
                container.Kernel.RemoveComponent("interceptor");
                container.Kernel.AddComponentInstance("interceptor", hmock);
                ISomething something = container.Resolve<ISomething>();
                something.AMethod("TEST");
                something.OtherMethod("1", "2");
            }

            mock.VerifyAll();
        }
コード例 #10
0
 /// <summary>
 /// Can I declare two pointcut?
 /// </summary>
 public void TestSmokeMultiplePointCut()
 {
     using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample3.config")) {}
 }
コード例 #11
0
        public void TestProxyObjectIfDeclaredBeforePointcut() {
            using (TestContainer container = new TestContainer(@"Concrete\Castle\AOP\TestSuite1\Configs\ConfigSample2.config"))
            {
                //Some class has a method that match the pointcut, it should be proxyed
                object obj = container.Resolve<ISomething>();
                Assert.IsNotInstanceOfType(typeof(SomeClass), obj);

                obj = container.Resolve<IAnotherSomething>();
                Assert.IsNotInstanceOfType(typeof(OtherClass), obj, "OtherClass must not be proxied");
            }
        }