public void InvokingAbstractMethodFromInterceptedAbstracTypeInstanceThrows() { VirtualMethodInterceptor interceptor = new VirtualMethodInterceptor(); Type proxyType = interceptor.CreateProxyType(typeof(AbstractClassWithPublicConstructor)); AbstractClassWithPublicConstructor instance = (AbstractClassWithPublicConstructor)Activator.CreateInstance(proxyType); try { instance.AbstractMethod(); Assert.Fail("should have thrown"); } catch (NotImplementedException) { } }
public void CanInvokeVirtualMethodOnInterceptedAbstractTypeInstance() { VirtualMethodInterceptor interceptor = new VirtualMethodInterceptor(); Type proxyType = interceptor.CreateProxyType(typeof(AbstractClassWithPublicConstructor)); AbstractClassWithPublicConstructor instance = (AbstractClassWithPublicConstructor)Activator.CreateInstance(proxyType); bool invoked = false; ((IInterceptingProxy)instance).AddInterceptionBehavior( new DelegateInterceptionBehavior((mi, gn) => { invoked = true; return(gn()(mi, gn)); })); int value = instance.VirtualMethod(); Assert.AreEqual(10, value); Assert.IsTrue(invoked); }