Ejemplo n.º 1
0
        public void Compare_List_With_Null()
        {
            SutEngine.Configure <IListModel>()
            .For(x => x.Children, x => x.MatchUsing(y => y.Id));

            var oldModel = new IListModel()
            {
                Id       = 1,
                Children = null,
            };

            var newModel = new IListModel()
            {
                Id       = 1,
                Children = new List <GrandChildModel>()
                {
                    new GrandChildModel()
                    {
                        Id    = 100,
                        Name  = "Name",
                        Value = 25,
                    }
                }
            };

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

            Assert.AreEqual(3, diff.Count());
        }
Ejemplo n.º 2
0
        public void Compare_Dictionary_With_Null()
        {
            SutEngine.Configure <IDictionaryModel>();

            var oldModel = new IDictionaryModel()
            {
                Id       = 1,
                Children = null,
            };

            var newModel = new IDictionaryModel()
            {
                Id       = 1,
                Children = new Dictionary <int, GrandChildModel>()
                {
                    { 100, new GrandChildModel()
                      {
                          Id    = 100,
                          Name  = "Name",
                          Value = 25,
                      } }
                }
            };

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

            Assert.AreEqual(3, diff.Count());
        }
Ejemplo n.º 3
0
        public void Configure_A_Type_Ignoring_Public_Fields()
        {
            SutEngine.Configure <PublicFieldsModel>();

            var oldModel = new PublicFieldsModel()
            {
                Id     = 1,
                Check  = false,
                Name   = "Name",
                Values = new List <int>()
                {
                    1, 2, 3, 4
                },
                Ignored = 5,
            };

            var newModel = new PublicFieldsModel()
            {
                Id     = 1,
                Check  = true,
                Name   = "Name 2",
                Values = new List <int>()
                {
                    2, 3, 4, 5
                },
                Ignored = 6,
            };

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

            Assert.AreEqual(0, diff.Count);
        }
Ejemplo n.º 4
0
        public void Compare_Nested_Null_Object_Does_Not_Throw_NullReferenceException()
        {
            var oldModel = new NestedModel()
            {
                Id    = 10,
                Child = null
            };

            var newModel = new NestedModel()
            {
                Id    = 10,
                Child = new ChildModel()
                {
                    Id         = 100,
                    Name       = "Child",
                    GrandChild = new GrandChildModel()
                    {
                        Id    = 1000,
                        Name  = "GrandChild",
                        Value = 500,
                    }
                }
            };

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

            Assert.AreEqual(changes.Count(), 5);
            Assert.IsNotNull(changes.Single(x => x.Name == "Child.Id"));
            Assert.IsNotNull(changes.Single(x => x.Name == "Child.GrandChild.Value"));
            Assert.IsNotNull(changes.Single(x => x.Name == "Child.GrandChild.Name"));
        }
Ejemplo n.º 5
0
        public void Compare_Object_With_Ignored_Properties()
        {
            SutEngine.Configure <HasIgnores>()
            .Ignore(x => x.IgnoreChild)
            .Ignore(x => x.IgnoreValue);

            var oldModel = new HasIgnores
            {
                Id          = 1,
                IgnoreValue = 5,
                IgnoreChild = new GrandChildModel
                {
                    Id    = 10,
                    Name  = "A",
                    Value = 100
                }
            };
            var newModel = new HasIgnores
            {
                Id          = 2,
                IgnoreValue = 55,
                IgnoreChild = new GrandChildModel
                {
                    Id    = 20,
                    Name  = "B",
                    Value = 200
                }
            };

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

            Assert.AreEqual(changes.Count(), 1);
            Assert.IsNotNull(changes.Single(x => x.Name == "Id" && (long)x.OldValue == 1 && (long)x.NewValue == 2));
        }
Ejemplo n.º 6
0
        public void Compare_List_As_Deep_Compare_With_Default()
        {
            SutEngine.Configure <NestedListWithDefault>()
            .For(x => x.Children, x => x.MatchUsing(y => y.Id, -1));

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

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

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

            Assert.AreEqual(changes.Count(), 9);
            Assert.IsNotNull(changes.Count(x => x.Name == "Children.0.Id" && (long)x.NewValue == 0) == 3);
        }
