Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }