コード例 #1
0
        public void InterceptVirtualAndOverloadMethod()
        {
            ProxyFactory   factory     = new ProxyFactory();
            NopInterceptor interceptor = new NopInterceptor(new ProxyTestClass("test", 0));

            object proxy = factory.CreateProxy(typeof(ProxyTestClass), interceptor);

            Assert.IsTrue(proxy is IProxy);
            Assert.IsTrue(proxy is ProxyTestClass);

            ProxyTestClass proxyTest = proxy as ProxyTestClass;

            Assert.AreEqual(0, proxyTest.Count);

            proxyTest.Dosomething(2);

            Assert.AreEqual(2, proxyTest.Count);
            Assert.AreEqual("test", proxyTest.Name);

            proxyTest.Dosomething("ing");

            Assert.AreEqual("testing", proxyTest.Name);
            Assert.AreEqual(2, proxyTest.Count);
            Assert.AreEqual(7, interceptor.Count);
        }
コード例 #2
0
        public void InterceptGenericMethodWithGenericParams()
        {
            ProxyFactory   factory     = new ProxyFactory();
            NopInterceptor interceptor = new NopInterceptor(new ProxyTestClass("test", 0));

            object         proxy     = factory.CreateProxy(typeof(ProxyTestClass), interceptor);
            ProxyTestClass proxyTest = proxy as ProxyTestClass;
            //Assert.AreEqual(5, proxyTest.GenericMethod<int>(5));
            //Assert.AreEqual(1, interceptor.Count);
        }
コード例 #3
0
        public void DirectCall()
        {
            ProxyFactory   factory     = new ProxyFactory();
            NopInterceptor interceptor = new NopInterceptor(new ProxyTestClass("test"));
            object         proxy       = factory.CreateProxy(typeof(ProxyTestClass), interceptor);

            Assert.IsTrue(proxy is IProxy);
            Assert.IsTrue(proxy is ProxyTestClass);
            ProxyTestClass proxyTest = proxy as ProxyTestClass;

            Assert.AreEqual("test", proxyTest.Name);
            Assert.AreEqual(1, interceptor.Count);
        }
コード例 #4
0
        public void InterceptVirtualMethod()
        {
            ProxyFactory   factory     = new ProxyFactory();
            NopInterceptor interceptor = new NopInterceptor(new ProxyTestClass("test"));
            object         proxy       = factory.CreateProxy(typeof(ProxyTestClass), interceptor);

            Assert.IsTrue(proxy is IProxy);
            Assert.IsTrue(proxy is ProxyTestClass);
            ProxyTestClass proxyTest = proxy as ProxyTestClass;

            proxyTest.Name = "test1";
            Assert.AreEqual("test1", proxyTest.Name);
            Assert.AreEqual(2, interceptor.Count);
        }
コード例 #5
0
        public void InterceptInterfaceVirtualMethod()
        {
            ProxyFactory   factory     = new ProxyFactory();
            NopInterceptor interceptor = new NopInterceptor(new ProxyTestClass("test", 0));

            object proxy = factory.CreateProxy(typeof(ProxyTestClass), interceptor);

            Assert.IsTrue(proxy is IProxy);
            Assert.IsTrue(proxy is IProxyTest);
            Assert.IsTrue(proxy is ProxyTestClass);

            IProxyTest proxyTest = proxy as IProxyTest;

            Assert.AreEqual("test", proxyTest.GetName());
            Assert.AreEqual(1, interceptor.Count);
        }