Example #1
0
        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();
        }
Example #2
0
 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;
 }
Example #3
0
        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();
        }
Example #4
0
        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());
        }
Example #5
0
        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();
        }
Example #6
0
        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));
        }