Exemple #1
0
        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)
            {
            }
        }
Exemple #2
0
        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);
        }