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