public void Parent_Should_Be_Same_As_Root_Object()
        {
            var mapper = CreateMapper(
                cfg =>
            {
                cfg.AddCollectionMappers();
                cfg.CreateMap <ThingWithCollection, ThingWithCollection>()
                .PreserveReferences();
                cfg.CreateMap <ThingCollectionItem, ThingCollectionItem>()
                .EqualityComparison((src, dst) => src.ID == dst.ID)
                .PreserveReferences();
            });

            var root = new ThingWithCollection()
            {
                Children = new List <ThingCollectionItem>()
            };

            root.Children.Add(new ThingCollectionItem()
            {
                ID = 1, Parent = root
            });

            var target = new ThingWithCollection()
            {
                Children = new List <ThingCollectionItem>()
            };

            mapper.Map(root, target).Should().Be(target);

            target.Children.Count.Should().Be(1);
            target.Children.Single().Parent.Should().Be(target);
        }
Ejemplo n.º 2
0
            public void WhenBothItemsHaveCollections_ButBothAreNull_ShouldBehaveAccordingly()
            {
                //--------------- Arrange -------------------
                var item1 = new ThingWithCollection();
                var item2 = new ThingWithCollection();
                var sut   = Create(item1, item2);

                //--------------- Assume ----------------
                Expect(item1.Subs).To.Be.Null();
                Expect(item2.Subs).To.Be.Null();

                //--------------- Act ----------------------
                Expect(sut.AreDeepEqual()).To.Be.True();

                //--------------- Assert -----------------------
            }
Ejemplo n.º 3
0
            public void WhenBothItemsHaveCollections_ButOneIsNull_ShouldNotBarfReversed()
            {
                //--------------- Arrange -------------------
                var item1 = new ThingWithCollection();
                var item2 = new ThingWithCollection()
                {
                    Subs = new[] { 1, 2, 3 }
                };
                var sut = Create(item1, item2);

                //--------------- Assume ----------------
                Expect(item1.Subs).To.Be.Null();

                //--------------- Act ----------------------
                Expect(sut.AreDeepEqual()).To.Be.False();

                //--------------- Assert -----------------------
            }
Ejemplo n.º 4
0
            public void WhenBothItemsHaveCollections_ShouldCompareThem_Positive()
            {
                //--------------- Arrange -------------------
                var item1 = new
                {
                    Subs = new[] { 1, 2, }
                };
                var item2 = new ThingWithCollection()
                {
                    Subs = new[] { 1, 2 }
                };
                var sut = Create(item1, item2);

                //--------------- Assume ----------------

                //--------------- Act ----------------------
                Expect(sut.AreDeepEqual()).To.Be.True();

                //--------------- Assert -----------------------
            }