public void TwoIdenfierNumbers_WithDifferentValue_AreNotEqual(long lhsNum, int lhsDigit, long rhsNum, int rhsDigit) { var lhs = new IdentificationNumber(lhsNum, lhsDigit); var rhs = new IdentificationNumber(rhsNum, rhsDigit); Assert.False(lhs.GetHashCode() == rhs.GetHashCode(), "In general, different values can have same hash code, but in this particular case they don't have it."); Assert.False(lhs.Equals((object)rhs)); Assert.False(lhs.Equals(rhs)); Assert.False(lhs == rhs); Assert.True(lhs != rhs); }
public void TwoIdenfierNumbers_WithSameValue_AreEqual() { var lhs = new IdentificationNumber(1257, 2); var rhs = new IdentificationNumber(1257, 2); Assert.Equal(lhs.GetHashCode(), rhs.GetHashCode()); Assert.True(lhs.Equals((object)rhs)); Assert.True(lhs.Equals(rhs)); Assert.True(lhs == rhs); Assert.False(lhs != rhs); }
public override int GetHashCode() { unchecked { var hashCode = Name.GetHashCode(); hashCode = (hashCode * 397) ^ Id.GetHashCode(); hashCode = (hashCode * 397) ^ Surname.GetHashCode(); hashCode = (hashCode * 397) ^ IdentificationNumber.GetHashCode(); hashCode = (hashCode * 397) ^ (Email?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ DateOfBirth.GetHashCode(); hashCode = (hashCode * 397) ^ ProfileCreationDate.GetHashCode(); return(hashCode); } }
public override int GetHashCode() { return(IdentificationNumber.GetHashCode() + Email.GetHashCode()); }