public void IsValidEmail() { var email = "*****@*****.**"; var emailRegex = new Regex(@"^[^@\s]+@[^@\s]+\.[^@\s]+$"); StringAssert.Matches(email, emailRegex); }
public static ValueChecker <string> Matches([NotNull] this ValueChecker <string> Checker, [NotNull] Regex ExpectedRegEx, string Message = null) { StringAssert.Matches(Checker.ActualValue, ExpectedRegEx, "{0}Указанная строка {1} не соответствует ожидаемому регулярному выражению {2}", Message.AddSeparator(), Checker.ActualValue, ExpectedRegEx); return(Checker); }
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. }
/// <summary> /// Tests whether the specified string matches a regular expression and /// throws an exception if the string does not match the expression. /// </summary> /// <param name="value"> /// The string that is expected to match <paramref name="pattern"/>. /// </param> /// <param name="pattern"> /// The regular expression that <paramref name="value"/> is /// expected to match. /// </param> /// <param name="message"> /// The message to include in the exception when <paramref name="value"/> /// does not match <paramref name="pattern"/>. The message is shown in /// test results. /// </param> /// <exception cref="AssertFailedException"> /// Thrown if <paramref name="value"/> does not match /// <paramref name="pattern"/>. /// </exception> public static void Matches(string value, Regex pattern, string message) { StringAssert.Matches(value, pattern, message, null); }
/// <summary> /// Tests whether the specified string matches a regular expression and /// throws an exception if the string does not match the expression. /// </summary> /// <param name="value"> /// The string that is expected to match <paramref name="pattern"/>. /// </param> /// <param name="pattern"> /// The regular expression that <paramref name="value"/> is /// expected to match. /// </param> /// <exception cref="AssertFailedException"> /// Thrown if <paramref name="value"/> does not match /// <paramref name="pattern"/>. /// </exception> public static void Matches(string value, Regex pattern) { StringAssert.Matches(value, pattern, string.Empty, null); }