public void ManualMapperMapErrorTest() { var target = new ManualMapper<FromTestClass, ToTestClass>(); var source = new FromTestClass() { Id = 5, Description = "test" }; var targetObj = new ToTestClass(); target.AddMappingAction("Id", "Code", (f, t) => { throw new InvalidOperationException(); }); target.Map(source, targetObj); }
public void Map_InvalidMappingAction_WrapsAndThrows() { var sut = new ManualMapper<FromTestClass, ToTestClass>(); var source = new FromTestClass {Id = 5, Description = "test"}; var targetObj = new ToTestClass(); sut.AddMappingAction("Id", "Code", (f, t) => { throw new InvalidOperationException(); }); Should.Throw<MappingException>(() => sut.Map(source, targetObj)); }
public async Task Map_ManualMappingsWithTarget_MapsCorrectly() { var source = new FromTestClass(); var sut = SetupTest(source); var target = new ToTestClass(); await sut.MapAsync(source, target); CheckMapping(source, target); }
public void MapExplicit() { var from = new FromTestClass(); var to = new ToTestClass(); Mapper.MapExplicit(from, to, new[] { "PublicProp" }); Assert.AreEqual(to.PublicField, 2); Assert.AreEqual(to.PublicProp, 1); Assert.AreEqual(to.PublicReadOnlyProp, 2); }
public void MapTestExceptions() { var from = new FromTestClass(); var to = new ToTestClass(); Mapper.MapExcept(from, to, "PublicField"); Assert.AreEqual(to.PublicField, 2); Assert.AreEqual(to.PublicProp, 1); Assert.AreEqual(to.PublicReadOnlyProp, 1); }
public void MapBasic() { var from = new FromTestClass(); var to = new ToTestClass(); Mapper.MapExcept(from, to); Assert.AreEqual(to.PublicField, 1); Assert.AreEqual(to.PublicProp, 1); Assert.AreEqual(to.PublicReadOnlyProp, 1); }
public void Map_InvalidMappingAction_WrapsAndThrows() { var sut = new ManualMapper <FromTestClass, ToTestClass>(); var source = new FromTestClass { Id = 5, Description = "test" }; var targetObj = new ToTestClass(); sut.AddMappingAction("Id", "Code", (f, t) => { throw new InvalidOperationException(); }); Should.Throw <MappingException>(() => sut.Map(source, targetObj)); }
public void ManualMapperMapTest() { var target = new ManualMapper<FromTestClass, ToTestClass>(); FromTestClass source = new FromTestClass() { Id = 5, Description = "test" }; var targetObj = new ToTestClass(); target.AddMappingAction("Id", "Code", (f, t) => t.Code = f.Id); target.AddMappingAction("Description", "Name", (f, t) => t.Name = f.Description); target.AddMappingAction("SampleDate", "SampleDateInStrFormat", (f, t) => t.SampleDateInStrFormat = f.SampleDate.ToShortDateString()); target.Map(source, targetObj); Assert.AreEqual(source.Id, targetObj.Code); Assert.AreEqual(source.Description, targetObj.Name); Assert.AreEqual(source.SampleDate.ToShortDateString(), targetObj.SampleDateInStrFormat); }
public void ManualMapperMapErrorTest() { var target = new ManualMapper <FromTestClass, ToTestClass>(); var source = new FromTestClass() { Id = 5, Description = "test" }; var targetObj = new ToTestClass(); target.AddMappingAction("Id", "Code", (f, t) => { throw new InvalidOperationException(); }); target.Map(source, targetObj); }
public void ManualMapperMapTest() { var target = new ManualMapper <FromTestClass, ToTestClass>(); FromTestClass source = new FromTestClass() { Id = 5, Description = "test" }; var targetObj = new ToTestClass(); target.AddMappingAction("Id", "Code", (f, t) => t.Code = f.Id); target.AddMappingAction("Description", "Name", (f, t) => t.Name = f.Description); target.AddMappingAction("SampleDate", "SampleDateInStrFormat", (f, t) => t.SampleDateInStrFormat = f.SampleDate.ToShortDateString()); target.Map(source, targetObj); Assert.AreEqual(source.Id, targetObj.Code); Assert.AreEqual(source.Description, targetObj.Name); Assert.AreEqual(source.SampleDate.ToShortDateString(), targetObj.SampleDateInStrFormat); }
private void CheckMapping(FromTestClass source, ToTestClass target) { source.Id.ShouldBe(target.Code); source.Description.ShouldBe(target.Name); source.SampleDate.ToShortDateString().ShouldBe(target.SampleDateInStrFormat); }