Example #1
0
            public void It_will_report_diff_when_right_is_null()
            {
                var a = new Person();
                Object b = null;

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsTrue(Diff.ObjectValues(b, a).DiffFound);
            }
Example #2
0
            public void It_will_report_diff_when_left_is_null()
            {
                Object a = null;
                var b = new Person();

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsTrue(Diff.ObjectValues(b, a).DiffFound);
            }
            public void It_will_throw_exception_to_say_its_currently_not_possible()
            {
                var left = new Person { Children = new List<Person>() };
                left.Children.Add(left);
                var right = new Person { Children = new List<Person>() };
                right.Children.Add(right);

                Diff.ObjectValues(left, right);
            }
Example #4
0
            public void It_can_deal_with_nulls_on_props()
            {
                var left = new Person {NameProperty = "Gøran"};
                var right = new Person {NameProperty = null};

                var diff = Diff.ObjectValues(left, right);
                Assert.IsTrue(diff.DiffFound);
                Assert.AreEqual(1, diff.Table.Rows.Count());
            }
Example #5
0
            public void It_will_report_diff_on_properties_with_nulls()
            {
                var personA = new Person { NameProperty = "Gøran" };
                var personB = new Person { NameProperty = null };

                Cross.diff(personA, personB, (left, right) =>
                {
                    var diff = Diff.ObjectValues(left, right);

                    Assert.AreEqual(1, diff.Table.Rows.Count());
                    Assert.AreEqual("NameProperty", diff.Table[0].MemberPath);
                });
            }
Example #6
0
            public void It_can_intercept_based_on_member_path()
            {
                var interceptor = new MemberPathInterceptor<string>(
                    "^NameField$",
                    input => input.ToUpper());
                var personA = new Person { NameField = "Gøran", NameProperty = "Gøran" };
                var personB = new Person { NameField = "Torkild", NameProperty = "Torkild" };

                var diff = Diff.ObjectValues(personA, personB, interceptor);

                Assert.AreEqual("GØRAN", diff.Table[0].LeftValue);
                Assert.AreEqual("TORKILD", diff.Table[0].RightValue);
                Assert.AreEqual("Gøran", diff.Table[1].LeftValue);
                Assert.AreEqual("Torkild", diff.Table[1].RightValue);
            }
Example #7
0
            public void It_can_intercept_on_node_type()
            {
                var interceptor = new TypeInterceptor<int>(input => input + 1);
                var personA = new Person { NameField = "Gøran", WeightField = 70, AgeField = 20, AgeProperty = 20 };
                var personB = new Person { NameField = "Torkild", WeightField = 80, AgeField = 30, AgeProperty = 30 };

                var diff = Diff.ObjectValues(personA, personB, interceptor);

                Assert.AreEqual(4, diff.Table.Rows.Count());
                Assert.AreEqual("Gøran", diff.Table[0].LeftValue);
                Assert.AreEqual("Torkild", diff.Table[0].RightValue);
                Assert.AreEqual(21, diff.Table[1].LeftValue);
                Assert.AreEqual(31, diff.Table[1].RightValue);
                Assert.AreEqual(70, diff.Table[2].LeftValue);
                Assert.AreEqual(80, diff.Table[2].RightValue);
                Assert.AreEqual(21, diff.Table[3].LeftValue);
                Assert.AreEqual(31, diff.Table[3].RightValue);
            }
