Пример #1
0
        public void UsingAutoRegistration_WhenSpecified_ShouldRegisterWithConventionAndWithRegistrationClasses()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(TestSimpleInjectorRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            A.CallTo(() => registrationHelper.GetTypesImplementing <ISimpleInjectorRegistration>(assembly))
            .Returns(new List <Type> {
                typeof(TestSimpleInjectorRegistration)
            });
            A.CallTo(() => registrationHelper.GetInstancesOfTypesImplementing <ISimpleInjectorRegistration>())
            .Returns(new List <ISimpleInjectorRegistration> {
                new TestSimpleInjectorRegistration()
            });
            var containerExtension = new SimpleInjectorExtension(registrationHelper, options);

            A.CallTo(() => options.AutoRegistration).Returns(true);

            //Act
            containerExtension.Run();

            //Assert
            Assert.IsNotNull(containerExtension.Resolve <SimpleInjectorExtension>());
            Assert.IsNotNull(containerExtension.Resolve <IRegisteredByConvention>());
        }
        public void Run_WhenInvokedAndAutoMapperExtensionIsLoaded_ShouldRegisterMapperAsSingelton()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(AutoMapperRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies())
            .Returns(new List <Assembly> {
                assembly
            });
            A.CallTo(() => registrationHelper.GetTypesImplementing <IBootstrapperRegistration>(assembly))
            .Returns(new List <Type> {
                typeof(AutoMapperRegistration)
            });
            A.CallTo(() => registrationHelper.GetInstancesOfTypesImplementing <IBootstrapperRegistration>())
            .Returns(new List <IBootstrapperRegistration> {
                new AutoMapperRegistration()
            });
            var containerExtension = new SimpleInjectorExtension(registrationHelper, options);

            //Act
            containerExtension.Run();

            //Assert
            Assert.IsNotNull(containerExtension.Resolve <IProfileExpression>());
            Assert.AreSame(Mapper.Configuration, containerExtension.Resolve <IProfileExpression>());
            Assert.AreSame(Mapper.Engine, containerExtension.Resolve <IMappingEngine>());
            Assert.AreSame(containerExtension.Resolve <IProfileExpression>(), containerExtension.Resolve <IProfileExpression>());
            Assert.AreSame(containerExtension.Resolve <IMappingEngine>(), containerExtension.Resolve <IMappingEngine>());
        }
Пример #3
0
        public void Resolve_WhenInvokedAndContainerIsNotInitialized_ShouldThrowException()
        {
            //Arrange
            var containerExtension = new SimpleInjectorExtension(registrationHelper, options);

            //Act
            var result = ExceptionAssert.Throws <NoContainerException>(() => containerExtension.Resolve <object>());

            //Assert
            Assert.AreEqual(NoContainerException.DefaultMessage, result.Message);
        }
Пример #4
0
        public void Resolve_WhenInvokedWithAGenericType_ShouldResolveToASingleInstance()
        {
            //Arrange
            var containerExtension = new SimpleInjectorExtension(registrationHelper, options);
            var container          = A.Fake <Container>();
            var instance           = new object();

            container.RegisterSingleton(instance);
            containerExtension.InitializeContainer(container);

            //Act
            var result = containerExtension.Resolve <object>();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreSame(instance, result);
        }
Пример #5
0
        public void Run_WhenInvoked_ShouldInvokeTheRegisterMethodOfAllISimpleInjectorRegistrationTypes()
        {
            //Arrange
            var assembly = Assembly.GetExecutingAssembly();

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            A.CallTo(() => registrationHelper.GetTypesImplementing <ISimpleInjectorRegistration>(assembly))
            .Returns(new List <Type> {
                typeof(TestSimpleInjectorRegistration)
            });
            A.CallTo(() => registrationHelper.GetInstancesOfTypesImplementing <ISimpleInjectorRegistration>())
            .Returns(new List <ISimpleInjectorRegistration> {
                new TestSimpleInjectorRegistration()
            });
            var containerExtension = new SimpleInjectorExtension(registrationHelper, options);

            //Act
            containerExtension.Run();

            //Assert
            Assert.IsNotNull(containerExtension.Resolve <SimpleInjectorExtension>());
        }