public void Equals_ReferenceOtherNull_ReturnsFalse()
        {
            var comparer = new FuncEqualityComparer <ComparerTestObject, string>(x => x.StrValue);

            var testObj1 = new ComparerTestObject {
                StrValue = "HelloWorld"
            };

            Assert.False(comparer.Equals(testObj1, null));
        }
        public void GetHashCode_IntValue_ReturnsIntHashCode()
        {
            var comparer = new FuncEqualityComparer <ComparerTestObject, int>(x => x.IntValue1);

            var testObj1 = new ComparerTestObject {
                IntValue1 = 1
            };

            Assert.Equal(testObj1.IntValue1.GetHashCode(), comparer.GetHashCode(testObj1));
        }
        public void GetHashCode_StrValueNull_ReturnsZero()
        {
            var comparer = new FuncEqualityComparer <ComparerTestObject, string>(x => x.StrValue);

            var testObj1 = new ComparerTestObject {
                StrValue = null
            };

            Assert.Equal(0, comparer.GetHashCode(testObj1));
        }
        public void Equals_SameReference_ReturnsTrue()
        {
            var comparer = new FuncEqualityComparer <ComparerTestObject, string>(x => x.StrValue);

            var testObj = new ComparerTestObject {
                StrValue = "HelloWorld"
            };

            Assert.True(comparer.Equals(testObj, testObj));
        }
        public void GetHashCode_SingleKeyStrValue_ReturnsStrHashCode()
        {
            var comparer = new MultiFuncEqualityComparer <ComparerTestObject, string>(x => x.StrValue);

            var testObj = new ComparerTestObject {
                StrValue = "HelloWorld"
            };

            Assert.Equal(testObj.StrValue.GetHashCode(), comparer.GetHashCode(testObj));
        }
        public void GetHashCode_SingleKeyIntValue_ReturnsIntHashCode()
        {
            var comparer = new MultiFuncEqualityComparer <ComparerTestObject, int>(x => x.IntValue1);

            var testObj = new ComparerTestObject {
                IntValue1 = 1
            };

            Assert.Equal(testObj.IntValue1.GetHashCode(), comparer.GetHashCode(testObj));
        }
        public void GetHashCode_StrValue_ReturnsIntHashCode()
        {
            var comparer = new FuncEqualityComparer <ComparerTestObject, string>(x => x.StrValue);

            var testObj1 = new ComparerTestObject {
                StrValue = "HelloWorld"
            };

            Assert.Equal(testObj1.StrValue.GetHashCode(), comparer.GetHashCode(testObj1));
        }
        public void GetHashCode_TwoKeysIntValue_ReturnsCorrectHashCode()
        {
            var comparer =
                new MultiFuncEqualityComparer <ComparerTestObject, int, int>(x => x.IntValue1, x => x.IntValue2);

            var testObj = new ComparerTestObject {
                IntValue1 = 1, IntValue2 = 2
            };

            Assert.Equal(ArrayHashCode(testObj.IntValue1, testObj.IntValue2), comparer.GetHashCode(testObj));
        }
        public void Equals_TwoKeysSameTypeEquals_ReturnsTrue()
        {
            var comparer = new MultiFuncEqualityComparer <ComparerTestObject, int>(x => x.IntValue1, x => x.IntValue2);

            var testObj1 = new ComparerTestObject {
                IntValue1 = 1, IntValue2 = 1
            };
            var testObj2 = new ComparerTestObject {
                IntValue1 = 1, IntValue2 = 1
            };

            Assert.True(comparer.Equals(testObj1, testObj2));
        }
        public void Equals_SingleKeyEquals_ReturnsTrue()
        {
            var comparer = new MultiFuncEqualityComparer <ComparerTestObject, int>(x => x.IntValue1);

            var testObj1 = new ComparerTestObject {
                IntValue1 = 1
            };
            var testObj2 = new ComparerTestObject {
                IntValue1 = 1
            };

            Assert.True(comparer.Equals(testObj1, testObj2));
        }
        public void Equals_NotEqual_ReturnsFalse()
        {
            var comparer = new FuncEqualityComparer <ComparerTestObject, int>(x => x.IntValue1);

            var testObj1 = new ComparerTestObject {
                IntValue1 = 1
            };
            var testObj2 = new ComparerTestObject {
                IntValue1 = 2
            };

            Assert.False(comparer.Equals(testObj1, testObj2));
        }
        public void Compare_TwoKeys_ReturnsExpectedResult(int obj0Value1, int obj0Value2, int obj1Value1,
            int obj1Value2, SortOrder sortOrder, int expectedResult)
        {
            var obj0 = new ComparerTestObject {IntValue1 = obj0Value1, IntValue2 = obj0Value2};
            var obj1 = new ComparerTestObject {IntValue1 = obj1Value1, IntValue2 = obj1Value2};

            var comparer = new MultiFuncComparer<ComparerTestObject, int, int>(
                new SortFieldInfo<ComparerTestObject, int>(x => x.IntValue1, sortOrder),
                new SortFieldInfo<ComparerTestObject, int>(x => x.IntValue2, sortOrder));

            var result = comparer.Compare(obj0, obj1);

            Assert.Equal(expectedResult, result);
        }
        public void Equals_TwoKeysDifferentTypeEquals_ReturnsTrue()
        {
            var comparer =
                new MultiFuncEqualityComparer <ComparerTestObject, int, string>(x => x.IntValue1, x => x.StrValue);

            var testObj1 = new ComparerTestObject {
                IntValue1 = 1, StrValue = "Hello"
            };
            var testObj2 = new ComparerTestObject {
                IntValue1 = 1, StrValue = "Hello"
            };

            Assert.True(comparer.Equals(testObj1, testObj2));
        }
