public void SingleObjectTest() { MapFactory.ResetAllMaps(); var target = new InnType { DateTimeValue = DateTime.Now, DesimalValue = (decimal)100.212, StringValue = "test", MyEnum = Mock.MyEnum.something }; var map = MapFactory.CreateEmptyMapRule <InnType, OutType>(); map.AddMap <InnType, OutType>(new Dictionary <string, string> { { "DateTimeValue", "DateTimeValue1" }, { "DesimalValue", "DesimalValue1" }, { "StringValue", "StringValue1" } }); map.GetRule <InnType, OutType>().Add(r => r.MyEnum, r => r.MyEnumName).Add(r => r.MyEnum, r => r.MyEnumVal); var result = target.Map().To <OutType>(map); Assert.IsNotNull(result); Assert.AreEqual(target.DateTimeValue.ToString("g"), result.DateTimeValue1); Assert.AreEqual(target.DesimalValue, result.DesimalValue1); Assert.AreEqual(target.StringValue, result.StringValue1); Assert.AreEqual("something", result.MyEnumName); Assert.AreEqual(2, result.MyEnumVal); }
public void MergeDataWithSameBaseType() { MapFactory.CreateMapRule <InnType, InnType>(true).GetRule().RemoveMapping("MyInts").RemoveMapping("DesimalValue"); var inValue = new InnType { DateTimeValue = DateTime.Now, MyInts = new List <int>(), StringValue = "Updated string", DesimalValue = 100 }; var targetValue = new InnType { DateTimeValue = DateTime.Now.AddYears(-1), MyInts = new List <int>(), StringValue = "original string", DesimalValue = 0 }; var newTarget = inValue.Map().To(targetValue); Assert.AreNotSame(inValue, newTarget); Assert.AreEqual(inValue.StringValue, newTarget.StringValue); Assert.AreEqual(inValue.DateTimeValue, newTarget.DateTimeValue); Assert.AreNotEqual(inValue.DesimalValue, newTarget.DesimalValue); }