Spring.Aop.Framework.ProxyFactoryTests.AddAndRemoveEventHandlerThroughInterceptor C# (CSharp) Метод

AddAndRemoveEventHandlerThroughInterceptor() приватный Метод

private AddAndRemoveEventHandlerThroughInterceptor ( ) : void
Результат void
        public void AddAndRemoveEventHandlerThroughInterceptor()
        {
            TestObject target = new TestObject();
            NopInterceptor nopInterceptor = new NopInterceptor();
            CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice();
            target.Name = "SOME-NAME";
            ProxyFactory pf = new ProxyFactory(target);
            pf.AddAdvice(nopInterceptor);
            pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice));
            object proxy = pf.GetProxy();
            ITestObject to = proxy as ITestObject;
            // add event handler through proxy
            to.Click += new EventHandler(OnClick);
            OnClickWasCalled = false;
            to.OnClick();
            Assert.IsTrue(OnClickWasCalled);
            Assert.AreEqual(2, countingBeforeAdvice.GetCalls());
            // remove event handler through proxy
            to.Click -= new EventHandler(OnClick);
            OnClickWasCalled = false;
            to.OnClick();
            Assert.IsFalse(OnClickWasCalled);
            Assert.AreEqual(4, countingBeforeAdvice.GetCalls());
        }