コード例 #1
0
        public void GlobalAndAttributeInterceptorConfigureOrderTest()
        {
            // ARRANGE
            RealServiceExecuted.ResetExecuted();
            MyInterceptor.ResetExecuted();
            MyOtherInterceptor.ResetExecuted();
            InterceptorsCalled.ResetList();

            unityContainer.RegisterType <IMyFooService, MyFooServiceWithAttributeInterceptor>();
            unityContainer = InterceptionHelper.InterceptContainer(unityContainer, new IInterceptor[] { new MyOtherInterceptor() }, new InterceptionOptions {
                GlobalInterceptorsOrder = GlobalInterceptorsOrder.AfterAttributeInterceptors
            });

            var myService = unityContainer.Resolve <IMyFooService>();

            // ACT
            myService.Execute();

            // ASSERT
            Assert.IsTrue(RealServiceExecuted.Executed);
            Assert.IsTrue(MyInterceptor.ExecutedBefore);
            Assert.IsTrue(MyInterceptor.ExecutedAfter);
            Assert.IsTrue(MyOtherInterceptor.ExecutedBefore);
            Assert.IsTrue(MyOtherInterceptor.ExecutedAfter);
            Assert.IsTrue(InterceptorsCalled.List[0].GetType() == typeof(MyOtherInterceptor));
            Assert.IsTrue(InterceptorsCalled.List[1].GetType() == typeof(MyInterceptor));
        }
コード例 #2
0
        public void RemoveGlobalInterceptorTest()
        {
            RealServiceExecuted.ResetExecuted();
            MyInterceptor.ResetExecuted();
            MyOtherInterceptor.ResetExecuted();

            unityContainer.RegisterType <IMyFooService, MyFooServiceWithRemoveGlobalInterceptor>();
            unityContainer = InterceptionHelper.InterceptContainer(unityContainer, new IInterceptor[] { new MyInterceptor(), new MyOtherInterceptor() });

            var myService = unityContainer.Resolve <IMyFooService>();

            // ACT
            myService.Execute();

            // ASSERT
            Assert.IsTrue(RealServiceExecuted.Executed);
            Assert.IsTrue(MyInterceptor.ExecutedBefore);
            Assert.IsTrue(MyInterceptor.ExecutedAfter);
            Assert.IsFalse(MyOtherInterceptor.ExecutedBefore);
            Assert.IsFalse(MyOtherInterceptor.ExecutedAfter);
        }