Inheritance: IName
Example #1
0
 public void SecondObjectNull()
 {
     Person p1 = new Person();
     Person p2 = null;
     Assert.IsFalse(_compare.Compare(p1, p2).AreEqual);
     Assert.IsFalse(_compare.Compare(p2, p1).AreEqual);
 }
 public void Initialize()
 {
     _objectComparer = new LogicEqualityComparer();
     _typedComparer = new LogicEqualityComparer<KeyValuePair<string, List<Person>>>();
     _abe = new Person() { Name = "Abe" };
     _joe1 = new Person() { Name = "Joe" };
     _joe2 = new Person() { Name = "Joe" };
     _sue = new Person() { Name = "Sue" };
 }
        public void TestIndexerPositive()
        {
            var jane = new Person { Name = "Jane" };
            var mary = new Person { Name = "Mary" };
            var jack = new Person { Name = "Jack" };

            var nameList1 = new List<Person>() { jane, jack, mary };
            var nameList2 = new List<Person>() { jane, jack, mary };

            var class1 = new ListClass<Person>(nameList1);
            var class2 = new ListClass<Person>(nameList2);

            Assert.IsTrue(_compare.Compare(class1, class2).AreEqual);
        }
        public void Compare_IndexerCompareAndPropertyComparePositive()
        {
            var jane = new Person {Name = "Jane"};
            var mary = new Person {Name = "Mary"};
            var jack = new Person {Name = "Jack"};

            var nameList1 = new List<Person>() {jane, jack, mary};
            var nameList2 = new List<Person>() {jane, jack, mary};

            var class1 = new ListClass<Person>(nameList1);
            var class2 = new ListClass<Person>(nameList2);

            var compare = new CompareLogic();
            Assert.IsTrue(compare.Compare(class1, class2).AreEqual);
        }
        public void ParentIsAClassTest()
        {
            Person person1 = new Person();
            person1.Name = "Batman";

            Person person2 = new Person();
            person2.Name = "Robin";

            ComparisonResult result = _compare.Compare(person1, person2);

            Assert.IsTrue(result.Differences[0].ParentObject1 != null);
            Assert.IsTrue(result.Differences[0].ParentObject2 != null);

            Assert.IsTrue(result.Differences[0].ParentObject1.Target.GetType() == typeof(Person));
            Assert.IsTrue(result.Differences[0].ParentObject2.Target.GetType() == typeof(Person));

            Assert.AreEqual("Batman", ((Person)result.Differences[0].ParentObject1.Target).Name);
            Assert.AreEqual("Robin", ((Person)result.Differences[0].ParentObject2.Target).Name);
        }
        public void DocumentationTest()
        {
            //This is the comparison class
            CompareLogic compareLogic = new CompareLogic();

            //Create a couple objects to compare
            Person person1 = new Person();
            person1.DateCreated = DateTime.Now;
            person1.Name = "Greg";

            Person person2 = new Person();
            person2.Name = "John";
            person2.DateCreated = person1.DateCreated;

            //These will be different, write out the differences
            ComparisonResult result = compareLogic.Compare(person1, person2);
            if (!result.AreEqual)
                Console.WriteLine(result.DifferencesString);
        }
        public void WeakReferenceNegativeTest()
        {
            var jane = new Person { Name = "Jane" };
            var mary = new Person { Name = "Mary" };
            var jack = new Person { Name = "Jack" };

            var nameList1 = new List<Person>() { jane, jack, mary };
            var nameList2 = new List<Person>() { jane, mary, jack };

            var result = _compare.Compare(nameList1, nameList2);
            _compare.Config.MaxDifferences = int.MaxValue;

            Console.WriteLine(result.DifferencesString);

            Assert.IsTrue(result.Differences[0].Object1.IsAlive);
            Assert.IsTrue(result.Differences[0].Object2.IsAlive);

            Assert.AreNotEqual(result.Differences[0].Object1.Target, result.Differences[0].Object2.Target);
        }
        public void TestDictionaryNegative()
        {
            Person p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Owen";
            Person p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = DateTime.Now.AddDays(-1);

            Dictionary<string, Person> dict1 = new Dictionary<string, Person>();
            dict1.Add("1001", p1);
            dict1.Add("1002", p2);

            Dictionary<string, Person> dict2 = Common.CloneWithSerialization(dict1);

            dict2["1002"].DateCreated = DateTime.Now.AddDays(1);

            Assert.IsFalse(_compare.Compare(dict1, dict2).AreEqual);

        }
        public void CallbackCalledTest()
        {
            Person p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Greg";
            Person p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = p1.DateCreated.AddSeconds(1);

            var called = false;

            _compare.Config.DifferenceCallback = d =>
            {
                called = true;
            };

            _compare.Compare(p1, p2);

            Assert.IsTrue(called);
        }
        public void TestDictionary()
        {
            Person p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Owen";
            Person p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = DateTime.Now.AddDays(-1);

            Dictionary<string, Person> dict1 = new Dictionary<string, Person>();
            dict1.Add("1001", p1);
            dict1.Add("1002", p2);

            Dictionary<string, Person> dict2 = Common.CloneWithSerialization(dict1);

            ComparisonResult result = _compare.Compare(dict1, dict2);

            if (!result.AreEqual)
                throw new Exception(result.DifferencesString);

        }
        public void CompareGiantLists()
        {
            int max = 10000;
            List<Person> persons1 = new List<Person>();

            for (int i = 0; i < max; i++)
            {
                Person person = new Person();
                person.Name = "Greg";
                persons1.Add(person);
            }

            List<Person> persons2 = Common.CloneWithSerialization(persons1);
           
            Stopwatch watch = new Stopwatch();
            watch.Start();
            ComparisonResult result = _compare.Compare(persons1, persons2);
            watch.Stop();
            
            Console.WriteLine(watch.ElapsedMilliseconds);
        }
        public void TestIndexerWithIgnoreCollectionOrderNegative()
        {
            var jane = new Person { Name = "Jane" };
            var john = new Person { Name = "Mary" };
            var mary = new Person { Name = "Mary" };
            var jack = new Person { Name = "Jack" };
            var jo = new Person { Name = "Jo" };
            var sarah = new Person { Name = "Sarah" };

            var nameList1 = new List<Person>() { jane, jack, mary, jo };
            var nameList2 = new List<Person>() { jane, john, jack, sarah };

            var class1 = new ListClass<Person>(nameList1);
            var class2 = new ListClass<Person>(nameList2);

            _compare.Config.IgnoreCollectionOrder = true;

            Assert.IsFalse(_compare.Compare(class1, class2).AreEqual);
            Assert.IsFalse(_compare.Compare(class2, class1).AreEqual);
        }
