public void When_the_same_failure_is_handled_twice_or_more_it_should_still_report_it_once()
        {
            // Arrange
            var scope = new AssertionScope();

            AssertionScope.Current.FailWith("Failure");
            AssertionScope.Current.FailWith("Failure");

            using (var nestedScope = new AssertionScope())
            {
                nestedScope.FailWith("Failure");
                nestedScope.FailWith("Failure");
            }

            // Act
            Action act = scope.Dispose;

            // Assert
            act.Should().Throw <XunitException>()
            .Which.Message.Should().Contain("Failure", Exactly.Times(4));
        }
Ejemplo n.º 2
0
        public static object[][] FailingConstraints() => new object[][]
        {
            new object[] { AtLeast.Once(), 0 },
            new object[] { AtLeast.Twice(), 1 },
            new object[] { AtLeast.Thrice(), 2 },
            new object[] { AtLeast.Times(4), 3 },

            new object[] { AtMost.Once(), 2 },
            new object[] { AtMost.Twice(), 3 },
            new object[] { AtMost.Thrice(), 4 },
            new object[] { AtMost.Times(4), 5 },

            new object[] { Exactly.Once(), 0 },
            new object[] { Exactly.Once(), 2 },
            new object[] { Exactly.Twice(), 1 },
            new object[] { Exactly.Twice(), 3 },
            new object[] { Exactly.Thrice(), 2 },
            new object[] { Exactly.Thrice(), 4 },
            new object[] { Exactly.Times(4), 3 },
            new object[] { Exactly.Times(4), 5 },

            new object[] { LessThan.Twice(), 2 },
            new object[] { LessThan.Twice(), 3 },
            new object[] { LessThan.Thrice(), 3 },
            new object[] { LessThan.Thrice(), 4 },
            new object[] { LessThan.Times(4), 4 },
            new object[] { LessThan.Times(4), 5 },

            new object[] { MoreThan.Once(), 0 },
            new object[] { MoreThan.Once(), 1 },
            new object[] { MoreThan.Twice(), 1 },
            new object[] { MoreThan.Twice(), 2 },
            new object[] { MoreThan.Thrice(), 2 },
            new object[] { MoreThan.Thrice(), 3 },
            new object[] { MoreThan.Times(4), 3 },
            new object[] { MoreThan.Times(4), 4 },
        };
Ejemplo n.º 3
0
                public void When_string_containment_equivalent_of_exactly_is_asserted_and_actual_value_contains_the_expected_string_exactly_expected_times_it_should_not_throw()
                {
                    // Arrange
                    string actual            = "abCDEBcDF";
                    string expectedSubstring = "Bcd";

                    // Act
                    Action act = () => actual.Should().ContainEquivalentOf(expectedSubstring, Exactly.Times(2));

                    // Assert
                    act.Should().NotThrow();
                }
Ejemplo n.º 4
0
                public void When_string_containment_equivalent_of_exactly_is_asserted_and_actual_value_contains_the_expected_string_but_not_exactly_expected_times_it_should_throw()
                {
                    // Arrange
                    string actual            = "abCDEBcDF";
                    string expectedSubstring = "Bcd";

                    // Act
                    Action act = () => actual.Should().ContainEquivalentOf(expectedSubstring, Exactly.Times(3));

                    // Assert
                    act.Should().Throw <XunitException>()
                    .WithMessage("Expected * \"abCDEBcDF\" to contain equivalent of \"Bcd\" exactly 3 times, but found it 2 times.");
                }