Exemplo n.º 1
0
        public void DependyContainerShouldThrowDependyNotRegisteredExceptionIfDependencyNotFound()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();

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

            // Act.
            dependyContainer.Get <IUserFactory>();
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 11
0
        public void DependyContainerShouldThrowDependyNotRegisteredExceptionIfDependencyNotFound()
        {
            // Arrange.
            var dependyContainer = new DependyContainer();
            dependyContainer.Add<IUserServiceStub, UserServiceStub>();
            dependyContainer.Add<IUserFactory, GeneralUserFactory>();

            // Act.
            dependyContainer.Get<IUserFactory>();
        }
Exemplo n.º 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);
        }