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