private Route(HttpMethod httpMethod, string pathInfo) { HttpMethod = httpMethod; PathInfo = (pathInfo != null) ? (!string.IsNullOrWhiteSpace(pathInfo)) ? pathInfo : string.Empty : string.Empty; PatternKeys = PatternParser.GeneratePatternKeys(PathInfo); PathInfoPattern = PatternParser.GenerateRegEx(PathInfo); }
/// <summary> /// Base constructor for a route /// </summary> /// <param name="httpMethod"></param> /// <param name="pathInfo"></param> private Route(HttpMethod httpMethod, string pathInfo) { Enabled = true; HttpMethod = httpMethod; PathInfo = !string.IsNullOrWhiteSpace(pathInfo) ? pathInfo : string.Empty; PatternKeys = PatternParser.GeneratePatternKeys(PathInfo); PathInfoPattern = PatternParser.GenerateRegEx(PathInfo); }
public void parses_pattern_to_regular_expression() { var pattern = "/path/[param1]/[param2]"; PatternParser.GenerateRegEx(pattern).ToString().ShouldBe(@"^/path/(.+)/(.+)$"); }
public void parses_null_to_default_expression() { PatternParser.GenerateRegEx(null).ToString().ShouldBe(@"^.*$"); }
public void parses_empty_string_to_default_expression() { PatternParser.GenerateRegEx("").ToString().ShouldBe(@"^.*$"); }
public void recognizes_pattern_as_regex() { var pattern = @"^\/path\/(\d+)\/(.+)$"; PatternParser.GenerateRegEx(pattern).ToString().ShouldBe(pattern); }
public void handles_regex_with_square_brackets() { var pattern = @"^\/path\/([0123456789]+)\/(.+)$"; PatternParser.GenerateRegEx(pattern).ToString().ShouldBe(pattern); }
public void ReturnsDefaultExpressionWhenParameterIsEmptyString() { PatternParser.GenerateRegEx(string.Empty).ToString().ShouldBe(@"^.*$"); }
public void ReturnedExressionEndsInSingleDollar() { PatternParser.GenerateRegEx(@"/path/info$").ToString().EndsWith("$").ShouldBeTrue(); PatternParser.GenerateRegEx(@"/path/info").ToString().EndsWith("$").ShouldBeTrue(); }
public void ReturnsDefaultExpressionWhenParameterIsNull() { PatternParser.GenerateRegEx(null).ToString().ShouldBe(@"^.*$"); }
public void IgnoresSquareBracketsInRegularExpressions() { const string pattern = @"^\/path\/([0123456789]+)\/(.+)$"; PatternParser.GenerateRegEx(pattern).ToString().ShouldBe(pattern); }
public void ReturnsSameExpressionWhenPathInfoPatternIsRegularExpression() { const string pattern = @"^\/path\/(\d+)\/(.+)$"; PatternParser.GenerateRegEx(pattern).ToString().ShouldBe(pattern); }
public void ReturnsRegularExpressionFromPathInfoPattern() { PatternParser.GenerateRegEx("/path/[param1]/[param2]").ToString().ShouldBe(@"^/path/(.+)/(.+)$"); }
public void pattern_ends_with_dollar_sign_only_if_path_info_does() { PatternParser.GenerateRegEx(@"/path/info$").ToString().EndsWith("$").ShouldBeTrue(); }