Example #1
0
        public void DependyContainerShouldThrowDependyNotRegisteredExceptionIfDependencyNotFound()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();

            dependyContainer.Add <IUserServiceStub, UserServiceStub>();
            dependyContainer.Add <IUserFactory, GeneralUserFactory>();

            // Act.
            dependyContainer.Get <IUserFactory>();
        }
Example #2
0
        public void DependyContainerShouldSupportParameterConstructorsAutomatically()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();

            dependyContainer.Add <IHelpServiceStub, HelpServiceStub>();
            dependyContainer.Add <IUserServiceStub, UserServiceStub>();
            dependyContainer.Add <IUserFactory, GeneralUserFactory>();

            // Act.
            var result = dependyContainer.Get <IUserFactory>();

            // Assert.
            Assert.IsInstanceOf <GeneralUserFactory>(result);
        }
        public void DependyContainerShouldBeAbleToAddAndGetAdminUserFactoryDynamically()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();
            dependyContainer.Add<IUserFactory, AdminUserFactory>();

            // Act.
            var result = dependyContainer.Get(typeof(IUserFactory));

            // Assert.
            Assert.IsInstanceOf<AdminUserFactory>(result);
        }
        public void DependyContainerShouldSupportTransientLifecycle()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();
            dependyContainer.Add<IUserFactory, AdminUserFactory>(Lifecycle.Transient);

            // Act.
            var factoryOne = (AdminUserFactory)dependyContainer.Get<IUserFactory>();
            var factoryTwo = (AdminUserFactory)dependyContainer.Get<IUserFactory>();
            
            // Assert.
            Assert.AreNotEqual(factoryOne.FactoryGuid, factoryTwo.FactoryGuid);
        }
Example #5
0
        public void DependyContainerShouldBeAbleToAddAndGetAdminUserFactoryDynamically()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();

            dependyContainer.Add <IUserFactory, AdminUserFactory>();

            // Act.
            var result = dependyContainer.Get(typeof(IUserFactory));

            // Assert.
            Assert.IsInstanceOf <AdminUserFactory>(result);
        }
Example #6
0
        public void DependyContainerShouldAcceptInjectorToResolveDependencies()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();

            dependyContainer.Add <IUserFactory, GeneralUserFactory>(new Injector(new UserServiceStub(), new HelpServiceStub()));

            // Act.
            var result = dependyContainer.Get <IUserFactory>();

            // Assert.
            Assert.IsInstanceOf <GeneralUserFactory>(result);
        }
Example #7
0
        public void DependyContainerShouldSupportSingletonLifecycle()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();

            dependyContainer.Add <IUserFactory, AdminUserFactory>(Lifecycle.Singleton);

            // Act.
            var factoryOne = (AdminUserFactory)dependyContainer.Get <IUserFactory>();
            var factoryTwo = (AdminUserFactory)dependyContainer.Get <IUserFactory>();

            // Assert.
            Assert.AreEqual(factoryOne.FactoryGuid, factoryTwo.FactoryGuid);
        }
Example #8
0
        public void DependyContainerShouldAcceptInjectorToResolveDependenciesAndSpecifyTransientLifecycle()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();

            dependyContainer.Add <IUserFactory, GeneralUserFactory>(new Injector(new UserServiceStub(), new HelpServiceStub()), Lifecycle.Transient);

            // Act.
            var result        = dependyContainer.Get <IUserFactory>();
            var result2       = dependyContainer.Get <IUserFactory>();
            var castedResult  = (GeneralUserFactory)result;
            var castedResult2 = (GeneralUserFactory)result2;

            // Assert.
            Assert.IsInstanceOf <GeneralUserFactory>(result);
            Assert.AreNotEqual(castedResult.FactoryGuid, castedResult2.FactoryGuid);
        }
        public void DependyContainerShouldAcceptInjectorToResolveDependenciesAndSpecifyTransientLifecycle()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();
            dependyContainer.Add<IUserFactory, GeneralUserFactory>(new Injector(new UserServiceStub(), new HelpServiceStub()), Lifecycle.Transient);

            // Act.
            var result = dependyContainer.Get<IUserFactory>();
            var result2 = dependyContainer.Get<IUserFactory>();
            var castedResult = (GeneralUserFactory)result;
            var castedResult2 = (GeneralUserFactory)result2;

            // Assert.
            Assert.IsInstanceOf<GeneralUserFactory>(result);
            Assert.AreNotEqual(castedResult.FactoryGuid, castedResult2.FactoryGuid);
        }
        public void DependyContainerShouldAcceptInjectorToResolveDependencies()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();
            dependyContainer.Add<IUserFactory, GeneralUserFactory>(new Injector(new UserServiceStub(), new HelpServiceStub()));

            // Act.
            var result = dependyContainer.Get<IUserFactory>();

            // Assert.
            Assert.IsInstanceOf<GeneralUserFactory>(result);
        }
        public void DependyContainerShouldThrowDependyNotRegisteredExceptionIfDependencyNotFound()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();
            dependyContainer.Add<IUserServiceStub, UserServiceStub>();
            dependyContainer.Add<IUserFactory, GeneralUserFactory>();

            // Act.
            dependyContainer.Get<IUserFactory>();
        }
        public void DependyContainerShouldSupportParameterConstructorsAutomatically()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();
            dependyContainer.Add<IHelpServiceStub, HelpServiceStub>();
            dependyContainer.Add<IUserServiceStub, UserServiceStub>();
            dependyContainer.Add<IUserFactory, GeneralUserFactory>();

            // Act.
            var result = dependyContainer.Get<IUserFactory>();

            // Assert.
            Assert.IsInstanceOf<GeneralUserFactory>(result);
        }