Exemplo n.º 1
0
            public void returns_regex_with_no_capture_groups_when_no_constraints_are_included()
            {
                var pattern     = "/api/resource/id";
                var expected    = $"(?i)^{pattern}$";
                var patternKeys = new List <string>();

                var regex = RouteTemplate.ConvertToRegex(pattern, out patternKeys);

                regex.ToString().ShouldBe(expected);
                patternKeys.Count.ShouldBe(0);
                regex.IsMatch(pattern).ShouldBeTrue();
            }
Exemplo n.º 2
0
            public void returns_regex_from_string_when_string_begins_with_caret()
            {
                var pattern     = @"^/api/([a-zA-Z]+)/(\d+)";
                var sample      = "/api/users/1234";
                var patternKeys = new List <string>();

                var regex = RouteTemplate.ConvertToRegex(pattern, out patternKeys);

                regex.ToString().ShouldBe(pattern);
                patternKeys.Count.ShouldBe(0);
                regex.IsMatch(sample).ShouldBeTrue();
            }
Exemplo n.º 3
0
            public void returns_regex_with_default_capture_groups_when_using_generic_contraints()
            {
                var pattern     = "/api/{resource}/{id}";
                var expected    = @"(?i)^/api/([^/]+)/([^/]+)$";
                var sample      = "/api/thing1/thing2";
                var patternKeys = new List <string>();

                var regex = RouteTemplate.ConvertToRegex(pattern, out patternKeys);

                regex.ToString().ShouldBe(expected);
                patternKeys.Count.ShouldBe(2);
                patternKeys[0].ShouldBe("resource");
                patternKeys[1].ShouldBe("id");
                regex.IsMatch(sample).ShouldBeTrue();
            }
Exemplo n.º 4
0
            public void returns_regex_with_capture_group_based_on_constraints()
            {
                var pattern     = "/api/{resource:maxlength(20)}/{id:num}";
                var expected    = @"(?i)^/api/([^/]{1,20})/(\d+)$";
                var sample      = "/api/users/1234";
                var patternKeys = new List <string>();

                var regex = RouteTemplate.ConvertToRegex(pattern, out patternKeys);

                regex.ToString().ShouldBe(expected);
                patternKeys.Count.ShouldBe(2);
                patternKeys[0].ShouldBe("resource");
                patternKeys[1].ShouldBe("id");
                regex.IsMatch(sample).ShouldBeTrue();
            }