Ejemplo n.º 7
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"));
        }
Ejemplo n.º 8
0
        public void Configure_IDictionary()
        {
            SutEngine.Configure <IDictionaryModel>();

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

            var newModel = new IDictionaryModel()
            {
                Id       = 1,
                Children = new Dictionary <int, GrandChildModel>
                {
                    { 100,
                      new GrandChildModel()
                      {
                          Id    = 100,
                          Name  = "Name 1",
                          Value = 100
                      } },
                    { 300,
                      new GrandChildModel()
                      {
                          Id    = 300,
                          Name  = "Name 3",
                          Value = 300
                      } }
                },
            };

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

            Assert.AreEqual(6, diff.Count);
        }
Ejemplo n.º 9
0
        public void Configure_Array()
        {
            SutEngine.Configure <ArrayModel>()
            .For(x => x.ArrayChildren, x => x.MatchUsing(y => y.Id));

            var oldModel = new ArrayModel()
            {
                Id            = 1,
                ArrayChildren = new[]
                {
                    new GrandChildModel()
                    {
                        Id    = 100,
                        Name  = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id    = 200,
                        Name  = "Name 2",
                        Value = 200
                    }
                },
            };

            var newModel = new ArrayModel()
            {
                Id            = 1,
                ArrayChildren = new[]
                {
                    new GrandChildModel()
                    {
                        Id    = 100,
                        Name  = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id    = 300,
                        Name  = "Name 3",
                        Value = 300
                    }
                },
            };

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

            Assert.AreEqual(6, diff.Count);
        }
Ejemplo n.º 10
0
        public void Configure_Inherited_IEnumerable()
        {
            SutEngine.Configure <InheritedIEnumerableModel>()
            .For(x => x.Children, x => x.MatchUsing(y => y.Id));

            var oldModel = new InheritedIEnumerableModel()
            {
                Id       = 1,
                Children = new IEnumerableCollectionClass
                {
                    new GrandChildModel()
                    {
                        Id    = 100,
                        Name  = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id    = 200,
                        Name  = "Name 2",
                        Value = 200
                    }
                },
            };

            var newModel = new InheritedIEnumerableModel()
            {
                Id       = 1,
                Children = new IEnumerableCollectionClass
                {
                    new GrandChildModel()
                    {
                        Id    = 100,
                        Name  = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id    = 300,
                        Name  = "Name 3",
                        Value = 300
                    }
                },
            };

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

            Assert.AreEqual(6, diff.Count);
        }
Ejemplo n.º 11
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.º 12
0
        public void Compile_A_Type_With_All_Properties_Ignored()
        {
            SutEngine.Configure <HasIgnores>()
            .Ignore(x => x.Id)
            .Ignore(x => x.IgnoreChild)
            .Ignore(x => x.IgnoreValue);
            var diff = SutEngine.Compare(new HasIgnores()
            {
                Id = 1, IgnoreValue = 100
            },
                                         new HasIgnores()
            {
                Id = 2, IgnoreValue = 200
            });

            Assert.AreEqual(0, diff.Count);
        }
Ejemplo n.º 13
0
        public void Compare_Object_Against_Null()
        {
            var model = new SimpleModel
            {
                Id    = 1,
                Check = true,
                Name  = "Name",
                Value = 1.23m,
                Date  = new DateTime(2015, 01, 01, 12, 50, 30),
                Time  = new TimeSpan(5, 4, 3)
            };

            var nullToModel = SutEngine.Compare(null, model);
            var modelToNull = SutEngine.Compare(model, null);

            Assert.IsTrue(nullToModel.All(x =>
                                          modelToNull.Single(y => x.Name == y.Name && object.Equals(y.OldValue, x.NewValue)) != null));
        }
Ejemplo n.º 14
0
        public void Compare_Null_With_Null()
        {
            var changes = SutEngine.Compare <NestedModel>(null, null);

            Assert.IsFalse(changes.Any());
        }
Ejemplo n.º 15
0
        public void Compile_A_Type_With_No_Public_Properties_To_Compare()
        {
            var diff = SutEngine.Compare(new NoPublicProperty(1), new NoPublicProperty(2));

            Assert.AreEqual(0, diff.Count);
        }