public void TestThrowOnEmployGenericClass() { FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>(); Assert.Throws <ArgumentException>( delegate() { testEmployer.Employ(typeof(GenericDerived <>)); } ); }
public void TestCanEmploy() { FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>(); Assert.IsFalse(testEmployer.CanEmploy(typeof(Base))); Assert.IsTrue(testEmployer.CanEmploy(typeof(Derived))); Assert.IsFalse(testEmployer.CanEmploy(typeof(Unrelated))); }
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 TestRepositoryStorage() { PluginRepository testRepository = new PluginRepository(); FactoryEmployer <PluginRepository> testEmployer = new FactoryEmployer <PluginRepository>(); PluginHost testHost = new PluginHost(testEmployer, testRepository); Assert.AreSame(testRepository, testHost.Repository); }
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()); }
public void TestAssemblyLoadingWithNoPluginAttribute() { PluginRepository testRepository = new PluginRepository(); FactoryEmployer <PluginHostTest> testEmployer = new FactoryEmployer <PluginHostTest>(); PluginHost testHost = new PluginHost(testEmployer, testRepository); // Might also use Assembly.GetCallingAssembly() here, but this leads to the exe of // the unit testing tool Assembly self = Assembly.GetAssembly(GetType()); testRepository.AddAssembly(self); Assert.AreSame(testRepository, testHost.Repository); Assert.AreEqual(0, testEmployer.Factories.Count); }
public void TestFullConstructorWithPreloadedAssembly() { PluginRepository testRepository = new PluginRepository(); FactoryEmployer <PluginRepository> testEmployer = new FactoryEmployer <PluginRepository>(); // Might also use Assembly.GetCallingAssembly() here, but this leads to the exe of // the unit testing tool Assembly self = Assembly.GetAssembly(GetType()); testRepository.AddAssembly(self); PluginHost testHost = new PluginHost(testEmployer, testRepository); Assert.AreSame(testEmployer, testHost.Employer); Assert.AreEqual(1, testEmployer.Factories.Count); }