Example #13
0
        public void CompareInterfaceMembers()
        {
            ComparisonConfig config = new ComparisonConfig();
            config.InterfaceMembers.Add(typeof(IName));

            _compare = new CompareLogic(config);

            Person person1 = new Person();
            person1.Name = "Greg";
            person1.DateCreated = DateTime.Now;

            Person person2 = new Person();
            person2.Name = "Greg";
            person2.DateCreated = DateTime.Now.AddDays(-1);

            var result = _compare.Compare(person1, person2);
            Assert.IsTrue(result.AreEqual, result.DifferencesString);

        }
        public void ClassTypeIgnoreNegative()
        {
            _compare.Config.ClassTypesToIgnore.Add(typeof(Entity));

            Person p1 = new Person();
            p1.Name = "Greg";
            p1.DateCreated = DateTime.Now;

            Person p2 = new Person();
            p2.Name = "Leyla";
            p2.DateCreated = DateTime.Now.AddDays(-1);

            var result = _compare.Compare(p1, p2);
            Assert.IsFalse(result.AreEqual, result.DifferencesString);
        }
        public void PropertyAndFieldTest()
        {
            Person p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Greg";
            Person p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = p1.DateCreated;

            ComparisonResult result = _compare.Compare(p1, p2);

            if (!result.AreEqual)
                throw new Exception(result.DifferencesString);
        }
