private static void CreateMap(TypeA source, TypeC dest) { dest.Name = source.Title; dest.Timestamp = source.Timestamp.ToUniversalTime(); if ((string.IsNullOrEmpty(source.Title)) || (string.IsNullOrEmpty(source.Description))) { dest.Status = Status.NotValid; } else { if (source.IsNew) { dest.Status = Status.IsNew; } else if (source.IsArchive) { dest.Status = Status.Old; } else { dest.Status = Status.Ready; } } }
public void CustomMappingTest() { TypeA objA = new TypeA { Title = "My title", Description = "My description", Timestamp = DateTime.Now, IsArchive = true }; DataMapper mapper = new DataMapper(); mapper.Register <TypeA, TypeC>(CreateMap); TypeC objC = mapper.Map <TypeA, TypeC>(objA); Assert.AreEqual(objA.Title, objC.Name); Assert.AreEqual(objA.Description, objC.Description); Assert.AreEqual(objA.Timestamp.ToUniversalTime(), objC.Timestamp); Assert.AreEqual(Status.Old, objC.Status); }