Example #1
0
        public void Compare_List_As_Deep_Compare()
        {
            SutEngine.Configure <NestedList>()
            .For(x => x.Children, x => x.MatchUsing(y => y.Id));

            var oldModel = new NestedList()
            {
                Children = new List <GrandChildModel>()
                {
                    new GrandChildModel()
                    {
                        Id    = 100,
                        Name  = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id    = 200,
                        Name  = "Name 2",
                        Value = 200
                    },
                }
            };

            var newModel = new NestedList()
            {
                Children = new List <GrandChildModel>()
                {
                    new GrandChildModel()
                    {
                        Id    = 100,
                        Name  = "Name 1 - Changed",
                        Value = 150
                    },
                    new GrandChildModel()
                    {
                        Id    = 300,
                        Name  = "Name 3",
                        Value = 300
                    },
                    new GrandChildModel()
                    {
                        Id    = 400,
                        Name  = "Name 4",
                        Value = 200
                    }
                }
            };

            var changes = SutEngine.Compare(oldModel, newModel);

            Assert.AreEqual(changes.Count(), 11);
            Assert.IsNotNull(changes.Single(x => x.Name == "Children.100.Name"));
        }
Example #2
0
        public void When_I_Compare_Lists_Of_Objects_I_Can_Specify_An_Id()
        {
            Comparer.Configure<NestedList>()
                .Enumerable(x => x.Children, x => x.DeepCompare(y => y.Id));

            var oldModel = new NestedList()
            {
                Children = new List<GrandChildModel>()
                {
                    new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id = 200,
                        Name = "Name 2",
                        Value = 200
                    },
                }
            };

            var newModel = new NestedList()
            {
                Children = new List<GrandChildModel>()
                {
                    new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1 - Changed",
                        Value = 150
                    },
                    new GrandChildModel()
                    {
                        Id = 300,
                        Name = "Name 3",
                        Value = 300
                    },
                    new GrandChildModel()
                    {
                        Id = 400,
                        Name = "Name 4",
                        Value = 200
                    }
                }
            };

            var changes = Comparer.Compare(oldModel, newModel);
            Assert.AreEqual(changes.Count(), 11);
            Assert.IsNotNull(changes.Single(x => x.Name == "Children.100.Name"));
        }
        public void Compare_List_As_Deep_Compare()
        {
            SutEngine.Configure<NestedList>()
                .For(x => x.Children, x => x.MatchUsing(y => y.Id));

            var oldModel = new NestedList()
            {
                Children = new List<GrandChildModel>()
                {
                    new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id = 200,
                        Name = "Name 2",
                        Value = 200
                    },
                }
            };

            var newModel = new NestedList()
            {
                Children = new List<GrandChildModel>()
                {
                    new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1 - Changed",
                        Value = 150
                    },
                    new GrandChildModel()
                    {
                        Id = 300,
                        Name = "Name 3",
                        Value = 300
                    },
                    new GrandChildModel()
                    {
                        Id = 400,
                        Name = "Name 4",
                        Value = 200
                    }
                }
            };

            var changes = SutEngine.Compare(oldModel, newModel);
            Assert.AreEqual(changes.Count(), 11);
            Assert.IsNotNull(changes.Single(x => x.Name == "Children.100.Name"));
        }