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_params_to_list() { var pattern = "/path/[param1]/[param2]"; var parsed = PatternParser.GeneratePatternKeys(pattern); parsed.Count.ShouldBe(2); parsed[0].ShouldBe("param1"); parsed[1].ShouldBe("param2"); }
public void ReturnsListOfKeysFoundInPathInfoPattern() { const string param1 = "api"; const string param2 = "user"; var pattern = $"/[{param1}]/[{param2}]"; var parsed = PatternParser.GeneratePatternKeys(pattern); parsed.Count.ShouldBe(2); parsed[0].ShouldBe(param1); parsed[1].ShouldBe(param2); }
public void does_not_parse_pattern_params_with_regex() { var pattern = @"^\/path\/(\d+)\/(.+)$"; PatternParser.GeneratePatternKeys(pattern).Count.ShouldBe(0); }
public void ThrowsExceptionWhenPathInfoHasDuplicateKeys() { Should.Throw <ArgumentException>(() => PatternParser.GeneratePatternKeys("/[part]/[part]")); }
public void ReturnsEmptyDictionaryWhenPathInfoIsNull() { PatternParser.GeneratePatternKeys(null).ShouldBeEmpty(); }
public void DoesNotParsePatternParamsWithRegularExpressions() { PatternParser.GeneratePatternKeys(@"^\/path\/(\d+)\/(.+)$").Count.ShouldBe(0); }
public void parser_throws_error_when_pathinfo_has_duplicate_keys() { Should.Throw <ArgumentException>(() => PatternParser.GeneratePatternKeys("/[part]/[part]")); }
public void parser_returns_empty_dictionary_when_pathinfo_in_null() { PatternParser.GeneratePatternKeys(null).ShouldBeEmpty(); }