public void TestMappingAssignsDefaultValue() { var sut = new ComponentCollectionAssociation <Foo, Baz, Bar, Qux>(_ => _.Bazes, _ => _.Quxes); var foo = new Foo(); var bar = CreateReader(sut)(foo); bar.Quxes.Should().BeNull(); }
protected IExpandable MapComponentCollections<TSourceItem, TTargetItem>( Expression<Func<TSource, IEnumerable<TSourceItem>>> source, Expression<Func<TTarget, IEnumerable<TTargetItem>>> target ) where TSourceItem : class where TTargetItem : class, new() { var association = new ComponentCollectionAssociation<TSource, TSourceItem, TTarget, TTargetItem>(source, target); _associations.Add(association); return association; }
public void TestEmptyMapsToEmpty() { var sut = new ComponentCollectionAssociation <Foo, Baz, Bar, Qux>(_ => _.Bazes, _ => _.Quxes); var foo = new Foo { Bazes = Enumerable.Empty <Baz>() }; var bar = CreateReader(sut)(foo); bar.Quxes.Should().NotBeNull(); bar.Quxes.Should().BeEmpty(); }
public void TestMappingCreatesTargetComponent() { var sut = new ComponentCollectionAssociation <Foo, Baz, Bar, Qux>(_ => _.Bazes, _ => _.Quxes); var foo = new Foo { Bazes = new[] { new Baz(), new Baz() } }; var bar = CreateReader(sut)(foo); bar.Quxes.Should().NotBeNull(); bar.Quxes.Count().Should().Be(foo.Bazes.Count()); }
public void TestReverseMappingDoNothing() { var sut = new ComponentCollectionAssociation <Foo, Baz, Bar, Qux>(_ => _.Bazes, _ => _.Quxes); var foo = new Foo(); var bar = new Bar { Quxes = new[] { new Qux(), new Qux() } }; CreateWriter(sut)(bar, foo); foo.Bazes.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)); }