Beispiel #1
0
        public void TestInheritedInterfaces()
        {
            var factory = new AdaptiveFactory <Base>();

            factory.ImplementMethods().UsingSharedExecuter("Init", "Exec");

            Type ibase    = factory.Implement(typeof(IBase));
            Type iderived = factory.Implement(typeof(IDerived));

            Assert.AreNotSame(ibase, iderived);
            Assert.IsTrue(typeof(IDisposable).IsAssignableFrom(ibase));
            Assert.IsTrue(typeof(IBase).IsAssignableFrom(ibase));
            Assert.IsTrue(typeof(IBase).IsAssignableFrom(iderived));
            Assert.IsTrue(typeof(IDerived).IsAssignableFrom(iderived));

            using (IBase b = (IBase)Activator.CreateInstance(ibase))
            {
                Assert.IsNotNull(b.DoSomething());
                Assert.AreEqual("DoSomething", b.DoSomething().Name);
            }
            using (IDerived d = (IDerived)Activator.CreateInstance(iderived))
            {
                Assert.AreEqual("DoSomething", d.DoSomething().Name);
                Assert.AreEqual("DoMore", d.DoMore().Name);
            }
        }