Beispiel #1
0
        public static object[][] PassingConstraints() => new object[][]
        {
            new object[] { AtLeast.Once(), 1 },
            new object[] { AtLeast.Once(), 2 },
            new object[] { AtLeast.Twice(), 2 },
            new object[] { AtLeast.Twice(), 3 },
            new object[] { AtLeast.Thrice(), 3 },
            new object[] { AtLeast.Thrice(), 4 },
            new object[] { AtLeast.Times(4), 4 },
            new object[] { AtLeast.Times(4), 5 },

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

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

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

            new object[] { MoreThan.Once(), 2 },
            new object[] { MoreThan.Twice(), 3 },
            new object[] { MoreThan.Thrice(), 4 },
            new object[] { MoreThan.Times(4), 5 },
        };
            public void When_a_string_is_matched_and_the_count_of_matches_fits_into_the_expected_it_passes()
            {
                // Arrange
                string subject = "hello world";

                // Act
                Action act = () => subject.Should().MatchRegex(new Regex("hello.*"), AtLeast.Once());

                // Assert
                act.Should().NotThrow();
            }
                public void When_string_containment_at_least_once_is_asserted_and_actual_value_is_null_then_it_should_throw()
                {
                    // Arrange
                    string actual            = null;
                    string expectedSubstring = "XYZ";

                    // Act
                    Action act = () => actual.Should().Contain(expectedSubstring, AtLeast.Once());

                    // Assert
                    act.Should().Throw <XunitException>()
                    .WithMessage("Expected * <null> to contain \"XYZ\" at least 1 time, but found it 0 times.");
                }
                public void When_string_containment_at_least_once_is_asserted_and_actual_value_does_not_contain_the_expected_string_it_should_throw_earlier()
                {
                    // Arrange
                    string actual            = "ABCDEF";
                    string expectedSubstring = "XYS";

                    // Act
                    Action act = () => actual.Should().Contain(expectedSubstring, AtLeast.Once());

                    // Assert
                    act.Should().Throw <XunitException>()
                    .WithMessage("Expected * \"ABCDEF\" to contain \"XYS\" at least 1 time, but found it 0 times.");
                }
            public void When_the_subject_is_empty_and_expected_count_is_more_than_zero_it_fails()
            {
                // Arrange
                string subject = string.Empty;

                // Act
                Action act = () =>
                {
                    using var _ = new AssertionScope();
                    subject.Should().MatchRegex(".+", AtLeast.Once());
                };

                // Assert
                act.Should().Throw <XunitException>()
                .WithMessage($"Expected subject*to match regex* at least 1 time, but found it 0 times*");
            }
Beispiel #6
0
        public void OrderByExcept([DataSources(TestProvName.AllSybase, TestProvName.AllSqlServer)] string context)
        {
            using (var db = GetDataContext(context))
            {
                var persons = db.Person
                              .OrderBy(c => c.LastName);

                var concat = persons
                             .Except(persons);

                var sql = concat.ToString();

                sql.Should().Contain("ORDER", AtLeast.Once());

                Assert.DoesNotThrow(() =>
                {
                    concat.ToList();
                });
            }
        }