Esempio n. 1
0
    public void StringMatchesRegexPattern()
    {
        string pattern     = "....";
        string actualValue = "xxx";

        // MSTest does not support this case.

        // NUnit
        Assert.That(actualValue, Does.Match(pattern), () => "Some context");
        // Some context
        //  Expected: String matching "...."
        //  But was: "xxx"

        // XUnit
        XUnitAssert.Matches(pattern, actualValue);
        // Assert.Matches() Failure
        // Regex: ....
        // Value: xxx

        // Fluent
        actualValue.Should().MatchRegex(pattern, "SOME REASONS");
        // Expected actualValue to match regex "...." because SOME REASONS, but "xxx" does not match.

        // Shouldly
        actualValue.ShouldMatch(pattern, "Some context");
        // actualValue
        //   should match
        // "...."
        //   but was
        // "xxx"
        //
        // Additional Info:
        //  Some context
    }
Esempio n. 2
0
        public void Assertions()
        {
            var condition = false;
            var text      = "something";
            var obj       = new Auto();
            var tokens    = new List <string> {
                "public", "void", "return"
            };
            var zero           = 8 - 8;
            var someEnumerable = new List <string>();

            Assert.False(condition);
            Assert.Equal("something", text);
            Assert.NotEqual("something else", text);
            Assert.Contains("tech", "technology"); // also DoesNotContain
            Assert.Matches(".*thing$", "something");
            Assert.Throws <DivideByZeroException>(() => 4 / zero);
            Assert.Empty(someEnumerable); // also NotEmpty
            Assert.IsType <Auto>(obj);
            Assert.Collection(new List <int> {
                2, 4
            },
                              n => Assert.Equal(2, n),
                              n => Assert.Equal(4, n)
                              );
            Assert.All(new List <string> {
                "a", "ab", "abc"
            },
                       s => s.StartsWith("a"));
        }
        public void IsValidEmail()
        {
            var email        = "*****@*****.**";
            var emailPattern = @"^[^@\s]+@[^@\s]+\.[^@\s]+$";

            Assert.Matches(emailPattern, email);
        }
Esempio n. 4
0
    public void StringMatchesRegexObject()
    {
        Regex  pattern     = new Regex("....");
        string actualValue = "xxx";

        // MSTest
        MSTestStringAssert.Matches(actualValue, pattern, "Some context");
        // StringAssert.Matches failed. String 'xxx' does not match pattern '....'. Some context.

        // NUnit does not support this case.

        // XUnit
        XUnitAssert.Matches(pattern, actualValue);
        // Assert.Matches() Failure
        // Regex: ....
        // Value: xxx

        // Fluent does not support this case.

        // Shouldly does not support this case.
    }
Esempio n. 5
0
        public void SignalAddressRegExp_ShouldMatch(string input)
        {
            var regex = new Regex(Constants.SignalAddressRegExp, RegexOptions.IgnoreCase);

            Assert.Matches(regex, input);
        }