Exemplo n.º 1
0
        public void DynamicFactoryTest2()
        {
            var dynamicAsmName   = "TestDynamicAssembly";
            var registerResolver = new OrlemContainer(new LoggingService(), dynamicAsmName);

            registerResolver.Start();
            registerResolver.RegisterFactory <IFactoryInterface, IClass, ClassImpl>();
            registerResolver.RegisterFactory <IFactoryInterface2, IClass, ClassImpl>();
            var factory = registerResolver.Resolve <IFactoryInterface>();

            Assert.IsNotNull(factory);

            var instance1 = factory.Create(0, 1);

            Assert.IsNotNull(instance1);
            Assert.IsNotNull(instance1.RegionManager);
            Assert.AreEqual(0, instance1.A);
            Assert.AreEqual(1, instance1.B);
            Assert.IsNull(instance1.C);

            var instance2 = factory.Create("str");

            Assert.IsNotNull(instance2);
            Assert.IsNotNull(instance2.RegionManager);
            Assert.AreEqual(0, instance2.A);
            Assert.AreEqual(0, instance2.B);
            Assert.AreEqual("str", instance2.C);

            var factory2 = registerResolver.Resolve <IFactoryInterface2>();

            Assert.IsNotNull(factory2);

            var instance4 = factory2.Create(0, 1);

            Assert.IsNotNull(instance4);
            Assert.IsNotNull(instance4.RegionManager);
            Assert.AreEqual(0, instance4.A);
            Assert.AreEqual(1, instance4.B);
            Assert.IsNull(instance4.C);

            var instance5 = factory2.Create("str");

            Assert.IsNotNull(instance5);
            Assert.IsNotNull(instance5.RegionManager);
            Assert.AreEqual(0, instance5.A);
            Assert.AreEqual(0, instance5.B);
            Assert.AreEqual("str", instance5.C);

            var asms = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.GetName().Name == dynamicAsmName).ToArray();

            Assert.AreEqual(1, asms.Length);
            var asm     = asms.First();
            var modules = asm.Modules.ToArray();

            Assert.AreEqual(1, modules.Length);
            var module = modules.First();
            var types  = module.GetTypes().ToArray();

            Assert.AreEqual(2, types.Length);
        }
Exemplo n.º 2
0
        public void DynamicFactoryTest()
        {
            var registerResolver = new OrlemContainer(new LoggingService());

            registerResolver.RegisterFactory <IFactoryInterface, IClass, ClassImpl>();
            registerResolver.Start();
            var factory = registerResolver.Resolve <IFactoryInterface>();

            Assert.IsNotNull(factory);

            var instance1 = factory.Create(0, 1);

            Assert.IsNotNull(instance1);
            Assert.IsNotNull(instance1.RegionManager);
            Assert.AreEqual(0, instance1.A);
            Assert.AreEqual(1, instance1.B);
            Assert.IsNull(instance1.C);

            var instance2 = factory.Create("str");

            Assert.IsNotNull(instance2);
            Assert.IsNotNull(instance2.RegionManager);
            Assert.AreEqual(0, instance2.A);
            Assert.AreEqual(0, instance2.B);
            Assert.AreEqual("str", instance2.C);

            Assert.ThrowsException <NotImplementedException>(() => factory.Create(0, "str"));
        }
Exemplo n.º 3
0
        public void DynamicFactoryTest3()
        {
            var dynamicAsmName   = "TestDynamicAssembly";
            var registerResolver = new OrlemContainer(new LoggingService(), dynamicAsmName);

            registerResolver.Start();

            registerResolver.RegisterFactory <IClass2Factory, IClass2, Class2Impl>();
            var factory   = registerResolver.Resolve <IClass2Factory>();
            var instance1 = factory.Create();

            Assert.IsNotNull(instance1?.RegionManager);
        }