protected IAccessable MapProperties<TSourceProperty, TTargetProperty>( Expression<Func<TSource, TSourceProperty>> source, Expression<Func<TSourceProperty, TTargetProperty>> converter, Expression<Func<TTarget, TTargetProperty>> target, Expression<Func<TTargetProperty, TSourceProperty>> inverseConverter ) { Contract.Assert(converter != null); Contract.Assert(inverseConverter != null); var association = new PropertyToPropertyWithConversionAssociation<TSource, TSourceProperty, TTarget, TTargetProperty>(source, converter, target, inverseConverter); _associations.Add(association); return association; }
public void TestStringToIntDefaultMapping() { Foo foo; Bar bar; var sut = new PropertyToPropertyWithConversionAssociation <Foo, int, Bar, string>(_ => _.Id, _ => _.ToString(), _ => _.Name, _ => int.Parse(_)); foo = new Foo { Id = 123 }; bar = new Bar { Name = string.Empty }; CreateWriter(sut)(bar, foo); foo.Id.Should().Be(default(int)); }
public void TestIntToStringMapping() { Foo foo; Bar bar; var sut = new PropertyToPropertyWithConversionAssociation <Foo, int, Bar, string>(_ => _.Id, _ => _.ToString(), _ => _.Name, _ => int.Parse(_)); foo = new Foo { Id = 123 }; bar = CreateReader(sut)(foo); bar.Should().NotBeNull(); bar.Name.Should().Be(foo.Id.ToString()); foo = new Foo { Id = 123 }; bar = new Bar { Name = "555" }; CreateWriter(sut)(bar, foo); foo.Id.Should().Be(int.Parse(bar.Name)); }