Ejemplo n.º 1
0
        public void When_I_Compare_Dictionary_Of_Objects_It_Does_A_Deep_Comparison()
        {
            Comparer.Configure<ObjectDictionary>()
                .DeepCompare(x => x.Nested);

            var oldModel = new ObjectDictionary()
            {
                Nested = new Dictionary<int, GrandChildModel>()
                {
                    {1, new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1",
                        Value = 100
                    }},
                    {2, new GrandChildModel()
                    {
                        Id = 200,
                        Name = "Name 2",
                        Value = 200
                    }},
                }
            };

            var newModel = new ObjectDictionary()
            {
                Nested = new Dictionary<int, GrandChildModel>()
                {
                    {1, new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1 - Changed",
                        Value = 150
                    }},
                    {3, new GrandChildModel()
                    {
                        Id = 300,
                        Name = "Name 3",
                        Value = 300
                    }},
                }
            };

            var changes = Comparer.Compare(oldModel, newModel);
            Assert.AreEqual(changes.Count(), 8);
            Assert.IsNotNull(changes.Single(x => x.Name == "Nested.1.Value"));
        }
Ejemplo n.º 2
0
        public void Compare_Dictionary_With_Deep_Compare()
        {
            SutEngine.Configure <ObjectDictionary>();

            var oldModel = new ObjectDictionary()
            {
                Nested = new Dictionary <int, GrandChildModel>()
                {
                    { 1, new GrandChildModel()
                      {
                          Id    = 100,
                          Name  = "Name 1",
                          Value = 100
                      } },
                    { 2, new GrandChildModel()
                      {
                          Id    = 200,
                          Name  = "Name 2",
                          Value = 200
                      } },
                }
            };

            var newModel = new ObjectDictionary()
            {
                Nested = new Dictionary <int, GrandChildModel>()
                {
                    { 1, new GrandChildModel()
                      {
                          Id    = 100,
                          Name  = "Name 1 - Changed",
                          Value = 150
                      } },
                    { 3, new GrandChildModel()
                      {
                          Id    = 300,
                          Name  = "Name 3",
                          Value = 300
                      } },
                }
            };

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

            Assert.AreEqual(changes.Count(), 8);
            Assert.IsNotNull(changes.Single(x => x.Name == "Nested.1.Value"));
        }
Ejemplo n.º 3
0
        public void Compare_Dictionary_With_Deep_Compare()
        {
            SutEngine.Configure<ObjectDictionary>();

            var oldModel = new ObjectDictionary()
            {
                Nested = new Dictionary<int, GrandChildModel>()
                {
                    {1, new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1",
                        Value = 100
                    }},
                    {2, new GrandChildModel()
                    {
                        Id = 200,
                        Name = "Name 2",
                        Value = 200
                    }},
                }
            };

            var newModel = new ObjectDictionary()
            {
                Nested = new Dictionary<int, GrandChildModel>()
                {
                    {1, new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1 - Changed",
                        Value = 150
                    }},
                    {3, new GrandChildModel()
                    {
                        Id = 300,
                        Name = "Name 3",
                        Value = 300
                    }},
                }
            };

            var changes = SutEngine.Compare(oldModel, newModel);
            Assert.AreEqual(changes.Count(), 8);
            Assert.IsNotNull(changes.Single(x => x.Name == "Nested.1.Value"));
        }