コード例 #1
0
        public void CanAddInterceptor_DirectSelection()
        {
            IWindsorContainer container = new WindsorContainer();

            container.Register(Component.For <WasCalledInterceptor>(),
                               Component.For <IWatcher>()
                               .ImplementedBy <BirdWatcher>()
                               .Named("bird.watcher")
                               .LifeStyle.Transient);

            var selector = new WatcherInterceptorSelector();

            container.Kernel.ProxyFactory.AddInterceptorSelector(selector);

            WasCalledInterceptor.WasCalled = false;
            var watcher = container.Resolve <IWatcher>();

            watcher.OnSomethingInterestingToWatch += delegate { };
            Assert.IsFalse(WasCalledInterceptor.WasCalled);

            selector.Interceptors = InterceptorKind.Dummy;

            WasCalledInterceptor.WasCalled = false;
            watcher = container.Resolve <IWatcher>();
            watcher.OnSomethingInterestingToWatch += delegate { };
            Assert.IsTrue(WasCalledInterceptor.WasCalled);
        }
コード例 #2
0
        public void TurnProxyOnAndOff_DirectSelection()
        {
            IWindsorContainer container = new WindsorContainer();

            container.Register(Component.For <WasCalledInterceptor>()).Register(
                Component.For(typeof(IWatcher)).ImplementedBy(typeof(BirdWatcher)).Named("bird.watcher").LifeStyle.Is(
                    LifestyleType.Transient));
            var selector = new WatcherInterceptorSelector();

            container.Kernel.ProxyFactory.AddInterceptorSelector(selector);

            Assert.IsFalse(container.Resolve <IWatcher>().GetType().Name.Contains("Proxy"));
            selector.Interceptors = InterceptorKind.Dummy;
            Assert.IsTrue(container.Resolve <IWatcher>().GetType().Name.Contains("Proxy"));
        }
コード例 #3
0
        public void InterceptorSelectors_Are_Cumulative()
        {
            IWindsorContainer container = new WindsorContainer();

            container.Register(Component.For <CountingInterceptor>(),
                               Component.For <WasCalledInterceptor>(),
                               Component.For <IWatcher>().ImplementedBy <BirdWatcher>().Named("bird.watcher").LifeStyle.Transient);

            var selector = new WatcherInterceptorSelector {
                Interceptors = InterceptorKind.Dummy
            };

            container.Kernel.ProxyFactory.AddInterceptorSelector(selector);
            container.Kernel.ProxyFactory.AddInterceptorSelector(new AnotherInterceptorSelector());

            var watcher = container.Resolve <IWatcher>();

            watcher.OnSomethingInterestingToWatch += delegate { };
            Assert.IsTrue(WasCalledInterceptor.WasCalled);
            Assert.IsTrue(WasCalledInterceptor.WasCalled);
        }
        public void InterceptorSelectors_Are_Cumulative()
        {
            IWindsorContainer container = new WindsorContainer();
            container
                .AddComponent<DummyInterceptor>()
                .AddComponent<AnotherDummyInterceptor>()
                .AddComponentLifeStyle<IWatcher, BirdWatcher>("bird.watcher", LifestyleType.Transient);

            WatcherInterceptorSelector selector = new WatcherInterceptorSelector();
            selector.Interceptors = Interceptors.Dummy;
            container.Kernel.ProxyFactory.AddInterceptorSelector(selector);
            container.Kernel.ProxyFactory.AddInterceptorSelector(new AnotherInterceptorSelector());

            IWatcher watcher = container.Resolve<IWatcher>();
            watcher.OnSomethingInterestingToWatch += delegate { };
            Assert.IsTrue(DummyInterceptor.WasCalled);
            Assert.IsTrue(AnotherDummyInterceptor.WasCalled);
        }
        public void CanAddInterceptor_DirectSelection()
        {
            IWindsorContainer container = new WindsorContainer();
            container
                .AddComponent<DummyInterceptor>()
                .AddComponentLifeStyle<IWatcher, BirdWatcher>("bird.watcher", LifestyleType.Transient);
          
            WatcherInterceptorSelector selector = new WatcherInterceptorSelector();
            container.Kernel.ProxyFactory.AddInterceptorSelector(selector);

            DummyInterceptor.WasCalled = false;
            IWatcher watcher = container.Resolve<IWatcher>();
            watcher.OnSomethingInterestingToWatch+=delegate {  };
            Assert.IsFalse(DummyInterceptor.WasCalled);
            
            selector.Interceptors = Interceptors.Dummy;

            DummyInterceptor.WasCalled = false;
            watcher = container.Resolve<IWatcher>();
            watcher.OnSomethingInterestingToWatch += delegate { };
            Assert.IsTrue(DummyInterceptor.WasCalled);
            
        }
        public void TurnProxyOnAndOff_SubDependency()
        {
            IWindsorContainer container = new WindsorContainer();
            container
                .AddComponent<DummyInterceptor>()
                .AddComponentLifeStyle<IWatcher, BirdWatcher>("bird.watcher", LifestyleType.Transient)
                .AddComponentLifeStyle<Person>(LifestyleType.Transient);
            WatcherInterceptorSelector selector = new WatcherInterceptorSelector();
            container.Kernel.ProxyFactory.AddInterceptorSelector(selector);

            Assert.IsFalse(container.Resolve<Person>().Watcher.GetType().Name.Contains("Proxy"));
            Assert.IsFalse(container.Resolve<Person>().GetType().Name.Contains("Proxy"));
            
            selector.Interceptors = Interceptors.Dummy;
      
            Assert.IsFalse(container.Resolve<Person>().GetType().Name.Contains("Proxy"));
            Assert.IsTrue(container.Resolve<Person>().Watcher.GetType().Name.Contains("Proxy"));
        }