Example #8
0
            public void It_can_handle_a_relatively_large_object_graph()
            {
                const int generations = 1000;
                Person left = null;
                Person right = null;

                Measure("Building test set:", () =>
                {
                    left = new Person();
                    Generations(generations, left);
                    right = new Person();
                    Generations(generations, right);
                });

                Measure("Diff", () =>
                {
                    var diff = Diff.ObjectValues(left, right, new TypeInterceptor<string>(input =>
                    {
                        return input;
                    }));

                    Assert.AreEqual(0, diff.Table.Rows.Count());
                });
            }
            public void It_will_report_diff_on_public_float_properties()
            {
                var a = new Person { WeightProperty = 80 };
                var b = new Person { WeightProperty = 81 };

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsTrue(Diff.ObjectValues(b, a).DiffFound);
            }
 public void It_will_report_diff_on_public_Enum_fields()
 {
     var personA = new Person {GenderField = Gender.Female};
     var personB = new Person {GenderField = Gender.Male};
     Cross.diff(personA, personB, (left, right) =>
     {
         var report = Diff.ObjectValues(left, right);
         Assert.IsTrue(report.DiffFound);
         Assert.AreEqual(1, report.Table.Rows.Count());
         Assert.AreEqual("GenderField", report.Table[0].MemberPath);
     });
 }
            public void It_will_report_diff_on_public_float_field()
            {
                var a = new Person { WeightField = 70 };
                var b = new Person { WeightField = 81 };

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsTrue(Diff.ObjectValues(b, a).DiffFound);
            }
Example #12
0
            public void It_will_report_diff_on_public_int_fields()
            {
                var a = new Person { AgeField = 20 };
                var b = new Person { AgeField = 29 };

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
            }
            public void It_will_report_diff_on_public_decimal_properties()
            {
                var personA = new Person {HeightProperty = 1.8m};
                var personB = new Person {HeightProperty = 2.10m};

                Cross.diff(personA, personB, (left, right) =>
                {
                    var diff = Diff.ObjectValues(left, right);
                    Assert.AreEqual(1, diff.Table.Rows.Count());
                    Assert.AreEqual("HeightProperty", diff.Table[0].MemberPath);
                });
            }
            public void It_will_report_diff_on_public_String_properties()
            {
                var a = new Person { NameProperty = "Gøran" };
                var b = new Person { NameProperty = "Gøran Hansen" };

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsTrue(Diff.ObjectValues(b, a).DiffFound);
            }
            public void It_will_report_diff_on_object_properties()
            {
                var personA = new Person
                {
                    Children = new List<Person>
                    {
                        new Person { NameProperty = "Steve" }
                    }
                };

                var personB = new Person
                {
                    Children = new List<Person>
                    {
                        new Person { NameProperty = "Bill" }
                    }
                };

                Cross.diff(personA, personB, (left, right) =>
                {
                    var diffResult = Diff.ObjectValues(left, right);
                    Assert.AreEqual(1, diffResult.Table.Rows.Count());
                    Assert.AreEqual("Children[0].NameProperty", diffResult.Table[0].MemberPath);
                });
            }
Example #16
0
            public void It_will_report_diff_on_public_Enum_properties()
            {
                var left = new Person {GenderProperty = Gender.Femal};
                var right = new Person {GenderProperty = Gender.Male};

                var report = Diff.ObjectValues(left, right);
                Assert.IsTrue(report.DiffFound);
                Assert.AreEqual(1, report.Table.Rows.Count());
                Assert.AreEqual("GenderProperty", report.Table[0].MemberPath);
            }
Example #17
0
            public void It_will_report_diff_on_public_decimal_properties()
            {
                var a = new Person {HeightProperty = 1.8m};
                var b = new Person {HeightProperty = 2.10m};

                var diff = Diff.ObjectValues(a, b);
                Assert.AreEqual(1, diff.Table.Rows.Count());
                Assert.AreEqual("HeightProperty", diff.Table[0].MemberPath);
            }
Example #18
0
 private static void Generations(int depth, Person person)
 {
     if (depth == 0) return;
     var newChild = new Person();
     person.Children = new List<Person>();
     for (int i = 0; i < 100; i++)
     {
         person.Children.Add(new Person());
     }
     Generations(depth - 1, newChild);
 }
Example #19
0
            public void It_will_report_diff_on_public_float_field()
            {
                var left = new Person { WeightField = 70 };
                var right = new Person { WeightField = 81 };

                Assert.IsTrue(Diff.ObjectValues(left, right).DiffFound);
            }
Example #20
0
            public void It_will_not_intercept_invalid_type_when_intercept_by_member_path()
            {
                var interceptor = new MemberPathInterceptor<int>("^NameField$",
                    input => input + 10);

                var left = new Person { NameField = "Gøran", NameProperty = "Gøran" };
                var right = new Person { NameField = "Torkild", NameProperty = "Torkild" };

                var diff = Diff.ObjectValues(left, right, interceptor);

                Assert.AreEqual(2, diff.Table.Rows.Count());
            }
