コード例 #1
0
        public void AddsValueToUrl()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.AddQuery("name", "value");

            Assert.Equal("?name=value", builder.ToUri().Query);
        }
コード例 #2
0
        public void AddsMultipleValuesWithSameNameToUrl()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.AddQuery("name", "value1");
            builder.AddQuery("name", "value2");

            Assert.Equal("?name=value1&name=value2", builder.ToUri().Query);
        }
コード例 #3
0
        public async Task <SearchResults <T> > SearchAsync <T>(string query, SearchOptions opts = null)
        {
            Guard.ArgumentNotNullOrEmpty("query", query);

            HttpUrlBuilder uri = new HttpUrlBuilder(host)
                                 .AppendPath(CollectionName)
                                 .AddQuery("query", query);

            if (opts != null)
            {
                if (!String.IsNullOrEmpty(opts.Sort))
                {
                    uri.AddQuery("sort", opts.Sort);
                }

                uri.AddQuery("limit", opts.Limit.ToString());
                uri.AddQuery("offset", opts.Offset.ToString());
            }

            var response = await restClient.GetAsync <SearchResultsResponse <T> >(uri);

            return(response.ToResults(new Uri(host), restClient));
        }
コード例 #4
0
        public async Task <KvMetadata> UpdateAsync <T>(string key,
                                                       T item,
                                                       string reference = null)
        {
            Guard.ArgumentNotNullOrEmpty("key", key);
            Guard.ArgumentNotNull("item", item);

            try
            {
                await GetAsync <T>(key);
            }
            catch (NotFoundException exception)
            {
                throw exception;
            }

            HttpUrlBuilder uri = new HttpUrlBuilder(host)
                                 .AppendPath(CollectionName)
                                 .AppendPath(key);

            var response = await restClient.SendIfMatchAsync(uri, HttpMethod.Put, item, reference);

            return(KvMetadata.Make(CollectionName, response));
        }
コード例 #5
0
        public async Task <ListResults <T> > HistoryAsync <T>(string productKey, HistoryOptions opts = null)
        {
            Guard.ArgumentNotNullOrEmpty("key", productKey);

            HttpUrlBuilder uri = new HttpUrlBuilder(host)
                                 .AppendPath(CollectionName)
                                 .AppendPath(productKey)
                                 .AppendPath("refs");

            if (opts != null)
            {
                if (opts.Values == true)
                {
                    uri.AddQuery("values", "true");
                }

                uri.AddQuery("limit", opts.Limit.ToString());
                uri.AddQuery("offset", opts.Offset.ToString());
            }

            var response = await restClient.GetAsync <ListResultsResponse <T> >(uri);

            return(response.ToResults(new Uri(host), restClient));
        }
コード例 #6
0
        public void EncodesFragmentArguments()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.AppendFragment("foo/{0}", "bar#bar");

            Assert.Equal("#/foo/bar%23bar", builder.ToUri().Fragment);
        }
コード例 #7
0
        public void ConvertsToString()
        {
            var builder = new HttpUrlBuilder("http://localhost/api/foo");

            Assert.Equal("http://localhost/api/foo", builder.ToString());
        }
コード例 #8
0
        public void WhenInitialUrlHasQueryString_AppendsQueryToExisting()
        {
            var builder = new HttpUrlBuilder("http://localhost?name1=value1");

            builder.AddQuery("name2", "value2");

            Assert.Equal("?name1=value1&name2=value2", builder.ToUri().Query);
        }
コード例 #9
0
        public void EncodesName()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.AddQuery("na/me", "value");

            Assert.Equal("?na%2fme=value", builder.ToUri().Query);
        }
コード例 #10
0
        public void ConvertsAbsoluteToUri()
        {
            var builder = new HttpUrlBuilder("http://localhost/api/foo", UriKind.Absolute);

            Assert.Equal(new Uri("http://localhost/api/foo", UriKind.Absolute), builder.ToUri());
        }
コード例 #11
0
        public void AppendsFragmentToExisting(string url)
        {
            var builder = new HttpUrlBuilder(url);

            builder.AppendFragment("foo/bar");

            Assert.Equal("#/existing/path/foo/bar", builder.ToUri().Fragment);
        }
コード例 #12
0
        public void EncodesPath(string path, string expectedPath)
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.WithPath(path);

            Assert.Equal(expectedPath, builder.ToUri().AbsolutePath);
        }
コード例 #13
0
        public void ConvertsToUri()
        {
            var builder = new HttpUrlBuilder("http://localhost/api/foo");

            Assert.Equal(new Uri("http://localhost/api/foo"), builder.ToUri());
        }
コード例 #14
0
        public void ChangesHostName()
        {
            var builder = new HttpUrlBuilder("http://host1:1337/path");

            builder.WithHost("host2");

            Assert.Equal("http://host2:1337/path", builder.ToString());
        }
