Beispiel #1
0
        public void TestThrowOnEmployGenericClass()
        {
            FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>();

            Assert.Throws <ArgumentException>(
                delegate() { testEmployer.Employ(typeof(GenericDerived <>)); }
                );
        }
Beispiel #2
0
        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)));
        }
Beispiel #3
0
        public void TestThrowOnEmployUnrelatedClass()
        {
            FactoryEmployer <Base> testEmployer = new FactoryEmployer <Base>();

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

            Assert.Throws <MissingMethodException>(
                delegate() { testEmployer.Employ(typeof(Base)); }
                );
        }
Beispiel #5
0
        public void TestRepositoryStorage()
        {
            PluginRepository testRepository = new PluginRepository();
            FactoryEmployer <PluginRepository> testEmployer = new FactoryEmployer <PluginRepository>();
            PluginHost testHost = new PluginHost(testEmployer, testRepository);

            Assert.AreSame(testRepository, testHost.Repository);
        }
Beispiel #6
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());
        }
Beispiel #7
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());
        }
Beispiel #8
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());
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }