Beispiel #1
0
        public void FromPattern()
        {
            Assert.AreEqual("http://example.com/", UriUtility.FromPattern("http://example.com").AbsoluteUri);

            Assert.AreEqual("http://example.com/%7Bx%7D", UriUtility.FromPattern("http://example.com/{x}").AbsoluteUri);
            Assert.AreEqual("http://example.com/r%26d", UriUtility.FromPattern("http://example.com/{x}", "x", "r&d").AbsoluteUri);
            Assert.AreEqual("http://example.com/r%26d?y=pb%26j", UriUtility.FromPattern("http://example.com/{x}", "x", "r&d", "y", "pb&j").AbsoluteUri);
            Assert.AreEqual("http://example.com/r%26d?y=pb%26j", UriUtility.FromPattern("http://example.com/{x}", "y", "pb&j", "x", "r&d").AbsoluteUri);

            Assert.AreEqual("http://example.com/%7Bx%7D?a=%7By%7D", UriUtility.FromPattern("http://example.com/{x}?a={y}").AbsoluteUri);
            Assert.AreEqual("http://example.com/r%26d?a=pb%26j", UriUtility.FromPattern("http://example.com/{x}?a={y}", "x", "r&d", "y", "pb&j").AbsoluteUri);
            Assert.AreEqual("http://example.com/r%26d?a=pb%26j", UriUtility.FromPattern("http://example.com/{x}?a={y}", "y", "pb&j", "x", "r&d").AbsoluteUri);
            Assert.AreEqual("http://example.com/r%26d?a=pb%26j&z=zed", UriUtility.FromPattern("http://example.com/{x}?a={y}", "y", "pb&j", "z", "zed", "x", "r&d").AbsoluteUri);
        }
        private Uri DoGetRequestUri(string relativeUriPattern, params string[] parameters)
        {
            string uriText = m_baseUri.AbsoluteUri;

            if (!string.IsNullOrEmpty(relativeUriPattern))
            {
                uriText = uriText.TrimEnd('/') + "/" + relativeUriPattern.TrimStart('/');
            }

            Uri uri = parameters != null && parameters.Length > 0 ? UriUtility.FromPattern(uriText, parameters) : new Uri(uriText);

            OnGetRequestUri(ref uri);

            return(uri);
        }
        private Uri DoGetRequestUri(string relativeUriPattern, IEnumerable <KeyValuePair <string, object> > uriParameters)
        {
            string uriText = m_baseUri.AbsoluteUri;

            if (!string.IsNullOrEmpty(relativeUriPattern))
            {
                uriText = uriText.TrimEnd('/') + "/" + relativeUriPattern.TrimStart('/');
            }

            Uri uri = uriParameters != null?UriUtility.FromPattern(uriText, uriParameters) : new Uri(uriText);

            OnGetRequestUri(ref uri);

            return(uri);
        }
Beispiel #4
0
        public void FromPatternKeyValuePairs()
        {
            var parameters = new SortedDictionary <string, object>()
            {
                ["x"] = "r&d",
                ["y"] = "pb&j",
                ["z"] = "zed",
                ["a"] = true,
                ["b"] = 0,
                ["c"] = TimeSpan.Zero,
                ["d"] = null,
            };

            Assert.AreEqual("http://example.com/r%26d?y=pb%26j&a=true&b=0&c=00%3A00%3A00&z=zed", UriUtility.FromPattern("http://example.com/{x}?y={y}", parameters).AbsoluteUri);
        }