コード例 #15
0
        public void OverwritesExistingPath(string url)
        {
            var builder = new HttpUrlBuilder(url);

            builder.WithPath("foo/bar");

            Assert.Equal("/foo/bar", builder.ToUri().AbsolutePath);
        }
コード例 #16
0
        public void InitializesUrlFromAbsoluteUri()
        {
            var builder = new HttpUrlBuilder(new Uri("http://localhost/api/foo", UriKind.Absolute));

            Assert.Equal(new Uri("http://localhost/api/foo", UriKind.Absolute), builder.ToUri());
        }
コード例 #17
0
        public void FormatsFragment()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.AppendFragment("foo/{0}", "bar");

            Assert.Equal("#/foo/bar", builder.ToUri().Fragment);
        }
コード例 #18
0
        public void DoesNotEncodeThePathSeperator()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.AppendFragment("foo/bar");

            Assert.Equal("#/foo/bar", builder.ToUri().Fragment);
        }
コード例 #19
0
        public void ConvertsRelativeUrlToString()
        {
            var builder = new HttpUrlBuilder("/api/foo", UriKind.Relative);

            Assert.Equal("/api/foo", builder.ToString());
        }
コード例 #20
0
        public void EncodesPathArguments()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.WithPath("foo/{0}", "bar#bar");

            Assert.Equal("/foo/bar%23bar", builder.ToUri().AbsolutePath);
        }
コード例 #21
0
        public void ConvertsAbsoluteUrlToString()
        {
            var builder = new HttpUrlBuilder("http://localhost/api/foo", UriKind.Absolute);

            Assert.Equal("http://localhost/api/foo", builder.ToString());
        }
コード例 #22
0
        public void DoesNotEncodeThePathSeperator()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.WithPath("foo/bar");

            Assert.Equal("/foo/bar", builder.ToUri().AbsolutePath);
        }
コード例 #23
0
        public void ConvertsRelativeToUri()
        {
            var builder = new HttpUrlBuilder("/api/foo", UriKind.Relative);

            Assert.Equal(new Uri("/api/foo", UriKind.Relative), builder.ToUri());
        }
コード例 #24
0
        public void FormatsPath()
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.WithPath("foo/{0}", "bar");

            Assert.Equal("/foo/bar", builder.ToUri().AbsolutePath);
        }
コード例 #25
0
        public void InitializesUrlFromComponents()
        {
            var builder = new HttpUrlBuilder("localhost", port: 1234, scheme: "https");

            Assert.Equal(new Uri("https://localhost:1234"), builder.ToUri());
        }
コード例 #26
0
        public void WhenNoExistingFragment_SetsFragment(string url)
        {
            var builder = new HttpUrlBuilder(url);

            builder.AppendFragment("foo/bar");

            Assert.Equal("#/foo/bar", builder.ToUri().Fragment);
        }
コード例 #27
0
        public void WhenNoExistingPath_SetsAbsolutePath(string url)
        {
            var builder = new HttpUrlBuilder(url);

            builder.AppendPath("foo/bar");

            Assert.Equal("/foo/bar", builder.ToUri().AbsolutePath);
        }
コード例 #28
0
        public void AppendsPathToExisting(string url)
        {
            var builder = new HttpUrlBuilder(url);

            builder.AppendPath("foo/bar");

            Assert.Equal("/existing/path/foo/bar", builder.ToUri().AbsolutePath);
        }
コード例 #29
0
        public void InitializesUrlFromString()
        {
            var builder = new HttpUrlBuilder("http://localhost/api/foo");

            Assert.Equal(new Uri("http://localhost/api/foo"), builder.ToUri());
        }
コード例 #30
0
        public void ChangesScheme()
        {
            var builder = new HttpUrlBuilder("http://host1:1337/path");

            builder.WithScheme("https");

            Assert.Equal("https://host1:1337/path", builder.ToString());
        }
コード例 #31
0
        public void InitializesUrlFromRelativeUri()
        {
            var builder = new HttpUrlBuilder(new Uri("/api/foo", UriKind.Relative));

            Assert.Equal(new Uri("/api/foo", UriKind.Relative), builder.ToUri());
        }
コード例 #32
0
        public void EncodesFragment(string path, string expectedPath)
        {
            var builder = new HttpUrlBuilder("http://localhost");

            builder.AppendFragment(path);

            Assert.Equal(expectedPath, builder.ToUri().Fragment);
        }
コード例 #33
0
        public void ChangesPost()
        {
            var builder = new HttpUrlBuilder("http://host1:1337/path");

            builder.WithPort(2112);

            Assert.Equal("http://host1:2112/path", builder.ToString());
        }
コード例 #34
0
        public Task PingAsync()
        {
            HttpUrlBuilder uri = new HttpUrlBuilder(application.HostUrl);

            return(restClient.SendAsync(uri, HttpMethod.Head));
        }