public void AddsValueToUrl() { var builder = new HttpUrlBuilder("http://localhost"); builder.AddQuery("name", "value"); Assert.Equal("?name=value", builder.ToUri().Query); }
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); }
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)); }
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)); }
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)); }
public void EncodesFragmentArguments() { var builder = new HttpUrlBuilder("http://localhost"); builder.AppendFragment("foo/{0}", "bar#bar"); Assert.Equal("#/foo/bar%23bar", builder.ToUri().Fragment); }
public void ConvertsToString() { var builder = new HttpUrlBuilder("http://localhost/api/foo"); Assert.Equal("http://localhost/api/foo", builder.ToString()); }
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); }
public void EncodesName() { var builder = new HttpUrlBuilder("http://localhost"); builder.AddQuery("na/me", "value"); Assert.Equal("?na%2fme=value", builder.ToUri().Query); }
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()); }
public void AppendsFragmentToExisting(string url) { var builder = new HttpUrlBuilder(url); builder.AppendFragment("foo/bar"); Assert.Equal("#/existing/path/foo/bar", builder.ToUri().Fragment); }
public void EncodesPath(string path, string expectedPath) { var builder = new HttpUrlBuilder("http://localhost"); builder.WithPath(path); Assert.Equal(expectedPath, builder.ToUri().AbsolutePath); }
public void ConvertsToUri() { var builder = new HttpUrlBuilder("http://localhost/api/foo"); Assert.Equal(new Uri("http://localhost/api/foo"), builder.ToUri()); }
public void ChangesHostName() { var builder = new HttpUrlBuilder("http://host1:1337/path"); builder.WithHost("host2"); Assert.Equal("http://host2:1337/path", builder.ToString()); }
public void OverwritesExistingPath(string url) { var builder = new HttpUrlBuilder(url); builder.WithPath("foo/bar"); Assert.Equal("/foo/bar", builder.ToUri().AbsolutePath); }
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()); }
public void FormatsFragment() { var builder = new HttpUrlBuilder("http://localhost"); builder.AppendFragment("foo/{0}", "bar"); Assert.Equal("#/foo/bar", builder.ToUri().Fragment); }
public void DoesNotEncodeThePathSeperator() { var builder = new HttpUrlBuilder("http://localhost"); builder.AppendFragment("foo/bar"); Assert.Equal("#/foo/bar", builder.ToUri().Fragment); }
public void ConvertsRelativeUrlToString() { var builder = new HttpUrlBuilder("/api/foo", UriKind.Relative); Assert.Equal("/api/foo", builder.ToString()); }
public void EncodesPathArguments() { var builder = new HttpUrlBuilder("http://localhost"); builder.WithPath("foo/{0}", "bar#bar"); Assert.Equal("/foo/bar%23bar", builder.ToUri().AbsolutePath); }
public void ConvertsAbsoluteUrlToString() { var builder = new HttpUrlBuilder("http://localhost/api/foo", UriKind.Absolute); Assert.Equal("http://localhost/api/foo", builder.ToString()); }
public void DoesNotEncodeThePathSeperator() { var builder = new HttpUrlBuilder("http://localhost"); builder.WithPath("foo/bar"); Assert.Equal("/foo/bar", builder.ToUri().AbsolutePath); }
public void ConvertsRelativeToUri() { var builder = new HttpUrlBuilder("/api/foo", UriKind.Relative); Assert.Equal(new Uri("/api/foo", UriKind.Relative), builder.ToUri()); }
public void FormatsPath() { var builder = new HttpUrlBuilder("http://localhost"); builder.WithPath("foo/{0}", "bar"); Assert.Equal("/foo/bar", builder.ToUri().AbsolutePath); }
public void InitializesUrlFromComponents() { var builder = new HttpUrlBuilder("localhost", port: 1234, scheme: "https"); Assert.Equal(new Uri("https://localhost:1234"), builder.ToUri()); }
public void WhenNoExistingFragment_SetsFragment(string url) { var builder = new HttpUrlBuilder(url); builder.AppendFragment("foo/bar"); Assert.Equal("#/foo/bar", builder.ToUri().Fragment); }
public void WhenNoExistingPath_SetsAbsolutePath(string url) { var builder = new HttpUrlBuilder(url); builder.AppendPath("foo/bar"); Assert.Equal("/foo/bar", builder.ToUri().AbsolutePath); }
public void AppendsPathToExisting(string url) { var builder = new HttpUrlBuilder(url); builder.AppendPath("foo/bar"); Assert.Equal("/existing/path/foo/bar", builder.ToUri().AbsolutePath); }
public void InitializesUrlFromString() { var builder = new HttpUrlBuilder("http://localhost/api/foo"); Assert.Equal(new Uri("http://localhost/api/foo"), builder.ToUri()); }
public void ChangesScheme() { var builder = new HttpUrlBuilder("http://host1:1337/path"); builder.WithScheme("https"); Assert.Equal("https://host1:1337/path", builder.ToString()); }
public void InitializesUrlFromRelativeUri() { var builder = new HttpUrlBuilder(new Uri("/api/foo", UriKind.Relative)); Assert.Equal(new Uri("/api/foo", UriKind.Relative), builder.ToUri()); }
public void EncodesFragment(string path, string expectedPath) { var builder = new HttpUrlBuilder("http://localhost"); builder.AppendFragment(path); Assert.Equal(expectedPath, builder.ToUri().Fragment); }
public void ChangesPost() { var builder = new HttpUrlBuilder("http://host1:1337/path"); builder.WithPort(2112); Assert.Equal("http://host1:2112/path", builder.ToString()); }
public Task PingAsync() { HttpUrlBuilder uri = new HttpUrlBuilder(application.HostUrl); return(restClient.SendAsync(uri, HttpMethod.Head)); }