public async Task Automapping_should_work_with_enumerable() { //Arrange MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true)); var fromObject = new FromObject() { Numbers = new [] { 1, 2, 3 } }; //Act var toObject = await fromObject.ConvertAsync <ToObject>(); //Assert toObject.Numbers.Should().Equal(new [] { 1, 2, 3 }); }
public async Task Mapping_Should_Work_Reversed() { //Arrange MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true)); var fromObject = new FromObject() { Name = "Testsson", Age = 22 }; //Act var toObject = await fromObject.ConvertAsync <ToObject>(); //Assert fromObject.Name.Should().Be(toObject.Name); }
public void Mapping_should_throw_if_fields_are_missing() { //Arrange MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, FailingToObject>(MappingPropertySource.Source)); var fromObject = new FromObject() { Name = "Testsson", Age = 22 }; //Act Func <Task> tryToConvert = async() => await fromObject.ConvertAsync <FailingToObject>(); //Assert tryToConvert.Should().Throw <KeyNotFoundException>(); }
public async Task Automapping_should_work_with_enums() { //Arrange MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true)); var fromObject = new FromObject() { Name = "Testsson", EnumValue = "Yes", Age = 22 }; //Act var toObject = await fromObject.ConvertAsync <ToObject>(); //Assert toObject.TestValue.Should().Be(TestEnum.Yes); }
public async Task Mapping_Should_Work_With_Wrapped_Elements() { //Arrange MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true)); MappingHandler.AddMapping <string, WrappedValue>((source) => new WrappedValue() { Value = source }); var fromObject = new FromObject() { Name = "Testsson", WrappedValue = "inner value", Age = 22 }; //Act var toObject = await fromObject.ConvertAsync <ToObject>(); //Assert fromObject.WrappedValue.Should().Be(toObject.WrappedValue.Value); }
public async Task Automapping_should_work_with_dictionaries() { //Arrange MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true)); var fromObject = new FromObject() { Table = new Dictionary <int, string> { { 1, "1" }, { 2, "2" }, { 3, "3" } } }; //Act var toObject = await fromObject.ConvertAsync <ToObject>(); //Assert toObject.Table.Should().Equal(new Dictionary <int, string> { { 1, "1" }, { 2, "2" }, { 3, "3" } }); }