public void ClassPropertyInequality()
        {
            var a1 = new A {
                ClassB = new B {
                    Property1 = "Str1"
                }
            };
            var a2 = new A {
                ClassB = new B {
                    Property1 = "Str2"
                }
            };
            var comparer = new Comparer <A>();

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            CollectionAssert.IsNotEmpty(differences);
            Assert.AreEqual("ClassB.Property1", differences.First().MemberPath);
            Assert.AreEqual("Str1", differences.First().Value1);
            Assert.AreEqual("Str2", differences.First().Value2);
        }
예제 #2
0
        public void NullAndCollectionInequality()
        {
            var a1 = new A();
            var a2 = new A {
                CollectionOfB = new Collection <B> {
                    new B {
                        Property1 = "Str1"
                    }, new B {
                        Property1 = "Str2"
                    }
                }
            };
            var comparer = new Comparer <A>();

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            CollectionAssert.IsNotEmpty(differences);
            Assert.AreEqual(1, differences.Count);
            Assert.AreEqual("CollectionOfB", differences[0].MemberPath);
            Assert.AreEqual(string.Empty, differences[0].Value1);
            Assert.AreEqual(a2.CollectionOfB.ToString(), differences[0].Value2);
        }
예제 #3
0
        public void InterfacePropertyInequality()
        {
            var a1 = new A {
                IntefaceProperty = new TestInterfaceImplementation1 {
                    Property = "Str1"
                }
            };
            var a2 = new A
            {
                IntefaceProperty = new TestInterfaceImplementation2 {
                    Property = "Str2", AnotherProperty = 50
                }
            };
            var comparer = new Comparer <A>();

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            CollectionAssert.IsNotEmpty(differences);
            Assert.AreEqual("IntefaceProperty.Property", differences.First().MemberPath);
            Assert.AreEqual("Str1", differences.First().Value1);
            Assert.AreEqual("Str2", differences.First().Value2);
        }
예제 #4
0
        public void OverrideIntComparisonWhenNotEqual()
        {
            var a1 = new A {
                IntArray = new[] { 1, 2 }
            };
            var a2 = new A {
                IntArray = new[] { 1, 3 }
            };
            var comparer       = new Comparer <A>();
            var stringComparer = Substitute.For <IValueComparer>();

            stringComparer.Compare(Arg.Any <object>(), Arg.Any <object>(), Arg.Any <ComparisonSettings>()).Returns(false);
            stringComparer.ToString(Arg.Any <object>()).Returns(info => (info.Arg <object>() ?? string.Empty).ToString());
            comparer.AddComparerOverride <int>(stringComparer);

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            CollectionAssert.IsNotEmpty(differences);
            Assert.IsTrue(differences.Any(d => d.MemberPath == "IntArray[0]" && d.Value1 == "1" && d.Value2 == "1"));
            Assert.IsTrue(differences.Any(d => d.MemberPath == "IntArray[1]" && d.Value1 == "2" && d.Value2 == "3"));
            stringComparer.Received().Compare(Arg.Any <object>(), Arg.Any <object>(), Arg.Any <ComparisonSettings>());
            stringComparer.Received().ToString(Arg.Any <object>());
        }
예제 #5
0
        public void PropertyInequality()
        {
            var date1 = new DateTime(2017, 1, 1);
            var date2 = new DateTime(2017, 1, 2);
            var a1    = new A {
                IntProperty = 10, DateTimeProperty = date1
            };
            var a2 = new A {
                IntProperty = 8, DateTimeProperty = date2
            };
            var comparer = new Comparer <A>();

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            CollectionAssert.IsNotEmpty(differences);
            Assert.AreEqual("IntProperty", differences[0].MemberPath);
            Assert.AreEqual("10", differences[0].Value1);
            Assert.AreEqual("8", differences[0].Value2);
            Assert.AreEqual("DateTimeProperty", differences[1].MemberPath);
            // ReSharper disable once SpecifyACultureInStringConversionExplicitly
            Assert.AreEqual(date1.ToString(), differences[1].Value1);
            // ReSharper disable once SpecifyACultureInStringConversionExplicitly
            Assert.AreEqual(date2.ToString(), differences[1].Value2);
        }
예제 #6
0
        public void ClassArrayInequalityCount()
        {
            var a1 = new A {
                ArrayOfB = new[] { new B {
                                       Property1 = "Str1"
                                   } }
            };
            var a2 = new A {
                ArrayOfB = new[] { new B {
                                       Property1 = "Str1"
                                   }, new B {
                                       Property1 = "Str2"
                                   } }
            };
            var comparer = new Comparer <A>();

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            CollectionAssert.IsNotEmpty(differences);
            Assert.AreEqual(1, differences.Count);
            Assert.AreEqual("ArrayOfB.Length", differences[0].MemberPath);
            Assert.AreEqual("1", differences[0].Value1);
            Assert.AreEqual("2", differences[0].Value2);
        }
예제 #7
0
        public void OverrideByName()
        {
            var a1 = new A {
                ClassB = new B {
                    Property1 = "123-456-7899"
                }
            };
            var a2 = new A {
                ClassB = new B {
                    Property1 = "(123)-456-7899"
                }
            };
            var comparer      = new Comparer <A>();
            var phoneComparer = Substitute.For <IValueComparer>();

            phoneComparer.Compare("123-456-7899", "(123)-456-7899", Arg.Any <ComparisonSettings>()).Returns(true);

            comparer.AddComparerOverride("Property1", phoneComparer);

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            CollectionAssert.IsEmpty(differences);
            phoneComparer.Received().Compare("123-456-7899", "(123)-456-7899", Arg.Any <ComparisonSettings>());
        }
예제 #8
0
        public void OverrideBClassProperty1ComparerWhenNotEqual()
        {
            var a1 = new A {
                ClassB = new B {
                    Property1 = "123-456-7898"
                }
            };
            var a2 = new A {
                ClassB = new B {
                    Property1 = "(123)-456-7899"
                }
            };
            var valueComparer = CreatePhoneComparer();
            var comparer      = new Comparer <A>();

            comparer.AddComparerOverride(() => new B().Property1, valueComparer);

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            CollectionAssert.IsNotEmpty(differences);
            Assert.AreEqual("ClassB.Property1", differences[0].MemberPath);
            Assert.AreEqual("123-456-7898", differences[0].Value1);
            Assert.AreEqual("(123)-456-7899", differences[0].Value2);
        }
예제 #9
0
        public void NullAndNotNullElementsInequality()
        {
            var a1 = new A {
                NonGenericEnumerable = new ArrayList {
                    null, "Str1"
                }
            };
            var a2 = new A {
                NonGenericEnumerable = new ArrayList {
                    "Str2", null
                }
            };
            var comparer = new Comparer <A>();

            var differences = comparer.CalculateDifferences(a1, a2).ToList();

            Assert.AreEqual(2, differences.Count);
            Assert.AreEqual("NonGenericEnumerable[0]", differences[0].MemberPath);
            Assert.AreEqual(string.Empty, differences[0].Value1);
            Assert.AreEqual("Str2", differences[0].Value2);
            Assert.AreEqual("NonGenericEnumerable[1]", differences[1].MemberPath);
            Assert.AreEqual("Str1", differences[1].Value1);
            Assert.AreEqual(string.Empty, differences[1].Value2);
        }