protected IAccessable MapProperties<TProperty>( Expression<Func<TSource, TProperty>> source, Expression<Func<TTarget, TProperty>> target ) { var association = new PropertyToPropertyAssociation<TSource, TTarget, TProperty>(source, target); _associations.Add(association); return association; }
public void TestDirectMappingAppliesMapper() { var foo = new Foo { Component = new Baz { Id = 15 } }; var sut = new ComponentToComponentAssociation <Foo, Baz, Bar, Qux>(_ => _.Component, _ => _.Component); var component = new PropertyToPropertyAssociation <Baz, Qux, int>(_ => _.Id, _ => _.Id); var bar = CreateReader(sut, component)(foo); bar.Should().NotBeNull(); bar.Component.Should().NotBeNull(); bar.Component.Id.Should().Be(foo.Component.Id); }
public void TestMappingAssignsDefaultValue() { var sut = new ComponentToComponentAssociation <Foo, Baz, Bar, Qux>(_ => _.Component, _ => _.Component); var component = new PropertyToPropertyAssociation <Baz, Qux, int>(_ => _.Id, _ => _.Id); var foo = new Foo(); var bar = CreateReader(sut, component)(foo); bar.Should().NotBeNull(); bar.Component.Should().BeNull(); foo = new Foo { Component = new Baz() }; bar = new Bar(); CreateWriter(sut, component)(bar, foo); foo.Component.Should().BeNull(); }
public void TestMappingAppliesMapper() { var sut = new ComponentCollectionAssociation <Foo, Baz, Bar, Qux>(_ => _.Bazes, _ => _.Quxes); var component = new PropertyToPropertyAssociation <Baz, Qux, int>(_ => _.Id, _ => _.Id); var foo = new Foo { Bazes = new[] { new Baz { Id = 1 }, new Baz { Id = 2 } } }; var bar = CreateReader(sut, component)(foo); bar.Quxes.Should().NotBeNull(); bar.Quxes.Should().NotBeEmpty(); bar.Quxes.Select(_ => _.Id).Should().BeEquivalentTo(foo.Bazes.Select(_ => _.Id)); }
public void TestInverseMappingAppliesMapper() { var foo = new Foo { Component = new Baz { Id = 15 } }; var bar = new Bar { Component = new Qux { Id = 16 } }; var sut = new ComponentToComponentAssociation <Foo, Baz, Bar, Qux>(_ => _.Component, _ => _.Component); var component = new PropertyToPropertyAssociation <Baz, Qux, int>(_ => _.Id, _ => _.Id); CreateWriter(sut, component)(bar, foo); foo.Component.Id.Should().Be(bar.Component.Id); }
public void TestStringMapping() { Foo foo; Bar bar; var sut = new PropertyToPropertyAssociation <Foo, Bar, string>(_ => _.Name, _ => _.Name); foo = new Foo { Name = "aaa" }; bar = CreateReader(sut)(foo); bar.Should().NotBeNull(); bar.Id.Should().Be(foo.Id); foo = new Foo { Name = "aaa" }; bar = new Bar { Name = "bbb" }; CreateWriter(sut)(bar, foo); foo.Id.Should().Be(bar.Id); }
public void TestIntMapping() { Foo foo; Bar bar; var sut = new PropertyToPropertyAssociation <Foo, Bar, int>(_ => _.Id, _ => _.Id); foo = new Foo { Id = 5 }; bar = CreateReader(sut)(foo); bar.Should().NotBeNull(); bar.Id.Should().Be(foo.Id); foo = new Foo { Id = 5 }; bar = new Bar { Id = 6 }; CreateWriter(sut)(bar, foo); foo.Id.Should().Be(bar.Id); }