void WhenPersonWithAgeReferenceAreEqual_ShouldBeEqualForAll() { var person = new PersonWithAge() { FirstName = "John", LastName = "Smith", Age = 25 }; var samePerson = person; Assert.True(person.Equals(samePerson)); Assert.True(person == samePerson); Assert.False(person != samePerson); Assert.True(person.GetHashCode() == samePerson.GetHashCode()); Assert.True(Equals(person, samePerson)); Assert.True(ReferenceEquals(person, samePerson)); }
void WhenPersonWithAgeFieldsNotTheSame_ShouldNotBeEqual() { var person = new PersonWithAge() { FirstName = "John", LastName = "Smith", Age = 25 }; var otherPerson = new PersonWithAge() { FirstName = "John", LastName = "Smith", Age = 30 }; Assert.False(person.Equals(otherPerson)); Assert.False(person == otherPerson); Assert.True(person != otherPerson); Assert.False(person.GetHashCode() == otherPerson.GetHashCode()); Assert.False(Equals(person, otherPerson)); Assert.False(ReferenceEquals(person, otherPerson)); }