public void ShouldCreateMapsFromMapCreatorsAndProfiles() { //Arrange Mapper.Reset(); var containerExtension = A.Fake <IBootstrapperContainerExtension>(); var mapCreators = new List <IMapCreator> { new TestAutoMapperMapCreator() }; var profiles = new List <Profile> { new TestAutoMapperProfile() }; A.CallTo(() => containerExtension.ResolveAll <IMapCreator>()).Returns(mapCreators); A.CallTo(() => containerExtension.ResolveAll <Profile>()).Returns(profiles); Bootstrapper.With.Extension(containerExtension); var mapperExtension = new AutoMapperExtension(registrationHelper); var from = A.Fake <ITestInterface>(); //Act mapperExtension.Run(); var result1 = Mapper.Map <ITestInterface, TestImplementation>(from); var result2 = Mapper.Map <TestImplementation, AnotherTestImplementation>(result1); //Assert Assert.IsNotNull(result1); Assert.IsNotNull(result2); Assert.IsInstanceOfType(result1, typeof(TestImplementation)); Assert.IsInstanceOfType(result2, typeof(AnotherTestImplementation)); }
public void ShouldInvokeCreateMapForAllMapCreatorsWhenNoContainerExtensionHasBeenDeclared() { //Arrange var mapCreators = new List <IMapCreator> { A.Fake <IMapCreator>(), A.Fake <IMapCreator>() }; A.CallTo(() => registrationHelper.GetInstancesOfTypesImplementing <IMapCreator>()).Returns(mapCreators); var mapperExtension = new AutoMapperExtension(registrationHelper); //Act mapperExtension.Run(); //Assert A.CallTo(() => registrationHelper.GetInstancesOfTypesImplementing <IMapCreator>()).MustHaveHappened(); mapCreators.ForEach(m => A.CallTo(() => m.CreateMap(A <IProfileExpression> .Ignored)).MustHaveHappened()); }
public void ShouldInvokeConfigureForAllProfilesWhenNoContainerExtensionHasBeenDeclared() { //Arrange var profiles = new List <Profile> { new TestAutoMapperProfile() }; A.CallTo(() => registrationHelper.GetInstancesOfTypesImplementing <Profile>()).Returns(profiles); var mapperExtension = new AutoMapperExtension(registrationHelper); var from = A.Fake <ITestInterface>(); //Act mapperExtension.Run(); var result = Mapper.Map <ITestInterface, TestImplementation>(from); //Assert A.CallTo(() => registrationHelper.GetInstancesOfTypesImplementing <Profile>()).MustHaveHappened(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(TestImplementation)); }
public void ShouldResetMapper() { //Arrange var containerExtension = A.Fake <IBootstrapperContainerExtension>(); var profiles = new List <Profile> { new TestAutoMapperProfile() }; A.CallTo(() => containerExtension.ResolveAll <Profile>()).Returns(profiles); Bootstrapper.With.Extension(containerExtension); var mapperExtension = new AutoMapperExtension(registrationHelper); mapperExtension.Run(); Assert.AreNotEqual(0, AutoMapperExtension.ConfigurationProvider.GetAllTypeMaps().Length); //Act mapperExtension.Reset(); //Assert Assert.AreEqual(0, AutoMapperExtension.ConfigurationProvider.GetAllTypeMaps().Length); }
public void ShouldInvokeConfigureForAllRegisteredProfiles() { //Arrange var containerExtension = A.Fake <IBootstrapperContainerExtension>(); var profiles = new List <Profile> { new TestAutoMapperProfile() }; A.CallTo(() => containerExtension.ResolveAll <Profile>()).Returns(profiles); Bootstrapper.With.Extension(containerExtension); var mapperExtension = new AutoMapperExtension(registrationHelper); var from = A.Fake <ITestInterface>(); //Act mapperExtension.Run(); var result = AutoMapperExtension.Mapper.Map <ITestInterface, TestImplementation>(from); //Assert A.CallTo(() => containerExtension.ResolveAll <Profile>()).MustHaveHappened(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(TestImplementation)); }
public void ShouldInvokeCreateMapForAllRegisteredMapCreators() { //Arrange var containerExtension = A.Fake <IBootstrapperContainerExtension>(); var mapCreators = new List <IMapCreator> { A.Fake <IMapCreator>(), A.Fake <IMapCreator>() }; A.CallTo(() => containerExtension.ResolveAll <IMapCreator>()).Returns(mapCreators); Bootstrapper.With.Extension(containerExtension); var mapperExtension = new AutoMapperExtension(registrationHelper); //Act mapperExtension.Run(); //Assert A.CallTo(() => containerExtension.ResolveAll <IMapCreator>()).MustHaveHappened(); foreach (var mapCreator in mapCreators) { var creator = mapCreator; A.CallTo(() => creator.CreateMap(A <IProfileExpression> .Ignored)).MustHaveHappened(); } }