Exemple #1
0
        public void TestContainsPrototypeWithObjectArg()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC()).Reconfigure();

            bool b = container.ContainsObject(typeof(Prototype));
            Assert.IsTrue(b);
        }
Exemple #2
0
        public void TestConfigurationExpansion()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            Assert.IsNotNull(container);

            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));

            container.ExpandConfiguration(new ComplexConfig());
            Assert.IsTrue(container.ContainsObject<IAggregate>());
        }
Exemple #3
0
        public void TestDisposeAndReConfiguration()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            Assert.IsNotNull(container);

            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));

            container.ExpandConfiguration(new ComplexConfig());
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            container.Reconfigure();
            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            IAggregate aggregate = container.GetObject<IAggregate>();
            Assert.IsNotNull(aggregate);

            var b = container.GetObject("SomeDomainCmdServiceB");
            Assert.IsNotNull(b);

            container.Dispose();

            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject("SomeDomainCmdServiceB"));
            container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            Assert.IsNotNull(container);

            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));

            container.ExpandConfiguration(new ComplexConfig());
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            container.Reconfigure();
            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            aggregate = container.GetObject<IAggregate>();
            Assert.IsNotNull(aggregate);

            b = container.GetObject("SomeDomainCmdServiceB");
            Assert.IsNotNull(b);
        }
Exemple #4
0
        public void TestGetPrototypeFromContainerObjArgsWithId()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC()).Reconfigure();

            Prototype prototype = (Prototype)container.GetObject(typeof(Prototype).FullName);
            Assert.IsNotNull(prototype);
        }
Exemple #5
0
        public void TestGetPrototypeFromContainerGenericArgs()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC()).Reconfigure();

            Prototype prototype = container.GetObject<Prototype>();
            Assert.IsNotNull(prototype);
        }
Exemple #6
0
        public void TestGetObjectsInheritingFromSuperClassFromContainer()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig());
            container.Reconfigure();
            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            List<ISomeDomainCmdService> someDomainCmdServices = container.GetAllObjectsInheriting<ISomeDomainCmdService>();
            Assert.AreEqual(2, someDomainCmdServices.Count);

            List<SomeDomainCmdServiceC> someDomainCmdServicesC = container.GetAllObjectsInheriting<SomeDomainCmdServiceC>();
            Assert.AreEqual(0, someDomainCmdServicesC.Count);
        }
Exemple #7
0
        public void TestGetObjectsInheritingFromPrototypeSuperClassFromContainer()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig());
            container.Reconfigure();

            List<Prototype> prototypes = container.GetAllObjectsInheriting<Prototype>();
            Assert.AreEqual(1, prototypes.Count);
        }
Exemple #8
0
        public void TestGetObjectFromContainer()
        {
            var container = new DependencyInjector(new ServiceConfiguration(), new MoreConfig());
            container.ExpandConfiguration(new ComplexConfig(), new ServiceConfigurationC());
            container.Reconfigure();
            Assert.IsTrue(container.ContainsObject<ISomeDomainCmdService>());
            Assert.IsTrue(container.ContainsObject<ICommandManager>());
            Assert.IsTrue(container.ContainsObject("SomeDomainCmdServiceB"));
            Assert.IsTrue(container.ContainsObject<IAggregate>());

            IAggregate aggregate = container.GetObject<IAggregate>();
            Assert.IsNotNull(aggregate);

            var b = container.GetObject("SomeDomainCmdServiceB");
            Assert.IsNotNull(b);

            // If some instance uniquely implements interface but the object definition id is specified, can it still be retrieved through the interface??
            ISomeNewDomainCmdService newCmdService = container.GetObject<ISomeNewDomainCmdService>();
            Assert.IsNotNull(newCmdService);
            SomeNewDomainCmdService newCmdService2 = container.GetObject<SomeNewDomainCmdService>();
            Assert.IsNotNull(newCmdService2);
            var serviceD = container.GetObject<SomeDomainCmdServiceD>("D");

            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<ISomeDomainCmdService>());
            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<SomeDomainCmdServiceD>());
            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<SomeDomainCmdServiceD>("E"));
            Assert.Throws<DependencyInjectorGetObjectException>(() => container.GetObject<INotImplementedInterface>());
        }