Beispiel #1
0
        public void When_two_equal_objects_should_not_be_equal_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("Hello");
            var other   = new ComparableOfString("Hello");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().NotBe(other, "they represent different things");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act
            .Should().Throw <XunitException>()
            .WithMessage(
#if NETCOREAPP1_1
                "*Did not expect object to be equal to*Hello*because they represent different things.*");
#else
                "*Did not expect subject to be equal to*Hello*because they represent different things.*");
#endif
        }
        public void When_two_instances_are_equal_it_should_succeed()
        {
            // Arrange
            var subject = new ComparableOfString("Hello");
            var other   = new ComparableOfString("Hello");

            // Act / Assert
            subject.Should().Be(other);
        }
Beispiel #3
0
        public void When_subject_is_greater_than_another_subject_and_greater_or_equal_is_expected_it_should_not_throw()
        {
            // Arrange
            var subject = new ComparableOfString("xyz");
            var other   = new ComparableOfString("abc");

            // Act
            Action act = () => subject.Should().BeGreaterOrEqualTo(other);

            // Assert
            act.Should().NotThrow();
        }
        public void When_two_unequal_objects_should_not_be_equal_it_should_not_throw()
        {
            // Arrange
            var subject = new ComparableOfString("Hello");
            var other   = new ComparableOfString("Hi");

            // Act
            Action act = () => subject.Should().NotBe(other);

            // Assert
            act.Should().NotThrow();
        }
Beispiel #5
0
        public void When_subject_is_less_than_another_subject_and_less_or_equal_is_expected_it_should_not_throw()
        {
            // Arrange
            var subject = new ComparableOfString("City");
            var other   = new ComparableOfString("World");

            // Act
            Action act = () => subject.Should().BeLessOrEqualTo(other);

            // Assert
            act.Should().NotThrow();
        }
Beispiel #6
0
        public void When_subect_is_not_ranked_equal_to_another_subject_and_that_is_expected_it_should_not_throw()
        {
            // Arrange
            var subject = new ComparableOfString("Hello");
            var other   = new ComparableOfString("Hi");

            // Act
            Action act = () => subject.Should().NotBeRankedEquallyTo(other);

            // Assert
            act.Should().NotThrow();
        }
Beispiel #7
0
        public void When_subject_is_equal_to_another_subject_and_expected_to_be_greater_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("efg");
            var other   = new ComparableOfString("efg");

            // Act
            Action act = () => subject.Should().BeGreaterThan(other);

            // Assert
            act.Should().Throw <XunitException>();
        }
Beispiel #8
0
        public void When_assertion_an_instance_not_to_be_null_and_it_is_not_null_it_should_succeed()
        {
            // Arrange
            var subject = new ComparableOfString("");

            // Act
            Action action = () =>
                            subject.Should().NotBeNull();

            // Assert
            action.Should().NotThrow();
        }
Beispiel #9
0
        public void When_assertion_an_instance_to_be_null_and_it_is_not_null_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("");

            // Act
            Action action = () =>
                            subject.Should().BeNull();

            // Assert
            action.Should().Throw <XunitException>()
            .WithMessage("Expected subject to be <null>, but found*");
        }
Beispiel #10
0
        public void When_assertion_an_instance_not_to_be_null_and_it_is_null_it_should_throw()
        {
            // Arrange
            ComparableOfString subject = null;

            // Act
            Action action = () =>
                            subject.Should().NotBeNull();

            // Assert
            action.Should().Throw <XunitException>()
            .WithMessage("Expected subject not to be <null>.");
        }
Beispiel #11
0
        public void When_subject_is_not_greater_than_another_subject_but_that_is_expected_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("abc");
            var other   = new ComparableOfString("def");

            // Act
            Action act = () => subject.Should().BeGreaterThan(other, "'a' is smaller then 'e'");

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage("Expected subject*abc*to be greater than*def*because 'a' is smaller then 'e'.");
        }
Beispiel #12
0
        public void When_subject_is_greater_than_another_subject_and_that_is_not_expected_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("World");
            var other   = new ComparableOfString("City");

            // Act
            Action act = () => subject.Should().BeLessOrEqualTo(other, "we want to order them");

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage("Expected subject*World*to be less or equal to*City*because we want to order them.");
        }
Beispiel #13
0
        public void When_subject_is_not_ranked_equal_to_another_subject_but_that_is_expected_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("42");
            var other   = new ComparableOfString("Forty two");

            // Act
            Action act = () => subject.Should().BeRankedEquallyTo(other, "they represent the same number");

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage("Expected subject*42*to be ranked as equal to*Forty two*because they represent the same number.");
        }
