Ejemplo n.º 1
0
        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(AutoMapperExtension.ConfigurationProvider, containerExtension.Resolve <IConfigurationProvider>());
            Assert.AreSame(AutoMapperExtension.ProfileExpression, containerExtension.Resolve <IProfileExpression>());
            Assert.AreSame(AutoMapperExtension.Mapper, containerExtension.Resolve <IMapper>());
            Assert.AreSame(AutoMapperExtension.Engine, containerExtension.Resolve <IMappingEngine>());
            Assert.AreSame(containerExtension.Resolve <IConfigurationProvider>(), containerExtension.Resolve <IConfigurationProvider>());
            Assert.AreSame(containerExtension.Resolve <IProfileExpression>(), containerExtension.Resolve <IProfileExpression>());
            Assert.AreSame(containerExtension.Resolve <IMapper>(), containerExtension.Resolve <IMapper>());
            Assert.AreSame(containerExtension.Resolve <IMappingEngine>(), containerExtension.Resolve <IMappingEngine>());
        }
Ejemplo n.º 2
0
        public void Run_WhenTheContainerInOptionsIsSet_ShouldUseTheExistingContainer()
        {
            //Arrange
            var assembly = Assembly.GetAssembly(typeof(TestStructureMapRegistration));

            A.CallTo(() => registrationHelper.GetAssemblies())
            .Returns(new List <Assembly> {
                assembly
            });
            A.CallTo(() => registrationHelper.GetTypesImplementing <IStructureMapRegistration>(assembly))
            .Returns(new List <Type> {
                typeof(TestStructureMapRegistration)
            });
            var container          = new Container();
            var containerExtension = new StructureMapExtension(registrationHelper, options)
            {
                Options = { Container = container }
            };


            //Act
            containerExtension.Run();

            //Assert
            Assert.AreSame(container, containerExtension.Container);
        }
Ejemplo n.º 3
0
        public void ShouldReturnAnIContainer()
        {
            //Arrange
            var containerExtension = new StructureMapExtension(registrationHelper, options);

            //Act
            containerExtension.Run();
            var result = containerExtension.Container;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IContainer));
        }
Ejemplo n.º 4
0
        public void ShouldResetTheContainer()
        {
            //Arrange
            var containerExtension = new StructureMapExtension(registrationHelper, options);

            containerExtension.Run();

            //Act
            containerExtension.Reset();

            //Assert
            Assert.IsNull(containerExtension.Container);
        }
Ejemplo n.º 5
0
        public void ShouldResetTheServiceLocator()
        {
            //Arrange
            ServiceLocator.SetLocatorProvider(A.Fake <IServiceLocator>);
            var containerExtension = new StructureMapExtension(registrationHelper, options);

            containerExtension.Run();

            //Act
            containerExtension.ResetServiceLocator();

            //Assert
            Assert.IsNull(ServiceLocator.Current);
        }
Ejemplo n.º 6
0
        public void ShouldSetTheServiceLocator()
        {
            //Arrange
            ServiceLocator.SetLocatorProvider(() => null);
            var containerExtension = new StructureMapExtension(registrationHelper, options);

            containerExtension.Run();

            //Act
            containerExtension.SetServiceLocator();
            var result = ServiceLocator.Current;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StructureMapServiceLocator));
        }
Ejemplo n.º 7
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>());
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        public void ShouldRegisterAllTypesOfIBootstrapperRegistration()
        {
            //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();
            var result = containerExtension.ResolveAll <IBootstrapperRegistration>();

            //Assert
            A.CallTo(() => registrationHelper.GetAssemblies()).MustHaveHappened();
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IEnumerable <IBootstrapperRegistration>));
            Assert.IsTrue(result.Any());
        }
Ejemplo n.º 10
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>());
        }