I have the following classes.
public class Person {
public string Name { get; set; }
public Address Address { get; set; }
}
public class PersonDTO {
public string Name { get; set; }
public Address Address { get; set; }
}
I create a standard mapping using
Mapper.CreateMap<Person, PersonDTO>();
Then I'd like to map a Person into an existing PersonDTO hierarchy in that way that the existing Address will be updated instead of reference copied if you know what I mean.
var person = new Person() {
Name = "Test",
Address = new Address() {
Country = "USA",
City = "New York"
}
};
var personDTO = new PersonDTO() {
Name = "Test2",
Address = new Address() {
Country = "Canada",
City = "Ottawa"
}
};
Mapper.Map(person, personDTO);
I'd like to fulfill the following tests.
Assert.AreNotEqual(person.Address, personDTO.Address);
Assert.AreEqual(person.Address.Country, personDTO.Address.Country);
Assert.AreEqual(person.Address.City, personDTO.Address.City);