Esempio n. 1
0
        public void TestThrowOnEmployGenericClass()
        {
            FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>();

            Assert.Throws <ArgumentException>(
                delegate() { testEmployer.Employ(typeof(GenericDerived <>)); }
                );
        }
Esempio n. 2
0
        public void TestThrowOnEmployUnrelatedClass()
        {
            FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>();

            Assert.Throws <InvalidCastException>(
                delegate() { testEmployer.Employ(typeof(Unrelated)); }
                );
        }
Esempio n. 3
0
        public void TestThrowOnEmployAbstractClass()
        {
            FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>();

            Assert.Throws <MissingMethodException>(
                delegate() { testEmployer.Employ(typeof(Base)); }
                );
        }
Esempio n. 4
0
        public void TestEmployProduct()
        {
            FactoryEmployer <Unrelated> testEmployer = new FactoryEmployer <Unrelated>();

            testEmployer.Employ(typeof(Unrelated));

            Assert.AreEqual(1, testEmployer.Factories.Count);
            Assert.IsInstanceOf <Unrelated>(testEmployer.Factories[0].CreateInstance());
        }
Esempio n. 5
0
        public void TestEmployClassDerivedFromProduct()
        {
            FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>();

            testEmployer.Employ(typeof(Derived));

            Assert.AreEqual(1, testEmployer.Factories.Count);
            Assert.IsInstanceOf <Derived>(testEmployer.Factories[0].CreateInstance());
        }
Esempio n. 6
0
        public void TestNonGenericCreateInstance()
        {
            FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>();

            testEmployer.Employ(typeof(Derived));

            Assert.That(testEmployer.Factories.Count, Is.AtLeast(1));

            IAbstractFactory factory = testEmployer.Factories[0] as IAbstractFactory;

            Assert.IsNotNull(factory);

            Assert.IsInstanceOf <Derived>(factory.CreateInstance());
        }