コード例 #1
0
 public IRestRequest WithUriTemplate(string uriTemplate)
 {
     uriTemplate      = UriTemplateHelper.AppendUriTemplateSuffix(this.uriTemplatePrefix + uriTemplate, this.uriTemplateSuffix);
     this.uriTemplate = UriTemplate.For(uriTemplate, false)
                        .WithValueFormatter(this.valueFormatter);
     return(this);
 }
コード例 #2
0
        private static void SpecTestCaseTests(SpecTestCase testCase, bool isPartial)
        {
            var uriTemplate = UriTemplate.For(testCase.Template);

            foreach (var variable in testCase.Variables)
            {
                uriTemplate.WithParameter(variable.Key, variable.Value);
            }

            switch (testCase)
            {
            case SpecFailTestCase x:
                ShouldFail(uriTemplate, isPartial);
                break;

            case SpecListTestCase x:
                ShouldMatchOne(uriTemplate, x, isPartial);
                break;

            case SpecStringTestCase x:
                ShouldMatch(uriTemplate, x, isPartial);
                break;

            default:
                break;
            }
        }
コード例 #3
0
        public void ShouldQueryObjectBeExpandedAsExpected(string expected, Options options, Filters filters)
        {
            var result = UriTemplate.For("/api{?options*,filters*}")
                         .WithParameter("options", options)
                         .WithParameter("filters", filters)
                         .ExpandToString();

            result.ShouldBeEquivalentTo(expected);
        }
コード例 #4
0
        public void Example06()
        {
            string uriString = UriTemplate.For("http://example.org/{area}/news{?type,count}")
                               .WithParameter("count", 10)
                               .WithPartialExpand()
                               .ExpandToString();

            uriString.ShouldBeEquivalentTo("http://example.org/{area}/news?count=10{&type}");
        }
コード例 #5
0
        public void Example05()
        {
            string uriString = UriTemplate.For("http://example.org/{resource}{?genre,count}")
                               .WithParameter("resource", "books")
                               .WithParameter("count", 10)
                               .ExpandToString();

            uriString.ShouldBeEquivalentTo("http://example.org/books?count=10");
        }
コード例 #6
0
        public void Example03()
        {
            string uriString = UriTemplate.For("http://example.org/{resource}{?genre*}")
                               .WithParameter("resource", "books")
                               .WithParameter("genre", "sci-fi", "horror", "fantasy")
                               .ExpandToString();

            uriString.ShouldBeEquivalentTo("http://example.org/books?genre=sci-fi&genre=horror&genre=fantasy");
        }
コード例 #7
0
        public void ShouldQueryObjectBeExpandedAsExpected()
        {
            Filters filters = new Filters
            {
                Year   = 1988,
                Genres = new[] { "action", "adventure" }
            };

            var result = UriTemplate.For("/api{?filters*}")
                         .WithParameter("filters", filters)
                         .ExpandToString();

            result.ShouldBeEquivalentTo("/api?year=1988&genres=action,adventure");
        }
コード例 #8
0
        public void ShouldHaveRightCases()
        {
            CustomQueryObject customQueryObject = new CustomQueryObject
            {
                KebabCase      = 1,
                LowerCamelCase = 2,
                MyOwnFormat    = 3
            };

            var result = UriTemplate.For("/api{?filters*}")
                         .WithParameter("filters", customQueryObject)
                         .ExpandToString();

            result.ShouldBeEquivalentTo("/api?kebab-case=1&lowerCamelCase=2&WithMyOwnKey=3");
        }
コード例 #9
0
        public void Example04()
        {
            Dictionary <string, string> options = new Dictionary <string, string>
            {
                ["genre"]  = "sci-fi",
                ["count"]  = "10",
                ["author"] = "George R. R. Martin",
            };

            string uriString = UriTemplate.For("http://example.org/{resource}{?options*}")
                               .WithParameter("resource", "books")
                               .WithParameter("options", options)
                               .ExpandToString();

            uriString.ShouldBeEquivalentTo("http://example.org/books?genre=sci-fi&count=10&author=George%20R.%20R.%20Martin");
        }
コード例 #10
0
        public void CascadingPartialExpandShouldBeCorrect(string template, string expected)
        {
            var uriTemplate = UriTemplate.For(template)
                              .WithPartialExpand();

            foreach (var key in Variables.Keys)
            {
                uriTemplate.WithParameter(key, Variables[key]);
                uriTemplate = UriTemplate.For(uriTemplate.ExpandToString()).WithPartialExpand();
            }

            var result = uriTemplate.WithPartialExpand(false)
                         .ExpandToString();

            result.ShouldBeEquivalentTo(expected);
        }
コード例 #11
0
        public void Example07()
        {
            Func <object, string> func = x =>
            {
                switch (x)
                {
                case Vector2 y:
                    return($"({y.X},{y.Y})");

                default:
                    return(x?.ToString());
                }
            };
            Vector2 u         = new Vector2(3, 4);
            string  uriString = UriTemplate.For("http://example.org{/vector}")
                                .WithParameter("vector", u)
                                .WithValueFormatter(func)
                                .ExpandToString();

            uriString.ShouldBeEquivalentTo("http://example.org/%283%2C4%29");
        }