コード例 #1
0
        public void InterceptNonVirtualMethodThatBelongsToAnInterface()
        {
            NopInterceptor ni = new NopInterceptor();

            AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());

            advised.AddAdvice(ni);

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            Assert.AreEqual(0, proxiedClass.Value);
            Assert.AreEqual(0, ni.Count);

            Assert.IsTrue(proxy is IIncrementable);
            IIncrementable proxiedInterface = proxy as IIncrementable;

            proxiedInterface.Increment();
            Assert.AreEqual(1, proxiedInterface.Value);
            Assert.AreEqual(2, ni.Count);
        }
コード例 #2
0
        public void DoesNotInterceptFinalMethod()
        {
            NopInterceptor ni = new NopInterceptor();

            AdvisedSupport advised = new AdvisedSupport();

            advised.Target = new InheritanceTestObject();
            advised.AddAdvice(ni);

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            proxiedClass.Name = "DoesNotInterceptFinalMethod";
            Assert.AreEqual("DoesNotInterceptFinalMethod", proxiedClass.Name);
            Assert.AreEqual(2, ni.Count);

            proxiedClass.Reset();
            Assert.AreEqual(2, ni.Count);
            Assert.AreEqual("InheritanceTestObject", proxiedClass.Name);
            Assert.AreEqual(3, ni.Count);
        }
コード例 #3
0
        public void CallBaseConstructor()
        {
            AdvisedSupport advised = new AdvisedSupport();

            advised.Target = new InheritanceTestObject();

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            Assert.AreEqual("InheritanceTestObject", proxiedClass.Name);
        }
コード例 #4
0
        public void ProxyTargetTypeOnly()
        {
            AdvisedSupport advised = new AdvisedSupport();

            advised.Target = new InheritanceTestObject("ProxyTargetTypeOnly");

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            Assert.AreNotEqual("ProxyTargetTypeOnly", proxiedClass.Name);
        }
コード例 #5
0
        public void InterceptProtectedMethod()
        {
            NopInterceptor ni = new NopInterceptor();

            AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());

            advised.AddAdvice(ni);

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            proxiedClass.Todo();
            Assert.AreEqual(1, ni.Count);
        }
コード例 #6
0
        public void InterceptThisCalls()
        {
            NopInterceptor ni = new NopInterceptor();

            AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());

            advised.AddAdvice(ni);

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            proxiedClass.IncrementTwice();
            Assert.AreEqual(2, ni.Count);
            Assert.AreEqual(2, proxiedClass.Value);
        }
コード例 #7
0
        public void DirectCall()
        {
            AdvisedSupport advised = new AdvisedSupport();

            advised.Target = new InheritanceTestObject();

            object proxy = CreateProxy(advised);

            //DynamicProxyManager.SaveAssembly();

            Assert.IsTrue(proxy is InheritanceTestObject);
            InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;

            proxiedClass.Name = "DirectCall";
            Assert.AreEqual("DirectCall", proxiedClass.Name);

            Assert.IsTrue(proxy is IIncrementable);
            IIncrementable proxiedIntf = proxy as IIncrementable;

            proxiedIntf.Increment();
            Assert.AreEqual(1, proxiedIntf.Value);
        }