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>()); }
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); }
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)); }
public void ShouldResetTheContainer() { //Arrange var containerExtension = new StructureMapExtension(registrationHelper, options); containerExtension.Run(); //Act containerExtension.Reset(); //Assert Assert.IsNull(containerExtension.Container); }
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); }
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)); }
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>()); }
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 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()); }
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>()); }