public void DocumentationTest()
        {
            //This is the comparison class
            CompareObjects compareObjects = new CompareObjects();

            //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
            if (!compareObjects.Compare(person1, person2))
                Console.WriteLine(compareObjects.DifferencesString);
        }
        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));
        }
        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);

            if (!_compare.Compare(array1, array2))
                throw new Exception(_compare.DifferencesString);
        }
        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));

        }
        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));
        }
        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);

            if (!_compare.Compare(dict1, dict2))
                throw new Exception(_compare.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;

            if (!_compare.Compare(p1, p2))
                throw new Exception(_compare.DifferencesString);
        }
 public void OneObjectNull()
 {
     Person p1 = null;
     Person p2 = new Person();     
     Assert.IsFalse(_compare.Compare(p1, p2));
     Assert.IsFalse(_compare.Compare(p2, p1));
 }
        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);

            Assert.IsFalse(_compare.Compare(class1, class2));
        }
        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));
        }
        public void CachingTest()
        {
            List<Person> list1 = new List<Person>();
            List<Person> list2 = new List<Person>();

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

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

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

            Assert.IsTrue(timeWithCaching < timeWithNoCaching);
        }