public void GetHashCodeConsistencyTest()
        {
            var comparer           = new CompoundValueEqualityComparer <CompoundValueEqualityComparerTestClass> (x => (new object[] { x.Number, x.TestClass, x.Text, x.Text2 }));
            var comparerIgnoreText = new CompoundValueEqualityComparer <CompoundValueEqualityComparerTestClass> (x => (new object[] { x.Number, x.TestClass, x.Text2 }));
            var testClass          = new CompoundValueEqualityComparerTestClass {
                Number = 987654, TestClass = new ComparableTestClass(34567), Text = "the", Text2 = "quick"
            };
            var testClassCopy = new CompoundValueEqualityComparerTestClass {
                Number = 987654, TestClass = new ComparableTestClass(34567), Text = "the", Text2 = "quick"
            };
            var testClass2 = new CompoundValueEqualityComparerTestClass {
                Number = 987654, TestClass = new ComparableTestClass(34567), Text = "Wabra", Text2 = "quick"
            };

            Assert.That(comparer.Equals(testClass, testClassCopy), Is.True);
            Assert.That(comparer.Equals(testClass, testClass2), Is.False);
            Assert.That(comparer.GetHashCode(testClass), Is.EqualTo(comparer.GetHashCode(testClassCopy)));
            Assert.That(comparer.GetHashCode(testClass), Is.Not.EqualTo(comparer.GetHashCode(testClass2)));

            Assert.That(comparerIgnoreText.Equals(testClass, testClassCopy), Is.True);
            Assert.That(comparerIgnoreText.Equals(testClass, testClass2), Is.True);
            Assert.That(comparerIgnoreText.GetHashCode(testClass), Is.EqualTo(comparerIgnoreText.GetHashCode(testClassCopy)));
            Assert.That(comparerIgnoreText.GetHashCode(testClass), Is.EqualTo(comparerIgnoreText.GetHashCode(testClass2)));
        }
Ejemplo n.º 2
0
 public override int GetHashCode()
 {
     return(_equalityComparer.GetHashCode(this));
 }
Ejemplo n.º 3
0
 public override int GetHashCode ()
 {
   return _userRoleAclAceCombinationsComparer.GetHashCode(this);
 }