Example #21
0
            public void It_should_be_possible_to_intercept_lists()
            {
                var left = new Person();
                left.Children = new List<Person>();
                var right = new Person();
                right.Children = new List<Person>();

                var numberOfInterceptions = 0;
                var listInterceptor = new TypeInterceptor<IEnumerable<Person>>(input =>
                {
                    numberOfInterceptions++;
                    return input;
                });

                Diff.ObjectValues(left, right, listInterceptor);
                Assert.AreEqual(2, numberOfInterceptions);
            }
Example #22
0
            public void It_will_report_diff_on_public_int_properties()
            {
                var left = new Person {AgeProperty = 20};
                var right = new Person {AgeProperty = 29};

                Assert.IsTrue(Diff.ObjectValues(left, right).DiffFound);
            }
            public void It_will_report_diff_on_public_int_properties()
            {
                var a = new Person { AgeProperty = 20 };
                var b = new Person { AgeProperty = 29 };

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsTrue(Diff.ObjectValues(b, a).DiffFound);
            }
            public void It_will_not_report_diff_on_object_references()
            {
                var a = new Person { Children = new List<Person>() };
                var b = new Person { Children = new List<Person>() };

                Assert.IsFalse(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsFalse(Diff.ObjectValues(b, a).DiffFound);
            }
            public void It_will_report_diff_on_public_String_fields()
            {
                var a = new Person { NameField = "Steve" };
                var b = new Person { NameField = "Bill" };

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsTrue(Diff.ObjectValues(b, a).DiffFound);
            }
            public void It_will_report_diff_on_object_when_one_of_the_sides_are_null()
            {
                var a = new Person { Children = new List<Person>() };
                var b = new Person();

                Assert.IsTrue(Diff.ObjectValues(a, b).DiffFound);
                Assert.IsTrue(Diff.ObjectValues(b, a).DiffFound);
            }
            public void It_will_report_multiple_diffs()
            {
                var personA = new Person
                {
                    NameProperty = "Gøran", AgeProperty = 29, NameField = "Hansen", AgeField = 31
                };
                var personB = new Person
                {
                    NameProperty = "Gøran Hansen", AgeProperty = 30, NameField = "Mr Hansen", AgeField = 32
                };
                Cross.diff(personA, personB, (left, right) =>
                {
                    var report = Diff.ObjectValues(left, right);

                    Assert.IsTrue(report.DiffFound);
                    Assert.AreEqual(4, report.Table.Rows.Count());
                    Assert.AreEqual("NameField", report.Table[0].MemberPath);
                    Assert.AreEqual("AgeField", report.Table[1].MemberPath);
                    Assert.AreEqual("NameProperty", report.Table[2].MemberPath);
                    Assert.AreEqual("AgeProperty", report.Table[3].MemberPath);
                });
            }
 public void It_will_report_diff_on_public_DateTime_properties()
 {
     var personA = new Person {BornProperty = new DateTime(1981, 10, 10)};
     var personB = new Person {BornProperty = new DateTime(1981, 10, 11)};
     Cross.diff(personA, personB, (left, right) =>
     {
         var diff = Diff.ObjectValues(left, right);
         Assert.AreEqual(1, diff.Table.Rows.Count());
     });
 }
Example #29
0
            public void It_will_report_diff_on_public_DateTime_fields()
            {
                var left = new Person { BornField = new DateTime(1981, 10, 10) };
                var right = new Person { BornField = new DateTime(1982, 10, 10) };

                var diff = Diff.ObjectValues(left, right);
                Assert.AreEqual(1, diff.Table.Rows.Count());
            }
Example #30
0
            public void It_will_report_diff_on_public_float_properties()
            {
                var left = new Person {WeightProperty = 80};
                var right = new Person {WeightProperty = 81};

                Assert.IsTrue(Diff.ObjectValues(left, right).DiffFound);
            }