コード例 #1
0
            public void returns_matches_with_parameterized_keys()
            {
                var pattern  = "/api/{resource:maxlength(20)}/{id:num}";
                var sample   = "/api/users/1234";
                var template = new RouteTemplate(pattern);

                template.Matches(sample).ShouldBeTrue();
                var matches = template.ParseEndpoint(sample);

                matches.Count.ShouldBe(2);
                matches.ContainsKey("resource").ShouldBeTrue();
                matches.ContainsKey("id").ShouldBeTrue();
                matches["resource"].ShouldBe("users");
                matches["id"].ShouldBe("1234");
            }
コード例 #2
0
            public void returns_matches_with_generic_keys()
            {
                var pattern  = @"^/api/([a-zA-Z]+)/(\d+)";
                var sample   = "/api/users/1234";
                var template = new RouteTemplate(pattern);

                template.Matches(sample).ShouldBeTrue();
                var matches = template.ParseEndpoint(sample);

                matches.Count.ShouldBe(2);
                matches.ContainsKey("p0").ShouldBeTrue();
                matches.ContainsKey("p1").ShouldBeTrue();
                matches["p0"].ShouldBe("users");
                matches["p1"].ShouldBe("1234");
            }
コード例 #3
0
            public void returns_matches_with_provided_keys()
            {
                var pattern    = new Regex(@"(?i)^/api/([^/]{1,20})/(\d+)$");
                var patterKeys = new List <string>()
                {
                    "resource",
                    "id"
                };
                var sample   = "/api/users/1234";
                var template = new RouteTemplate(pattern, patterKeys);

                template.Matches(sample).ShouldBeTrue();
                var matches = template.ParseEndpoint(sample);

                matches.Count.ShouldBe(2);
                matches.ContainsKey("resource").ShouldBeTrue();
                matches.ContainsKey("id").ShouldBeTrue();
                matches["resource"].ShouldBe("users");
                matches["id"].ShouldBe("1234");
            }