public void When_validating_invalid_emails() { var helper = new RegexHelper(); helper.IsValidEmail("*****@*****.**").ShouldBeFalse(); helper.IsValidEmail("*****@*****.**").ShouldBeFalse(); helper.IsValidEmail("js*@proseware.com").ShouldBeFalse(); helper.IsValidEmail("*****@*****.**").ShouldBeFalse(); helper.IsValidEmail("*****@*****.**").ShouldBeFalse(); }
public void When_converting_input_to_case_incensitive_regex_pattern() { const string SampleInput = "this is some STUFF fOo-bar"; const string Argument = "foo-bAr"; var caseIncensitiveArgument = RegexHelper.ToCaseInsensitiveRegexPattern(Argument); caseIncensitiveArgument.ShouldBe("[fF][oO][oO]-[bB][aA][rR]"); Regex.IsMatch(SampleInput, Argument).ShouldBeFalse(); Regex.IsMatch(SampleInput, caseIncensitiveArgument).ShouldBeTrue(); new [] { "aNt", "A-", "a|", "A", "a" } .ShouldAllBe(x => Regex.IsMatch(x, RegexHelper.ToCaseInsensitiveRegexPattern("A.*"))); RegexHelper.ToCaseInsensitiveRegexPattern(null).ShouldBeNull(); RegexHelper.ToCaseInsensitiveRegexPattern(string.Empty).ShouldBe(string.Empty); RegexHelper.ToCaseInsensitiveRegexPattern(" ").ShouldBe(" "); RegexHelper.ToCaseInsensitiveRegexPattern("a").ShouldBe("[aA]"); RegexHelper.ToCaseInsensitiveRegexPattern("ab").ShouldBe("[aA][bB]"); RegexHelper.ToCaseInsensitiveRegexPattern("aB").ShouldBe("[aA][bB]"); RegexHelper.ToCaseInsensitiveRegexPattern("ab\\S").ShouldBe("[aA][bB]\\S"); RegexHelper.ToCaseInsensitiveRegexPattern("ab\\SS").ShouldBe("[aA][bB]\\S[sS]"); RegexHelper.ToCaseInsensitiveRegexPattern("ab\\Ss").ShouldBe("[aA][bB]\\S[sS]"); RegexHelper.ToCaseInsensitiveRegexPattern("ab\\m").ShouldBe("[aA][bB]\\[mM]"); RegexHelper.ToCaseInsensitiveRegexPattern("\\D").ShouldBe("\\D"); RegexHelper.ToCaseInsensitiveRegexPattern("\\DX\\Q").ShouldBe("\\D[xX]\\[qQ]"); RegexHelper.ToCaseInsensitiveRegexPattern("(?<name>ab\\SX)") .ShouldBe("(?<name>[aA][bB]\\S[xX])"); RegexHelper.ToCaseInsensitiveRegexPattern("(?<name>ab\\SX)(?<foo>A)") .ShouldBe("(?<name>[aA][bB]\\S[xX])(?<foo>[aA])"); RegexHelper.ToCaseInsensitiveRegexPattern("(?<name>ab\\SX)(<foo>A)") .ShouldBe("(?<name>[aA][bB]\\S[xX])(<[fF][oO][oO]>[aA])"); RegexHelper.ToCaseInsensitiveRegexPattern("(?<name>ab\\SX)(?<fooA)") .ShouldBe("(?<name>[aA][bB]\\S[xX])(?<[fF][oO][oO][aA])"); }
public void When_validating_valid_emails() { var helper = new RegexHelper(); helper.IsValidEmail("*****@*****.**").ShouldBeTrue(); helper.IsValidEmail("*****@*****.**").ShouldBeTrue(); helper.IsValidEmail("*****@*****.**").ShouldBeTrue(); helper.IsValidEmail("[email protected]").ShouldBeTrue(); helper.IsValidEmail("js#[email protected]").ShouldBeTrue(); helper.IsValidEmail("j_9@[129.126.118.1]").ShouldBeTrue(); helper.IsValidEmail("[email protected]").ShouldBeTrue(); helper.IsValidEmail("*****@*****.**").ShouldBeTrue(); helper.IsValidEmail("\"j\\\"s\\\"\"@proseware.com").ShouldBeTrue(); helper.IsValidEmail("js@contoso.中国").ShouldBeTrue(); helper.IsValidEmail("*****@*****.**").ShouldBeTrue(); /* * This is a valid email address but is being rejected. * See: https://github.com/dotnet/docs/issues/5305 */ // [ToDo] - helper.IsValidEmail("#[email protected]").ShouldBeTrue(); }