Пример #1
0
        public void WHEN_register_dependency_THEN_dependency_can_be_found()
        {
            // Arrange
            var dependencies = new IDependency[]
            { new Dependency(typeof(TestClass), LifeTime.OnRequest) };

            // Act
            _adapter.Register(dependencies);

            // Assert
            var instance = _container.Get <TestClass>();

            instance.StringValue = "test";

            var onRequest = _container.Get <TestClass>();

            onRequest.StringValue.Should().Be(null);
        }
Пример #2
0
        public void WHEN_lifetime_is_onRequest_THEN_instance_is_onRequest()
        {
            // Arrange
            var dependencies = new IDependency[]
            { new InterfaceDependency(typeof(ITestClass), typeof(TestClass), LifeTime.OnRequest), };

            // Act
            _adapter.Register(dependencies);

            // Assert
            var instance = _container.Get <ITestClass>();

            instance.StringValue = "test";

            var onRequest = _container.Get <ITestClass>();

            onRequest.StringValue.Should().Be(null);
        }
Пример #3
0
        public void WHEN_register_by_name_and_use_factory_THEN_correct_implementation_is_returned()
        {
            // Arrange
            var dependencies = new IDependency[]
            {
                new InterfaceDependency(typeof(ITestClassFactory), typeof(TestClassFactory), LifeTime.Singleton),
                new NinjectNamedDependency(typeof(ITestClass), typeof(TestClass), LifeTime.OnRequest, typeof(TestClass).Name),
                new NinjectNamedDependency(typeof(ITestClass), typeof(TestClassTwo), LifeTime.OnRequest, typeof(TestClassTwo).Name)
            };

            // Act
            _adapter.Register(dependencies);

            // Assert
            var factory = _container.Get <ITestClassFactory>();

            var implementationOne = factory.Create(typeof(TestClass).Name);

            implementationOne.Should().BeOfType <TestClass>();

            var implementationTwo = factory.Create(typeof(TestClassTwo).Name);

            implementationTwo.Should().BeOfType <TestClassTwo>();
        }