Beispiel #14
0
        public void When_subject_is_ranked_equal_to_another_subject_but_that_is_not_expected_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("Lead");
            var other   = new ComparableOfString("Lead");

            // Act
            Action act = () => subject.Should().NotBeRankedEquallyTo(other, "they represent different concepts");

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage("Expected subject*Lead*not to be ranked as equal to*Lead*because they represent different concepts.");
        }
Beispiel #15
0
        public void When_subject_is_not_less_than_another_subject_but_that_is_expected_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("World");
            var other   = new ComparableOfString("City");

            // Act
            Action act = () => subject.Should().BeLessThan(other, "a city is smaller than the world");

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage("Expected subject*World*to be less than*City*because a city is smaller than the world.");
        }
Beispiel #16
0
        public void When_subject_is_less_than_another_subject_and_that_is_not_expected_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("abc");
            var other   = new ComparableOfString("def");

            // Act
            Action act = () => subject.Should().BeGreaterOrEqualTo(other, "'d' is bigger then 'a'");

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage("Expected subject*abc*to be greater or equal to*def*because 'd' is bigger then 'a'.");
        }
        public void When_two_instances_are_not_equal_it_should_throw()
        {
            // Arrange
            var subject = new ComparableOfString("Hello");
            var other   = new ComparableOfString("Hi");

            // Act
            Action act = () => subject.Should().Be(other, "they have the same property values");

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage(
                "Expected*Hi*because they have the same property values, but found*Hello*.");
        }
Beispiel #18
0
        public void When_subject_is_less_than_another_subject_and_that_is_expected_it_should_not_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("City");
            var other   = new ComparableOfString("World");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeLessThan(other);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
Beispiel #19
0
        public void When_assertion_an_instance_to_be_null_and_it_is_null_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ComparableOfString subject = null;

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                            subject.Should().BeNull();

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.Should().NotThrow();
        }
Beispiel #20
0
        public void When_subject_is_equal_to_another_subject_and_that_is_equal_or_greater_it_should_not_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("def");
            var other   = new ComparableOfString("def");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeGreaterOrEqualTo(other);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
Beispiel #21
0
        public void When_subject_is_greater_than_another_subject_and_that_is_expected_it_should_not_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("efg");
            var other   = new ComparableOfString("abc");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeGreaterThan(other);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_assertion_an_instance_not_to_be_null_and_it_is_null_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ComparableOfString subject = null;

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () =>
                            subject.Should().NotBeNull();

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldThrow <AssertFailedException>()
            .WithMessage(
                "Expected object not to be <null>.", ComparisonMode.Wildcard);
        }
        public void When_two_instances_are_not_equal_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("Hello");
            var other   = new ComparableOfString("Hi");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().Be(other, "they have the same property values");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act
            .ShouldThrow <AssertFailedException>()
            .WithMessage(
                "Expected*Hi*because they have the same property values, but found*Hello*.", ComparisonMode.Wildcard);
        }
        public void When_subject_is_not_greater_than_another_subject_but_that_is_expected_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("abc");
            var other   = new ComparableOfString("def");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeGreaterThan(other, "'a' is smaller then 'e'");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act
            .ShouldThrow <AssertFailedException>()
            .WithMessage("Expected object*abc*to be greater than*def*because 'a' is smaller then 'e'.",
                         ComparisonMode.Wildcard);
        }
        public void When_subject_is_less_than_another_subject_and_that_is_not_expected_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("abc");
            var other   = new ComparableOfString("def");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeGreaterOrEqualTo(other, "'d' is bigger then 'a'");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act
            .ShouldThrow <AssertFailedException>()
            .WithMessage("Expected object*abc*to be greater or equal to*def*because 'd' is bigger then 'a'.",
                         ComparisonMode.Wildcard);
        }
        public void When_subject_is_greater_than_another_subject_and_that_is_not_expected_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("World");
            var other   = new ComparableOfString("City");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeLessOrEqualTo(other, "we want to order them");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act
            .ShouldThrow <AssertFailedException>()
            .WithMessage("Expected object*World*to be less or equal to*City*because we want to order them.",
                         ComparisonMode.Wildcard);
        }
        public void When_subject_is_not_less_than_another_subject_but_that_is_expected_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("World");
            var other   = new ComparableOfString("City");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeLessThan(other, "a city is smaller than the world");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act
            .ShouldThrow <AssertFailedException>()
            .WithMessage("Expected object*World*to be less than*City*because a city is smaller than the world.",
                         ComparisonMode.Wildcard);
        }
        public void When_two_equal_objects_should_not_be_equal_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new ComparableOfString("Hello");
            var other   = new ComparableOfString("Hello");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().NotBe(other, "they represent different things");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act
            .ShouldThrow <AssertFailedException>()
            .WithMessage(
                "Did not expect object to be equal to*Hello*because they represent different things.",
                ComparisonMode.Wildcard);
        }