protected override object CreateProxy(AdvisedSupport advisedSupport)
        {
            advisedSupport.ProxyTargetType = true;
            object proxy = CreateAopProxy(advisedSupport).GetProxy();

            Assert.IsTrue(AopUtils.IsDecoratorAopProxy(proxy));
            return(proxy);
        }
Ejemplo n.º 2
0
        public void TargetImplementsAnInterfaceWithProxyTargetTypeSetToTrue()
        {
            ProxyFactory advisedSupport = new ProxyFactory();

            advisedSupport.ProxyTargetType = true;
            advisedSupport.Target          = new TestObject();

            IAopProxy aopProxy = CreateAopProxy(advisedSupport);

            Assert.IsNotNull(aopProxy);
            Assert.IsTrue(AopUtils.IsDecoratorAopProxy(aopProxy));
        }
Ejemplo n.º 3
0
        public void IsDecoratorProxy()
        {
            var pf = new ProxyFactory(new DebugAdvice());

            pf.Target          = _target;
            pf.ProxyTargetType = true;

            var proxy = (TestObject)pf.GetProxy();

            Assert.True(AopUtils.IsDecoratorAopProxy(proxy));
            Assert.True(AopUtils.IsAopProxy(proxy));
        }
Ejemplo n.º 4
0
        public void TargetDoesNotImplementAnyInterfaces()
        {
            ProxyFactory advisedSupport = new ProxyFactory();

            advisedSupport.AopProxyFactory = new DefaultAopProxyFactory();
            advisedSupport.ProxyTargetType = false;
            advisedSupport.Target          = new DoesNotImplementAnyInterfacesTestObject();

            IAopProxy aopProxy = CreateAopProxy(advisedSupport);

            Assert.IsNotNull(aopProxy);
            Assert.IsTrue(AopUtils.IsDecoratorAopProxy(aopProxy));
        }
        private void DecoratorProxyAssertions(ITestObject testObject)
        {
            CountingBeforeAdvice cba = (CountingBeforeAdvice)ctx.GetObject("countingBeforeAdvice");
            NopInterceptor       nop = (NopInterceptor)ctx.GetObject("nopInterceptor");

            Assert.AreEqual(0, cba.GetCalls());
            Assert.AreEqual(0, nop.Count);
            Assert.IsTrue(AopUtils.IsDecoratorAopProxy(testObject), testObject + " is not an AOP Proxy");
            //extra advice calls are due to test IsDecoratorAopProxy and call to .GetType in impl
            Assert.AreEqual(1, nop.Count);
            Assert.AreEqual(1, cba.GetCalls());
            int age = 5;

            testObject.Age = age;
            Assert.AreEqual(age, testObject.Age);
            Assert.AreEqual(3, nop.Count);
            Assert.AreEqual(3, cba.GetCalls());
        }
        public void ProxyCanBeClassAndInterface()
        {
            TestObject target = new TestObject();

            target.Age = 32;
            mockTargetSource.SetTarget(target);
            AdvisedSupport advised = new AdvisedSupport();

            advised.TargetSource = mockTargetSource;
            IAopProxy aop = CreateAopProxy(advised);

            object proxy = aop.GetProxy();

            Assert.IsTrue(AopUtils.IsDecoratorAopProxy(proxy), "Should be a decorator-based proxy");
            Assert.IsTrue(proxy is ITestObject);
            Assert.IsTrue(proxy is TestObject);

            ITestObject itb = (ITestObject)proxy;

            Assert.AreEqual(32, itb.Age, "Incorrect age");
            TestObject tb = (TestObject)proxy;

            Assert.AreEqual(32, tb.Age, "Incorrect age");
        }