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

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

            // Act.
            dependyContainer.Get <IUserFactory>();
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#10
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);
        }
示例#11
0
        public void DependyContainerShouldThrowDependyNotRegisteredExceptionIfDependencyNotFound()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();
            dependyContainer.Add<IUserServiceStub, UserServiceStub>();
            dependyContainer.Add<IUserFactory, GeneralUserFactory>();

            // Act.
            dependyContainer.Get<IUserFactory>();
        }
示例#12
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);
        }