public void TestUsingProfileWithIgnoreDoesntAffectOtherProfiles() { //SETUP var profile1 = new UnitTestProfile(true); profile1.AddWriteMap <WriteAuthorReadOnlyDto, Author>(); var config1 = new MapperConfiguration(cfg => cfg.AddProfile(profile1)); var profile2 = new UnitTestProfile(false); profile2.AddWriteMap <WriteAuthorReadOnlyDto, Author>(); var config2 = new MapperConfiguration(cfg => cfg.AddProfile(profile2)); //ATTEMPT var dto = new WriteAuthorReadOnlyDto { AuthorId = 123, Name = "New Name", Email = "*****@*****.**" }; var entity1 = new Author { AuthorId = 1, Name = "Start Name", Email = "*****@*****.**" }; config1.CreateMapper().Map(dto, entity1); var entity2 = new Author { AuthorId = 1, Name = "Start Name", Email = "*****@*****.**" }; config2.CreateMapper().Map(dto, entity2); //VERIFY entity1.Email.ShouldEqual("*****@*****.**"); //not changed - ReadOnly entity2.Email.ShouldEqual("*****@*****.**"); //changes }
public void TestUsingProfileWithIgnore() { //SETUP var entity = new Author { AuthorId = 1, Name = "Start Name", Email = "*****@*****.**" }; var profile = new UnitTestProfile(true); profile.AddWriteMap <WriteAuthorReadOnlyDto, Author>(); var config = new MapperConfiguration(cfg => cfg.AddProfile(profile)); //ATTEMPT var dto = new WriteAuthorReadOnlyDto { AuthorId = 123, Name = "New Name", Email = "*****@*****.**" }; var mapper = config.CreateMapper(); var data = mapper.Map(dto, entity); //VERIFY data.Name.ShouldEqual("New Name"); //changed data.AuthorId.ShouldEqual(123); //changed data.Email.ShouldEqual("*****@*****.**"); //not changed - ReadOnly }