public void TestThrowOnEmployGenericClass() { FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>(); Assert.Throws <ArgumentException>( delegate() { testEmployer.Employ(typeof(GenericDerived <>)); } ); }
public void TestThrowOnEmployUnrelatedClass() { FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>(); Assert.Throws <InvalidCastException>( delegate() { testEmployer.Employ(typeof(Unrelated)); } ); }
public void TestThrowOnEmployAbstractClass() { FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>(); Assert.Throws <MissingMethodException>( delegate() { testEmployer.Employ(typeof(Base)); } ); }
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()); }
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()); }
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()); }