public void MemberIsAddedToIncompatibleMappingsIfConversionCantBeMade() { var mapper = new MemberMapper(); mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true; mapper.AddCustomConstructor <Guid>(() => Guid.NewGuid()); var result = mapper.Map <DateTimeSource, GuidDestination>(new DateTimeSource()); }
public void CustomConstructorOnMapperIsRespected() { var mapper = new MemberMapper(); mapper.AddCustomConstructor<NestedDestinationType>(() => new NestedDestinationType(1)); var source = new SourceType { Foo = new NestedSourceType { ID = 10 } }; var result = mapper.Map<SourceType, DestinationType>(source); Assert.AreEqual(1, result.Foo.OtherID); Assert.AreEqual(10, result.Foo.ID); }
public void CustomConstructorOnMapperIsRespected() { var mapper = new MemberMapper(); mapper.AddCustomConstructor <NestedDestinationType>(() => new NestedDestinationType(1)); var source = new SourceType { Foo = new NestedSourceType { ID = 10 } }; var result = mapper.Map <SourceType, DestinationType>(source); Assert.AreEqual(1, result.Foo.OtherID); Assert.AreEqual(10, result.Foo.ID); }
public void CustomConstructorOnProposalTakesPrecedence() { var mapper = new MemberMapper(); mapper.AddCustomConstructor<NestedDestinationType>(() => new NestedDestinationType(1)); mapper.CreateMapProposal<SourceType, DestinationType>() .WithConstructorFor<NestedDestinationType>((src, dest) => new NestedDestinationType(2)) .FinalizeMap(); var source = new SourceType { Foo = new NestedSourceType { ID = 10 } }; var result = mapper.Map<SourceType, DestinationType>(source); Assert.AreEqual(2, result.Foo.OtherID); Assert.AreEqual(10, result.Foo.ID); }
public void CustomConstructorOnProposalTakesPrecedence() { var mapper = new MemberMapper(); mapper.AddCustomConstructor <NestedDestinationType>(() => new NestedDestinationType(1)); mapper.CreateMapProposal <SourceType, DestinationType>() .WithConstructorFor <NestedDestinationType>((src, dest) => new NestedDestinationType(2)) .FinalizeMap(); var source = new SourceType { Foo = new NestedSourceType { ID = 10 } }; var result = mapper.Map <SourceType, DestinationType>(source); Assert.AreEqual(2, result.Foo.OtherID); Assert.AreEqual(10, result.Foo.ID); }
public void MemberIsAddedToIncompatibleMappingsIfConversionCantBeMade() { var mapper = new MemberMapper(); mapper.Options.Strictness.ThrowWithoutCorrespondingSourceMember = true; mapper.AddCustomConstructor<Guid>(() => Guid.NewGuid()); var result = mapper.Map<DateTimeSource, GuidDestination>(new DateTimeSource()); }