public void Struct_Equal() { PersonStruct p1 = new PersonStruct("Ehsan Sajjad"); PersonStruct p2 = new PersonStruct("Ahsan Sajjad"); PersonStruct p3 = new PersonStruct("Ehsan Sajjad"); Assert.That(p1.Equals(p3)); Assert.That((object)p1 != (object)p3); Assert.That(!p1.Equals(p2)); }
void WhenTwoValuesAreTheSame_ShouldBeEqual() { var person = new PersonStruct() { FirstName = "John", LastName = "Smith" }; var samePerson = person; Assert.True(person.Equals(samePerson)); Assert.True(person.GetHashCode() == samePerson.GetHashCode()); Assert.True(person == samePerson); Assert.False(person != samePerson); }
public void Equals_SecondPersonIsNull_ReturnsFalse() { // Arrange var p1 = new PersonStruct { FirstName = "Kim", LastName = "Kuan" }; // Act var result = p1.Equals(null); // Assert Assert.IsFalse(result); }
void WhenTwoStructsContainsDifferentValues_ShouldNotBeEqual() { var person = new PersonStruct() { FirstName = "John", LastName = "Smith" }; var otherPerson = new PersonStruct() { FirstName = "Bob", LastName = "Smith" };; Assert.False(person.Equals(otherPerson)); Assert.False(person.GetHashCode() == otherPerson.GetHashCode()); Assert.False(person == otherPerson); Assert.True(person != otherPerson); }
public void Equals_SecondPersonHasIncompatibleType_ReturnsFalse() { // Arrange var p1 = new PersonStruct { FirstName = "Kim", LastName = "Kuan" }; var p2 = new PersonClass { FirstName = "Kim", LastName = "Kuan" }; // Act var result = p1.Equals(p2); // Assert Assert.IsFalse(result); }
public void Equals_LastNamesNotEqual_ReturnsFalse() { // Arrange var p1 = new PersonStruct { FirstName = "Kim", LastName = "Kuan" }; var p2 = new PersonStruct { FirstName = "Kim", LastName = "Kuann" }; // Act var result = p1.Equals(p2); // Assert Assert.IsFalse(result); }