Exemple #14
0
        public void Compare_StrValue_ReturnCorrectCompareResult(string value0, string value1, int expectedResult)
        {
            var obj0 = new ComparerTestObject {
                StrValue = value0
            };
            var obj1 = new ComparerTestObject {
                StrValue = value1
            };

            var comparer = new FuncComparer <ComparerTestObject, string>(x => x.StrValue, SortOrder.Ascending);

            var result = comparer.Compare(obj0, obj1);

            Assert.Equal(expectedResult, result);
        }
        public void GetHashCode_FiveKeysIntValue_ReturnsCorrectHashCode()
        {
            var comparer = new MultiFuncEqualityComparer <ComparerTestObject, int, int, int, int, int>(x => x.IntValue1,
                                                                                                       x => x.IntValue2, x => x.IntValue3, x => x.IntValue4, x => x.IntValue5);

            var testObj = new ComparerTestObject
            {
                IntValue1 = 1, IntValue2 = 2, IntValue3 = 3, IntValue4 = 4, IntValue5 = 5
            };

            Assert.Equal(
                ArrayHashCode(testObj.IntValue1, testObj.IntValue2, testObj.IntValue3, testObj.IntValue4,
                              testObj.IntValue5),
                comparer.GetHashCode(testObj));
        }
Exemple #16
0
        public void Compare_IntValue_ReturnCorrectCompareResult(int value0, int value1, int expectedResult)
        {
            var obj0 = new ComparerTestObject {
                IntValue1 = value0
            };
            var obj1 = new ComparerTestObject {
                IntValue1 = value1
            };

            var comparer = new FuncComparer <ComparerTestObject, int>(x => x.IntValue1, SortOrder.Ascending);

            var result = comparer.Compare(obj0, obj1);

            Assert.Equal(expectedResult, result);
        }
        public void Equals_ThreeKeysDifferentTypeNotEquals_ReturnsFalse()
        {
            var comparer =
                new MultiFuncEqualityComparer <ComparerTestObject, int, string, int>(x => x.IntValue1, x => x.StrValue,
                                                                                     x => x.IntValue2);

            var testObj1 = new ComparerTestObject {
                IntValue1 = 1, StrValue = "Hello", IntValue2 = 3
            };
            var testObj2 = new ComparerTestObject {
                IntValue1 = 2, StrValue = "Hello", IntValue2 = 3
            };

            Assert.False(comparer.Equals(testObj1, testObj2));
        }
        public void Equals_FiveKeysDifferentTypeEquals_ReturnsTrue()
        {
            var comparer = new MultiFuncEqualityComparer <ComparerTestObject, int, string, int, string, int>(
                x => x.IntValue1,
                x => x.StrValue, x => x.IntValue2, x => x.StrValue1, x => x.IntValue3);

            var testObj1 = new ComparerTestObject
            {
                IntValue1 = 1, StrValue = "Hello", IntValue2 = 3, StrValue1 = "World", IntValue3 = 123
            };
            var testObj2 = new ComparerTestObject
            {
                IntValue1 = 1, StrValue = "Hello", IntValue2 = 3, StrValue1 = "World", IntValue3 = 123
            };

            Assert.True(comparer.Equals(testObj1, testObj2));
        }