コード例 #1
0
 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);
 }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
        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");
        }
コード例 #4
0
            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);
            }
コード例 #5
0
        public void does_not_parse_pattern_params_with_regex()
        {
            var pattern = @"^\/path\/(\d+)\/(.+)$";

            PatternParser.GeneratePatternKeys(pattern).Count.ShouldBe(0);
        }
コード例 #6
0
 public void ThrowsExceptionWhenPathInfoHasDuplicateKeys()
 {
     Should.Throw <ArgumentException>(() => PatternParser.GeneratePatternKeys("/[part]/[part]"));
 }
コード例 #7
0
 public void ReturnsEmptyDictionaryWhenPathInfoIsNull()
 {
     PatternParser.GeneratePatternKeys(null).ShouldBeEmpty();
 }
コード例 #8
0
 public void DoesNotParsePatternParamsWithRegularExpressions()
 {
     PatternParser.GeneratePatternKeys(@"^\/path\/(\d+)\/(.+)$").Count.ShouldBe(0);
 }
コード例 #9
0
 public void parser_throws_error_when_pathinfo_has_duplicate_keys()
 {
     Should.Throw <ArgumentException>(() => PatternParser.GeneratePatternKeys("/[part]/[part]"));
 }
コード例 #10
0
 public void parser_returns_empty_dictionary_when_pathinfo_in_null()
 {
     PatternParser.GeneratePatternKeys(null).ShouldBeEmpty();
 }