Example #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());
        }
Example #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());
        }
Example #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);
        }
        public void Configure_A_Type_Twice_Should_Throw()
        {
            SutEngine.Configure <SimpleModel>()
            .Ignore(x => x.Value);

            SutEngine.Configure <SimpleModel>();
        }
Example #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));
        }
        public void Configure_A_Property_Twice_Should_Throw()
        {
            SutEngine.Configure <SimpleModel>()
            .For(x => x.Value, x => x.Ignore())
            .For(x => x.Value, x => x.Ignore());

            SutEngine.Configure <NestedList>()
            .For(x => x.Children, x => x.MatchUsing(y => y.Id));
        }
Example #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"));
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
0
        public void Compile_Async()
        {
            Assert.IsFalse(SutEngine.IsTypeConfigured(typeof(SimpleModel)));

            SutEngine.Configure <SimpleModel>()
            .Compile.Async();

            Assert.IsTrue(SutEngine.IsTypeConfigured(typeof(SimpleModel)));
            Assert.IsFalse(SutEngine.IsTypeCompiled(typeof(SimpleModel)));

            var comparer = SutEngine.Get <SimpleModel>();

            Assert.IsTrue(SutEngine.IsTypeConfigured(typeof(SimpleModel)));
            Assert.IsTrue(SutEngine.IsTypeCompiled(typeof(SimpleModel)));
        }
Example #13
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"));
        }
Example #14
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);
        }
Example #15
0
 public void Compile_A_Type_With_IEnumerable_Parent_Class()
 {
     SutEngine.Configure <InheritedIEnumerableModel>()
     .Compile.Now();
 }
Example #16
0
 public void Compile_A_Type_With_A_Struct_Member()
 {
     SutEngine.Configure <StructModel>()
     .Compile.Now();
 }
Example #17
0
 public void Configure_Enumerable_Twice_Should_Throw()
 {
     SutEngine.Configure <ArrayModel>()
     .For(x => x.ArrayChildren, x => x.MatchUsing(y => y.Id))
     .For(x => x.ArrayChildren, x => x.MatchUsing(y => y.Id));
 }
Example #18
0
 public void Configure_Not_A_Member_Should_Throw()
 {
     SutEngine.Configure <SimpleModel>()
     .For(x => "a string", x => x.Ignore());
 }
Example #19
0
 public void Configure_A_Member_That_Is_Not_A_Field_Or_Property_Should_Throw()
 {
     SutEngine.Configure <SimpleModel>()
     .For(x => x.GetHashCode(), x => x.Ignore());
 }
Example #20
0
 public void Compile_A_Type_With_Circular_References()
 {
     SutEngine.Configure <ParentCirularRef>()
     .Compile.Now();
 }
Example #21
0
 public void Compile_A_Configured_Type_With_IEnumerable_Parent_Class()
 {
     SutEngine.Configure <InheritedIEnumerableModel>()
     .For(x => x.Children, x => x.MatchUsing(y => y.Id))
     .Compile.Now();
 }
Example #22
0
 public void Compile_A_Child_Type()
 {
     SutEngine.Configure <Child>()
     .Compile.Now();
 }