示例#1
0
        public void ResolveIsNotAvailableForPartialVariablesTest([Values("#", "+", "")] string exprOp)
        {
            var template = new UriTemplate("{" + exprOp + "param1,param2}");

            Assert.Throws <UriTemplateException>(() => template.GetResolver().Bind("param1", "test").ResolveTemplate());
            Assert.Throws <UriTemplateException>(() => template.GetResolver().Bind("param2", "test").ResolveTemplate());
        }
示例#2
0
        public void PartialResolveMultipleContinuationsTest()
        {
            UriTemplate partialTemplate;
            var         template = new UriTemplate("{&name1,name2,name3}");

            partialTemplate = template.GetResolver().Bind("name1", "value").ResolveTemplate();
            Assert.AreEqual("&name1=value{&name2,name3}", partialTemplate.ToString());

            partialTemplate = template.GetResolver().Bind("name2", "value").ResolveTemplate();
            Assert.AreEqual("{&name1}&name2=value{&name3}", partialTemplate.ToString());

            partialTemplate = template.GetResolver().Bind("name3", "value").ResolveTemplate();
            Assert.AreEqual("{&name1,name2}&name3=value", partialTemplate.ToString());
        }
示例#3
0
        public void PartialResolveMultiplePathsTest()
        {
            UriTemplate partialTemplate;
            var         template = new UriTemplate("{/path1,path2,path3}");

            partialTemplate = template.GetResolver().Bind("path1", "value").ResolveTemplate();
            Assert.AreEqual("/value{/path2,path3}", partialTemplate.ToString());

            partialTemplate = template.GetResolver().Bind("path2", "value").ResolveTemplate();
            Assert.AreEqual("{/path1}/value{/path3}", partialTemplate.ToString());

            partialTemplate = template.GetResolver().Bind("path3", "value").ResolveTemplate();
            Assert.AreEqual("{/path1,path2}/value", partialTemplate.ToString());
        }
示例#4
0
        public void PartialResolveNothingTest([Values("#", "+", "")] string exprOp)
        {
            var template        = new UriTemplate("{" + exprOp + "param1,param2}");
            var partialTemplate = template.GetResolver().Bind("unknown", "1").ResolveTemplate();

            Assert.AreEqual(template.ToString(), partialTemplate.ToString());
        }
示例#5
0
        public void PartialResolveSimpleTest()
        {
            var template = new UriTemplate("{host}{/path}{?query}{#fragment}");

            template = template.GetResolver().Bind("host", "example.com").ResolveTemplate();
            Assert.AreEqual("example.com{/path}{?query}{#fragment}", template.ToString());

            template = template.GetResolver().Bind("path", "path").ResolveTemplate();
            Assert.AreEqual("example.com/path{?query}{#fragment}", template.ToString());

            template = template.GetResolver().Bind("query", "value").ResolveTemplate();
            Assert.AreEqual("example.com/path?query=value{#fragment}", template.ToString());

            template = template.GetResolver().Bind("fragment", "fragment").ResolveTemplate();
            Assert.AreEqual("example.com/path?query=value#fragment", template.ToString());
        }
示例#6
0
        public void PartialResolveMultipleQueryWithReorderingTest()
        {
            var template = new UriTemplate("{?param1,param2}");
            var actual   = template.GetResolver().Bind("param2", "test").ResolveTemplate().ToString();

            Assert.AreEqual("?param2=test{&param1}", actual);
        }
示例#7
0
        public void PartialResolveAllVariablesTest([Values("#", "+", "")] string exprOp)
        {
            var template        = new UriTemplate("{" + exprOp + "param1,param2}");
            var partialTemplate = template.GetResolver().Bind("param1", "param1").Bind("param2", "param2").ResolveTemplate();
            var expected        = (exprOp == "+" ? string.Empty : exprOp) + "param1,param2";

            Assert.AreEqual(expected, partialTemplate.ToString());
        }
示例#8
0
        public void AnotherExampleTest()
        {
            var template = new UriTemplate("http://example.org/{area}/last-news{?type}");

            var uri = template.GetResolver()
                      .Bind("area", "world")
                      .Bind("type", new string[] { "it", "music", "art" })
                      .Resolve();

            Assert.AreEqual("http://example.org/world/last-news?type=it,music,art", uri);
        }