Exemple #1
0
            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_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_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_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.");
        }
Exemple #5
0
            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>.");
            }
Exemple #6
0
            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).");
            }
        private bool Equals(ClassWithCustomEqualMethod other)
        {
            if (other is null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(other.Key == Key);
        }
Exemple #8
0
            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).");
            }
Exemple #9
0
            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).");
            }
Exemple #10
0
            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.");
            }