コード例 #1
0
 public void out_of_two_templates_with_one_query_parameter_only_the_correct_one_is_used()
 {
     var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List<KeyValuePair<OpenRasta.UriTemplate, object>>
     {
         new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}"), null),
         new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query2={queryText}"), null)
     });
     Collection<OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1?query=testing a query"));
     match.Count.ShouldBe(1);
     match[0].QueryParameters["queryText"].ShouldBe("testing a query");
 }
コード例 #2
0
        public void a_template_with_no_params_is_the_best_match_for_a_uri_with_no_params()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List <KeyValuePair <OpenRasta.UriTemplate, object> >
            {
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}&query2={queryiestText}"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}"), null)
            });
            Collection <OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1"));

            match.Count.ShouldBe(3);
            match[0].PathSegmentVariables.Count.ShouldBe(0);
            match[0].PathSegmentVariables.Count.ShouldBe(0);
        }
コード例 #3
0
        public void out_of_two_templates_with_one_query_parameter_only_the_correct_one_is_listed_first()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List <KeyValuePair <OpenRasta.UriTemplate, object> >
            {
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query2={queryText}"), null)
            });
            Collection <OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1?query=testing a query"));

            match.Count.ShouldBe(2);
            match[0].QueryStringVariables.Count.ShouldBe(1);
            match[1].QueryStringVariables.Count.ShouldBe(0);
            match[0].QueryStringVariables["queryText"].ShouldBe("testing a query");
        }
コード例 #4
0
        public void a_template_with_no_params_is_the_best_match_for_a_uri_with_no_params()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List<KeyValuePair<OpenRasta.UriTemplate, object>>
            {
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}&query2={queryiestText}"), null),
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1"), null),
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}"), null)
            });
            Collection<OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1"));

            match.Count.ShouldBe(3);
            match[0].PathSegmentVariables.Count.ShouldBe(0);
            match[0].PathSegmentVariables.Count.ShouldBe(0);
        }
コード例 #5
0
        public void equidistant_matches_are_ordered_by_bound_params()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List <KeyValuePair <OpenRasta.UriTemplate, object> >
            {
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1/{resourceId}"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1/{resourceId}?query={queryText}&query2={queryiestText}"), null),
            });

            Collection <OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1/123?query=ceci_nest_pas_un_value"));

            match.Count.ShouldBe(2);
            match.First().QueryStringVariables.Count.ShouldBe(1);
            match.First().PathSegmentVariables.Count.ShouldBe(1);
            match.First().QueryParameters.Count.ShouldBe(2);
        }
コード例 #6
0
        public void a_template_with_one_param_is_the_best_match_for_a_uri_with_one_param()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List <KeyValuePair <OpenRasta.UriTemplate, object> >
            {
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}&query2={queryiestText}"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={quasiText}"), null)
            });
            Collection <OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1?query=ceci_nest_pas_un_value"));

            match.Count.ShouldBe(3);
            match[0].QueryStringVariables.Count.ShouldBe(1);
            match[0].QueryParameters.Count.ShouldBe(1);
            match[0].QueryStringVariables["quasiText"].ShouldBe("ceci_nest_pas_un_value");
        }
コード例 #7
0
        public void a_template_with_one_param_is_the_best_match_for_a_uri_with_one_param()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List<KeyValuePair<OpenRasta.UriTemplate, object>>
            {
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}&query2={queryiestText}"), null),
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1"), null),
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={quasiText}"), null)
            });
            Collection<OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1?query=ceci_nest_pas_un_value"));

            match.Count.ShouldBe(3);
            match[0].QueryStringVariables.Count.ShouldBe(1);
            match[0].QueryParameters.Count.ShouldBe(1);
            match[0].QueryStringVariables["quasiText"].ShouldBe("ceci_nest_pas_un_value");
        }
コード例 #8
0
        public void irrelevant_params_do_not_affect_the_ordering()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List <KeyValuePair <OpenRasta.UriTemplate, object> >
            {
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}&query2={queryiestText}"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}&query3={queryiestText}"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1"), null),
                new KeyValuePair <OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={quasiText}"), null)
            });
            Collection <OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1?query=ceci_nest_pas_un_value&irrelevant=value"));

            match.Count.ShouldBe(4);
            match[0].QueryStringVariables.Count.ShouldBe(1);
            match[0].QueryParameters.Count.ShouldBe(1);
            match[0].QueryStringVariables["quasiText"].ShouldBe("ceci_nest_pas_un_value");
        }
コード例 #9
0
        public void irrelevant_params_do_not_affect_the_ordering()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List<KeyValuePair<OpenRasta.UriTemplate, object>>
            {
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}&query2={queryiestText}"), null),
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={queryText}&query3={queryiestText}"), null),
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1"), null),
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1?query={quasiText}"), null)
            });
            Collection<OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1?query=ceci_nest_pas_un_value&irrelevant=value"));

            match.Count.ShouldBe(4);
            match[0].QueryStringVariables.Count.ShouldBe(1);
            match[0].QueryParameters.Count.ShouldBe(1);
            match[0].QueryStringVariables["quasiText"].ShouldBe("ceci_nest_pas_un_value");
        }
コード例 #10
0
        public void equidistant_matches_are_ordered_by_bound_params()
        {
            var table = new OpenRasta.UriTemplateTable(new Uri("http://localhost"), new List<KeyValuePair<OpenRasta.UriTemplate, object>>
            {
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1/{resourceId}"), null),
                new KeyValuePair<OpenRasta.UriTemplate, object>(new OpenRasta.UriTemplate("resource1/{resourceId}?query={queryText}&query2={queryiestText}"), null),
            });

            Collection<OpenRasta.UriTemplateMatch> match = table.Match(new Uri("http://localhost/resource1/123?query=ceci_nest_pas_un_value"));
            
            match.Count.ShouldBe(2);
            match.First().QueryStringVariables.Count.ShouldBe(1);
            match.First().PathSegmentVariables.Count.ShouldBe(1);
            match.First().QueryParameters.Count.ShouldBe(2);
        }