Example #16
0
        public void ArrayTest()
        {
            Person p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Greg";

            Person p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = p1.DateCreated;

            Person[] array1 = new Person[2];
            Person[] array2 = new Person[2];

            array1[0] = p1;
            array1[1] = p2;

            array2[0] = Common.CloneWithSerialization(p1);
            array2[1] = Common.CloneWithSerialization(p2);

            ComparisonResult result = _compare.Compare(array1, array2);

            if (!result.AreEqual)
                throw new Exception(result.DifferencesString);

        }
        public void TestIndexerLengthNegative()
        {
            var jane = new Person { Name = "Jane" };
            var john = new Person { Name = "John" };
            var mary = new Person { Name = "Mary" };
            var jack = new Person { Name = "Jack" };

            var nameList1 = new List<Person>() { jane, john, jack, mary };
            var nameList2 = new List<Person>() { jane, john, jack };

            var class1 = new ListClass<Person>(nameList1);
            var class2 = new ListClass<Person>(nameList2);

            var prior = _compare.Config.MaxDifferences;
            _compare.Config.MaxDifferences = int.MaxValue;

            ComparisonResult result = _compare.Compare(class1, class2);
            Assert.AreEqual(result.Differences.Count, 3);

            result = _compare.Compare(class2, class1);
            Assert.AreEqual(result.Differences.Count, 3);

            _compare.Config.MaxDifferences = prior;
        }
        public void TestDictionaryWithIgnoreCollectionOrder()
        {
            var p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Owen";

            var p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = DateTime.Now.AddDays(-1);

            var p3 = new Person();
            p3.Name = "Wink";
            p3.DateCreated = DateTime.Now.AddDays(-2);

            var dict1 = new Dictionary<string, Person>();
            dict1.Add("1001", p1);
            dict1.Add("1002", p2);

            var dict2 = new Dictionary<string, Person>();
            dict2.Add("1002", p2);
            dict2.Add("1001", p1);

            _compare.Config.IgnoreCollectionOrder = true;

            ComparisonResult result = _compare.Compare(dict1, dict2);

            if (!result.AreEqual)
                throw new Exception(result.DifferencesString);

            result = _compare.Compare(dict2, dict1);

            if (!result.AreEqual)
                throw new Exception(result.DifferencesString);


            dict1.Add("1003", p3);
            dict2.Add("1003", p3);

            result = _compare.Compare(dict1, dict2);

            if (!result.AreEqual)
                throw new Exception(result.DifferencesString);

            result = _compare.Compare(dict2, dict1);

            if (!result.AreEqual)
                throw new Exception(result.DifferencesString);
        }
        public void CachingTest()
        {
            List<Person> list1 = new List<Person>();
            List<Person> list2 = new List<Person>();

            for (int i = 1; i <= 10000; i++)
            {
                Person person = new Person();
                person.DateCreated = DateTime.Now;
                person.Name = "Robot " + i;
                list1.Add(person);
                list2.Add(Common.CloneWithSerialization(person));
            }

            _compare.Config.Caching = false;
            Stopwatch watch = new Stopwatch();
            watch.Start();
            Assert.IsTrue(_compare.Compare(list1, list2).AreEqual);
            watch.Stop();
            long timeWithNoCaching = watch.ElapsedMilliseconds;
            Console.WriteLine("Compare 10000 objects no caching: {0} milliseconds", timeWithNoCaching);

            _compare.Config.Caching = true;
            watch.Reset();
            watch.Start();
            Assert.IsTrue(_compare.Compare(list1, list2).AreEqual);
            watch.Stop();
            long timeWithCaching = watch.ElapsedMilliseconds;
            Console.WriteLine("Compare 10000 objects with caching: {0} milliseconds", timeWithCaching);

            Assert.IsTrue(timeWithCaching < timeWithNoCaching);
        }
        public void TestIndexerWithIgnoreCollectionLengthNegative()
        {
            var jane = new Person { Name = "Jane" };
            var john = new Person { Name = "John" };
            var mary = new Person { Name = "Mary" };
            var jack = new Person { Name = "Jack" };

            var nameList1 = new List<Person>() { jane, john, jack, mary };
            var nameList2 = new List<Person>() { jane, john, jack };

            var class1 = new ListClass<Person>(nameList1);
            var class2 = new ListClass<Person>(nameList2);

            var prior = _compare.Config.MaxDifferences;
            _compare.Config.MaxDifferences = int.MaxValue;
            _compare.Config.IgnoreCollectionOrder = true;

            var result = _compare.Compare(class1, class2);
            Console.WriteLine(result.DifferencesString);

            Assert.AreEqual(3, result.Differences.Count);

            result = _compare.Compare(class2, class1);
            Console.WriteLine(result.DifferencesString);
            Assert.AreEqual(3, result.Differences.Count);


            _compare.Config.MaxDifferences = prior;
        }
        public void TestDictionaryWithIgnoreCollectionOrderNegative()
        {
            var p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Owen";

            var p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = DateTime.Now.AddDays(-1);

            var p3 = new Person();
            p3.Name = "Wink";
            p3.DateCreated = DateTime.Now.AddDays(-2);

            var p4 = new Person();
            p3.Name = "Larry";
            p3.DateCreated = DateTime.Now.AddDays(-3);

            var dict1 = new Dictionary<string, Person>();
            dict1.Add("1001", p1);
            dict1.Add("1002", p2);
            dict1.Add("1003", p3);

            var dict2 = new Dictionary<string, Person>();
            dict2.Add("1002", p2);
            dict2.Add("1001", p1);
            dict2.Add("1003", p4);

            Assert.IsFalse(_compare.Compare(dict1, dict2).AreEqual);
        }
Example #22
0
        public void ArrayTestNegative()
        {
            Person p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Greg";

            Person p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = p1.DateCreated;

            Person[] array1 = new Person[2];
            Person[] array2 = new Person[2];

            array1[0] = p1;
            array1[1] = p2;

            array2[0] = Common.CloneWithSerialization(p1);
            array2[1] = Common.CloneWithSerialization(p2);
            array2[1].Name = "Bob";

            Assert.IsFalse(_compare.Compare(array1, array2).AreEqual);
        }
        public void TickTest()
        {
            Person p1 = new Person();
            p1.DateCreated = DateTime.Now;
            p1.Name = "Greg";
            Person p2 = new Person();
            p2.Name = "Greg";
            p2.DateCreated = p1.DateCreated.AddTicks(1);

            Assert.IsFalse(_compare.Compare(p1, p2).AreEqual);
        }