public void Mapper_WhenMappingPolicyTransaction_MapsAllValuesCorrectly() { // Arrange var mapper = new PolicyTransactionMapper(); var address = new AddressDto() { Line1 = "Line1", Line2 = "Line2", Town = "Town" }; var modelFrom = new PolicyTransaction() { PolicyId = "PolicyId" }; modelFrom.Addresses.Add(address); Models.Domain.IPolicyTransaction modelTo = Substitute.For <Models.Domain.IPolicyTransaction>(); modelTo.Addresses = new List <Address>(); // Act mapper.Map(modelFrom, modelTo); // Assert Assert.Equal("PolicyId", modelTo.PolicyId); Assert.Single(modelTo.Addresses); Assert.Collection(modelTo.Addresses, first => { Assert.Equal("Line1", first.Line1); Assert.Equal("Line2", first.Line2); Assert.Equal("Town", first.Town); }); }
public void Mapper_WhenMappingPolicyTransaction_MapsAllValuesCorrectly_Fluent() { // Arrange var mapper = new PolicyTransactionMapper(); var address = new AddressDto() { Line1 = "Line1", Line2 = "Line2", Line3 = "Line3", Town = "Town" }; var modelFrom = new PolicyTransaction() { PolicyId = "PolicyId" }; modelFrom.Addresses.Add(address); Models.Domain.IPolicyTransaction modelTo = Substitute.For <Models.Domain.IPolicyTransaction>(); modelTo.Addresses = new List <Address>(); // Act mapper.Map(modelFrom, modelTo); // Assert modelTo.Addresses.Should().SatisfyRespectively( first => { first.Line1.Should().Be("Line1"); first.Line2.Should().Be("Line2"); first.Line3.Should().BeNull(); first.Town.Should().Be("Town"); }); }
public void Map(Models.Dto.IPolicyTransaction from, Models.Domain.IPolicyTransaction to) { to.PolicyId = from.PolicyId; foreach (var address in from.Addresses) { var domainAddress = new Address() { Line1 = address.Line1, Line2 = address.Line2, Line3 = address.Line3, Town = address.Town }; to.Addresses.Add(domainAddress); } }