コード例 #1
0
        public void WhenListOfPersonsEqual_ThenTrue()
        {
            var comparator = new CollectionComparator <Person>();

            List <Person> persons = new List <Person>();

            persons.Add(new Person()
            {
                Name = "Hans", Id = 1
            });
            persons.Add(new Person()
            {
                Name = "Peter", Id = 2
            });

            List <Person> persons2 = new List <Person>();

            persons2.Add(new Person()
            {
                Name = "Hans", Id = 1
            });
            persons2.Add(new Person()
            {
                Name = "Peter", Id = 2
            });

            var result = comparator.IsEqual(persons, persons2);

            Assert.AreEqual(true, result.Result);
            Assert.AreEqual("", result.Message);
        }
コード例 #2
0
        public void WhenListOfPersonsDiffer_ThenFalse()
        {
            var comparator = new CollectionComparator <Person>();

            List <Person> persons = new List <Person>();

            persons.Add(new Person()
            {
                Name = "Hans", Id = 1
            });
            persons.Add(new Person()
            {
                Name = "Peter", Id = 2
            });

            List <Person> persons2 = new List <Person>();

            persons2.Add(new Person()
            {
                Name = "Hans", Id = 3
            });
            persons2.Add(new Person()
            {
                Name = "Peter", Id = 2
            });

            var result = comparator.IsEqual(persons, persons2);

            Assert.AreEqual(false, result.Result);
            Assert.IsTrue(result.Message.Contains("Values at index 0 differ"));
        }
コード例 #3
0
        public void CompareTest_WhenBothNull_ThenCorrect()
        {
            var           comparator = new CollectionComparator <string>();
            List <string> list1      = null;
            List <string> list2      = null;

            var result = comparator.IsEqual(list1, list2);

            Assert.AreEqual(true, result.Result);
            Assert.AreEqual("Both collections are null.", result.Message);
        }
コード例 #4
0
        public void CompareTest_WhenFloatArrayEqual_ThenTrue()
        {
            var comparator = new CollectionComparator <double>();

            var array1 = new double[] { 1, 2, 3 };
            var array2 = new double[] { 1, 2, 3 };

            var result = comparator.IsEqual(array1, array2);

            Assert.AreEqual(true, result.Result);
            Assert.AreEqual("", result.Message);
        }
コード例 #5
0
        public void CompareTest_WhenFloatArrayDiffer_ThenFalse()
        {
            var comparator = new CollectionComparator <double>();

            var array1 = new double[] { 1, 2, 3 };
            var array2 = new double[] { 1, 2, 3.0001 };

            var result = comparator.IsEqual(array1, array2);

            Assert.AreEqual(false, result.Result);
            Assert.AreEqual(true, result.Message.ToLower().Contains("values") && result.Message.ToLower().Contains("differ"));
        }
コード例 #6
0
        public void CompareTest_WhenDoubleArrayAlmostEqualSetPrecision_ThenFalse()
        {
            var comparator = new CollectionComparator <double>(precision: 0.000001);

            var array1 = new double[] { 1.000001, 2, 3 };
            var array2 = new double[] { 1, 2, 3 };

            var result = comparator.IsEqual(array1, array2);

            Assert.AreEqual(true, result.Result);
            Assert.AreEqual("", result.Message);
        }
コード例 #7
0
        public void CompareTest_WhenOneListNull_ThenCorrect()
        {
            var           comparator = new CollectionComparator <string>();
            List <string> list1      = null;
            var           list2      = new List <string>()
            {
                "a", "b", "c"
            };

            var result = comparator.IsEqual(list1, list2);

            Assert.AreEqual(false, result.Result);
            Assert.AreEqual("One collection is null, the other has elements.", result.Message);
        }
コード例 #8
0
        public void CompareTest_WhenIntEqual_ThenTrue()
        {
            var comparator = new CollectionComparator <int>();

            var list1 = new List <int>()
            {
                1, 2, 3
            };
            var list2 = new List <int>()
            {
                1, 2, 3
            };

            var result = comparator.IsEqual(list1, list2);

            Assert.AreEqual(true, result.Result);
            Assert.AreEqual("", result.Message);
        }
コード例 #9
0
        public void CompareTest_WhenStringDiffer_ThenFalse()
        {
            var comparator = new CollectionComparator <string>();

            var list1 = new List <string>()
            {
                "a", "b", "c"
            };
            var list2 = new List <string>()
            {
                "a", "b"
            };

            var result = comparator.IsEqual(list1, list2);

            Assert.AreEqual(false, result.Result);
            Assert.AreEqual(true, result.Message.ToLower().Contains("sizes differ"));
        }
コード例 #10
0
        public void CompareTest_WhenStringEqual_ThenTrue()
        {
            var comparator = new CollectionComparator <string>();

            var list1 = new List <string>()
            {
                "a", "b", "c"
            };
            var list2 = new List <string>()
            {
                "a", "b", "c"
            };

            var result = comparator.IsEqual(list1, list2);

            Assert.AreEqual(true, result.Result);
            Assert.AreEqual("", result.Message);
        }
コード例 #11
0
        public void CompareTest_WhenIntDiffer_ThenFalse()
        {
            var comparator = new CollectionComparator <int>();

            var list1 = new List <int>()
            {
                1, 2, 3
            };
            var list2 = new List <int>()
            {
                1, 2, 4
            };

            var result = comparator.IsEqual(list1, list2);

            Assert.AreEqual(false, result.Result);
            Assert.AreEqual(true, result.Message.ToLower().Contains("values") && result.Message.ToLower().Contains("differ"));
        }