Ejemplo n.º 1
0
        public void TestGenerationSimpleInterface()
        {
            IInvocationHandler handler = new StandardInvocationHandler(new MyInterfaceImpl());
            object             proxy   = ProxyGenerator.CreateProxy(typeof(IMyInterface), handler);

            Assert.IsNotNull(proxy);
            Assert.IsTrue(typeof(IMyInterface).IsAssignableFrom(proxy.GetType()));

            IMyInterface inter = (IMyInterface)proxy;

            Assert.AreEqual(45, inter.Calc(20, 25));

            inter.Name = "opa";
            Assert.AreEqual("opa", inter.Name);

            inter.Started = true;
            Assert.AreEqual(true, inter.Started);
        }
Ejemplo n.º 2
0
        public void TestGenerationWithInterfaceHeritage()
        {
            IInvocationHandler handler = new StandardInvocationHandler(new MySecondInterfaceImpl());
            object             proxy   = ProxyGenerator.CreateProxy(typeof(IMySecondInterface), handler);

            Assert.IsNotNull(proxy);
            Assert.IsTrue(typeof(IMyInterface).IsAssignableFrom(proxy.GetType()));
            Assert.IsTrue(typeof(IMySecondInterface).IsAssignableFrom(proxy.GetType()));

            IMySecondInterface inter = (IMySecondInterface)proxy;

            inter.Calc(1, 1);

            inter.Name = "hammett";
            Assert.AreEqual("hammett", inter.Name);

            inter.Address = "pereira leite, 44";
            Assert.AreEqual("pereira leite, 44", inter.Address);

            Assert.AreEqual(45, inter.Calc(20, 25));
        }