Beispiel #1
0
        public void ShouldThrowNoContainerExceptionWhenResolvingSimpleTypeBeforeInitializingTheContainer()
        {
            //Arrange
            var containerExtension = new StructureMapExtension(registrationHelper, options);

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

            //Assert
            Assert.AreEqual(NoContainerException.DefaultMessage, result.Message);
        }
Beispiel #2
0
        public void ShouldRegisterWithConventionAndWithRegistration()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(StructureMapExtensionTests));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });

            var containerExtension = new StructureMapExtension(registrationHelper, options);

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

            //Act
            containerExtension.Run();

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            Assert.IsNotNull(containerExtension.Resolve <StructureMapExtension>());
            Assert.IsNotNull(containerExtension.Resolve <IRegisteredByConvention>());
        }
Beispiel #3
0
        public void ShouldInvokeTheRegisterMethodOfAllIBootstrapperRegistrationTypes()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(AutoMapperRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            var containerExtension = new StructureMapExtension(registrationHelper, options);

            //Act
            containerExtension.Run();

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            Assert.IsNotNull(containerExtension.Resolve <IProfileExpression>());
        }
Beispiel #4
0
        public void ShouldResolveASingleType()
        {
            //Arrange
            var containerExtension = new StructureMapExtension(registrationHelper, options);
            var container          = A.Fake <IContainer>();

            containerExtension.InitializeContainer(container);
            var instance = new object();

            A.CallTo(() => container.GetInstance <object>()).Returns(instance);

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

            //Assert
            A.CallTo(() => container.GetInstance <object>()).MustHaveHappened();
            Assert.IsNotNull(result);
            Assert.AreSame(instance, result);
        }
Beispiel #5
0
        public void ShouldInvokeRegistrationsOfAllRegistryTypes()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(TestStructureMapRegistry));

            A.CallTo(() => registrationHelper.GetAssemblies()).Returns(new List <Assembly> {
                assembly
            });
            var containerExtension = new StructureMapExtension(registrationHelper, options);

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

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ITestInterface));
        }
        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)
            });
            var containerExtension = new StructureMapExtension(registrationHelper, options);

            //Act
            containerExtension.Run();

            //Assert
            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>());
        }