public void When_the_same_objects_are_expected_to_be_the_same_it_should_not_fail() { // Arrange var subject = new ClassWithCustomEqualMethod(1); var referenceToSubject = subject; // Act / Assert subject.Should().BeSameAs(referenceToSubject); }
public void When_non_equal_objects_are_expected_to_be_not_equal_it_should_not_fail() { // Arrange var someObject = new ClassWithCustomEqualMethod(1); var nonEqualObject = new ClassWithCustomEqualMethod(2); // Act / Assert someObject.Should().NotBe(nonEqualObject); }
public void When_two_different_objects_are_expected_not_to_be_the_same_it_should_not_fail() { // Arrange var someObject = new ClassWithCustomEqualMethod(1); var notSameObject = new ClassWithCustomEqualMethod(1); // Act / Assert someObject.Should().NotBeSameAs(notSameObject); }
private bool Equals(ClassWithCustomEqualMethod other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(other.Key == Key); }
public void When_the_same_objects_are_expected_to_be_the_same_it_should_not_fail() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var subject = new ClassWithCustomEqualMethod(1); var referenceToSubject = subject; //------------------------------------------------------------------------------------------------------------------- // Act / Arrange //------------------------------------------------------------------------------------------------------------------- subject.Should().BeSameAs(referenceToSubject); }
public void When_two_different_objects_are_expected_to_be_equal_it_should_fail_with_a_clear_explanation() { // Arrange var someObject = new ClassWithCustomEqualMethod(1); var nonEqualObject = new ClassWithCustomEqualMethod(2); // Act Action act = () => someObject.Should().Be(nonEqualObject); // Assert act.Should().Throw <XunitException>().WithMessage( "Expected someObject to be ClassWithCustomEqualMethod(2), but found ClassWithCustomEqualMethod(1)."); }
public void When_two_equal_object_are_expected_to_be_equal_it_should_not_fail() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var someObject = new ClassWithCustomEqualMethod(1); var equalObject = new ClassWithCustomEqualMethod(1); //------------------------------------------------------------------------------------------------------------------- // Act / Assert //------------------------------------------------------------------------------------------------------------------- someObject.Should().Be(equalObject); }
public void When_the_subject_is_null_it_should_fail() { // Arrange object someObject = null; var nonEqualObject = new ClassWithCustomEqualMethod(2); // Act Action act = () => someObject.Should().Be(nonEqualObject); // Assert act.Should().Throw <XunitException>() .WithMessage("Expected someObject to be ClassWithCustomEqualMethod(2), but found <null>."); }
public void When_two_different_objects_are_expected_not_to_be_the_same_it_should_not_fail() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var someObject = new ClassWithCustomEqualMethod(1); var notSameObject = new ClassWithCustomEqualMethod(1); //------------------------------------------------------------------------------------------------------------------- // Act / Assert //------------------------------------------------------------------------------------------------------------------- someObject.Should().NotBeSameAs(notSameObject); }
public void When_two_equal_object_are_expected_not_to_be_the_same_it_should_fail() { // Arrange var someObject = new ClassWithCustomEqualMethod(1); ClassWithCustomEqualMethod sameObject = someObject; // Act Action act = () => someObject.Should().NotBeSameAs(sameObject, "they are {0} {1}", "the", "same"); // Assert act.Should().Throw <XunitException>() .WithMessage("Did not expect someObject to refer to*ClassWithCustomEqualMethod(1) because they are the same."); }
public void When_two_equal_objects_are_expected_not_to_be_equal_it_should_fail_with_a_clear_explanation() { // Arrange var someObject = new ClassWithCustomEqualMethod(1); var equalObject = new ClassWithCustomEqualMethod(1); // Act Action act = () => someObject.Should().NotBe(equalObject); // Assert act.Should().Throw <XunitException>().WithMessage( "Did not expect someObject to be equal to ClassWithCustomEqualMethod(1)."); }
public void When_two_different_objects_are_expected_to_be_equal_it_should_fail_and_use_the_reason() { // Arrange var someObject = new ClassWithCustomEqualMethod(1); var nonEqualObject = new ClassWithCustomEqualMethod(2); // Act Action act = () => someObject.Should().Be(nonEqualObject, "because it should use the {0}", "reason"); // Assert act.Should().Throw <XunitException>() .WithMessage( "Expected someObject to be ClassWithCustomEqualMethod(2) because it should use the reason, but found ClassWithCustomEqualMethod(1)."); }
public void When_two_equal_objects_are_expected_not_to_be_equal_it_should_fail_and_use_the_reason() { // Arrange var someObject = new ClassWithCustomEqualMethod(1); var equalObject = new ClassWithCustomEqualMethod(1); // Act Action act = () => someObject.Should().NotBe(equalObject, "because we want to test the failure {0}", "message"); // Assert act.Should().Throw <XunitException>().WithMessage( "Did not expect someObject to be equal to ClassWithCustomEqualMethod(1) " + "because we want to test the failure message."); }
public void When_two_equal_object_are_expected_not_to_be_the_same_it_should_fail() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var someObject = new ClassWithCustomEqualMethod(1); ClassWithCustomEqualMethod sameObject = someObject; //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- Action act = () => someObject.Should().NotBeSameAs(sameObject, "they are {0} {1}", "the", "same"); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- act.ShouldThrow <AssertFailedException>() .WithMessage("Did not expect reference to object \r\nClassWithCustomEqualMethod(1) because they are the same."); }
public void When_the_subject_is_null_it_should_fail() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- object someObject = null; var nonEqualObject = new ClassWithCustomEqualMethod(2); //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- Action act = () => someObject.Should().Be(nonEqualObject); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage("Expected object to be ClassWithCustomEqualMethod(2), but found <null>."); }
public void When_two_different_objects_are_expected_to_be_equal_it_should_fail_with_a_clear_explanation() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var someObject = new ClassWithCustomEqualMethod(1); var nonEqualObject = new ClassWithCustomEqualMethod(2); //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- Action act = () => someObject.Should().Be(nonEqualObject); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected object to be ClassWithCustomEqualMethod(2), but found ClassWithCustomEqualMethod(1)."); }
public void When_two_equal_object_are_expected_not_to_be_the_same_it_should_fail() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var someObject = new ClassWithCustomEqualMethod(1); ClassWithCustomEqualMethod sameObject = someObject; //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- Action act = () => someObject.Should().NotBeSameAs(sameObject, "they are {0} {1}", "the", "same"); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage("Did not expect reference to object \r\nClassWithCustomEqualMethod(1) because they are the same."); }
public void When_two_equal_objects_are_expected_not_to_be_equal_it_should_fail_with_a_clear_explanation() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var someObject = new ClassWithCustomEqualMethod(1); var equalObject = new ClassWithCustomEqualMethod(1); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => someObject.Should().NotBe(equalObject); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Did not expect object to be equal to ClassWithCustomEqualMethod(1)."); }
public void When_two_equal_objects_are_expected_not_to_be_equal_it_should_fail_and_use_the_reason() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var someObject = new ClassWithCustomEqualMethod(1); var equalObject = new ClassWithCustomEqualMethod(1); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => someObject.Should().NotBe(equalObject, "because we want to test the failure {0}", "message"); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Did not expect object to be equal to ClassWithCustomEqualMethod(1) " + "because we want to test the failure message."); }
public void When_two_different_objects_are_expected_to_be_equal_it_should_fail_and_use_the_reason() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var someObject = new ClassWithCustomEqualMethod(1); var nonEqualObject = new ClassWithCustomEqualMethod(2); //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- Action act = () => someObject.Should().Be(nonEqualObject, "because it should use the {0}", "reason"); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage( "Expected object to be ClassWithCustomEqualMethod(2) because it should use the reason, but found ClassWithCustomEqualMethod(1)."); }
private bool Equals(ClassWithCustomEqualMethod other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return other.Key == Key; }