public void SimpleWithNonDefaultPort() { RestUri target = new RestUri("http://localhost:50001/", "account"); var actual = target.ToString(); Assert.Equal("http://localhost:50001/account", actual); }
public void WithUriTemplateParameter() { RestUri target = new RestUri("http://localhost/", "account/{id}").SetParameter("id", 1); var actual = target.ToString(); Assert.Equal("http://localhost/account/1", actual); }
public Task <RestResponse <T> > PatchAsync <T>(RestUri uri, RestRequestBody requestBody, ContentType contentType) { RestRequest request = CreateRestRequest(HttpMethod.PATCH, uri); request.Body = requestBody; request.ContentType = contentType; return(InvokeAsync <T>(request)); }
public void SimpleWithPathPortionInUrlAndNoTrailingAndLeadingSlashes() { RestUri target = new RestUri("http://localhost/api", "account"); var actual = target.ToString(); Assert.Equal("http://localhost/api/account", actual); }
public void SimpleWithPathPortionInUrlAndTrailingAndLeadingSlashesInBaseUriAndResourceUrlRespectively() { RestUri target = new RestUri("http://localhost/api/", "/account"); var actual = target.ToString(); Assert.Equal("http://localhost/api/account", actual); }
public void WithSingleQueryString() { RestUri target = new RestUri("http://localhost/", "account").SetQuery("id", 1); var actual = target.ToString(); Assert.Equal("http://localhost/account?id=1", actual); }
public Task <RestResponse> PutAsync(RestUri uri, RestRequestBody requestBody, ContentType contentType)//1 { RestRequest request = CreateRestRequest(HttpMethod.PUT, uri); request.Body = requestBody; request.ContentType = contentType; return(InvokeAsync(request)); }
public void Simple() { RestUri target = new RestUri("http://localhost/", "account"); var actual = target.ToString(); Assert.Equal("http://localhost/account", actual); }
public void WithMultipleUriTemplateParameter() { RestUri target = new RestUri("http://localhost/", "account/{id}/{uid}/{date}/{email}").SetParameter("id", 1).SetParameter("uid", new Guid("5AAE425D-A603-43B7-86CE-D66EF0AC870C")).SetParameter("date", new DateTime(2010, 1, 1)).SetParameter("email", "*****@*****.**"); var actual = target.ToString(); var dateString = Uri.EscapeDataString(new DateTime(2010, 1, 1).ToString()); var expected = string.Format("http://localhost/account/1/5aae425d-a603-43b7-86ce-d66ef0ac870c/{0}/abc%40abc.com", dateString); Assert.Equal(expected, actual); }
public void WithQueryStringRepeatedInBaseUrlAndUsingSetQuery() { RestUri target = new RestUri("http://localhost/account?id=1").SetQuery("id", 2); var actual = target.ToString(); var expected = "http://localhost/account?id=2"; Assert.Equal(expected, actual); }
public void WithQueryStringNotInNameValueFormatOption2() { RestUri target = new RestUri("http://localhost/", "account").SetQuery("123456", QueryStringParameter.None); var actual = target.ToString(); var expected = "http://localhost/account?123456"; Assert.Equal(expected, actual); }
public void WithOnlyQueryStringInResourceUrl() { RestUri target = new RestUri("http://localhost/account", "?id=1"); var actual = target.ToString(); var expected = "http://localhost/account?id=1"; Assert.Equal(expected, actual); }
public void WithQueryStringNotInNameValueFormatOption3() { RestUri target = new RestUri("http://localhost/", "account?123456").SetQuery("id", "1"); var actual = target.ToString(); var expected = "http://localhost/account?123456&id=1"; Assert.Equal(expected, actual); }
public void WithEmbededUrlInQueryString() { RestUri target = new RestUri("http://localhost/account/") .SetQuery("redirectTo", "http://localhost/login"); var actual = target.ToString(); var expected = "http://localhost/account?redirectTo=http%3A%2F%2Flocalhost%2Flogin"; Assert.Equal(expected, actual); }
public void WithEmbededUrlWithPortInUriTemplate() { RestUri target = new RestUri("http://localhost/account/{redirectTo}") .SetParameter("redirectTo", "http://localhost:80/login"); var actual = target.ToString(); var expected = "http://localhost/account/http%3A%2F%2Flocalhost%3A80%2Flogin"; Assert.Equal(expected, actual); }
public void WithMultipleQueryStrings() { RestUri target = new RestUri("http://localhost/", "account").SetQuery("id", 1).SetQuery("date", new DateTime(2010, 1, 1)).SetQuery("uid", new Guid("5AAE425D-A603-43B7-86CE-D66EF0AC870C")); var actual = target.ToString(); var dateString = Uri.EscapeDataString(new DateTime(2010, 1, 1).ToString()); var expected = string.Format("http://localhost/account?id=1&date={0}&uid=5aae425d-a603-43b7-86ce-d66ef0ac870c", dateString); Assert.Equal(expected, actual); }
private RestRequest CreateRestRequest(HttpMethod method, RestUri uri) { var restRequest = new RestRequest(method, uri); foreach (Cookie cookie in _cookies) { restRequest.AddCookie(cookie); } foreach (var header in _headers) { if (header.Key is string) { restRequest.AddHeader(header.Key.ToString(), header.Value.ToString()); } else if (header.Key is HttpRequestHeader) { restRequest.AddHeader((HttpRequestHeader)header.Key, header.Value.ToString()); } } restRequest.AllowAutoRedirect = AllowAutoRedirect; restRequest.AuthenticationLevel = AuthenticationLevel; restRequest.AutomaticDecompression = AutomaticDecompression; restRequest.CachePolicy = CachePolicy; if (ClientCertificates != null) { foreach (var cert in ClientCertificates) { restRequest.ClientCertificates.Add(cert); } } restRequest.Credentials = Credentials; restRequest.KeepAlive = KeepAlive; restRequest.MaximumAutomaticRedirections = MaximumAutomaticRedirections; restRequest.Referer = Referer; restRequest.TcpKeepAlive = TcpKeepAlive; restRequest.TcpKeepAliveTimeOut = TcpKeepAliveTimeOut; restRequest.TimeOut = TimeOut; restRequest.UserAgent = UserAgent; return(restRequest); }
private RestUri CreateRestUri(Uri baseUri, string resourceUri, object parameters) { var uri = new RestUri(baseUri, resourceUri); var nameValuePairs = parameters.ToDictionary(); foreach (var nameValue in nameValuePairs) { if (resourceUri.IndexOf("{" + nameValue.Key + "}") > -1) { uri.SetParameter(nameValue.Key, nameValue.Value); } else { uri.SetQuery(nameValue.Key, nameValue.Value); } } return(uri); }
public Task <RestResponse <T> > DeleteAsync <T>(RestUri uri) { return(InvokeAsync <T>(CreateRestRequest(HttpMethod.DELETE, uri))); }
public RestRequestBuilder(HttpMethod method, RestUri uri) { _request = new RestRequest(method, uri); }
public Task <RestResponse <T> > PatchAsync <T>(RestUri uri, RestRequestBody requestBody) { return(PatchAsync <T>(uri, requestBody, ContentType.ApplicationX_WWW_Form_UrlEncoded)); }
public RestResponse <T> Patch <T>(RestUri uri, RestRequestBody requestBody, ContentType contentType) { return(PatchAsync <T>(uri, requestBody, contentType).Result); }
public RestResponse Patch(RestUri uri, RestRequestBody requestBody) { return(PatchAsync(uri, requestBody).Result); }
public void NamedParametersAreReplaced() { var restUri = new RestUri("http://domain.ext/{foo}/index.{ext}", new { foo = "bar", ext = "html" }); Assert.Equal("http://domain.ext/bar/index.html", restUri.AbsoluteUri); }
public void Patch_overload1() { //Arrange RestInvoker target = new RestInvoker(_MyUri.OriginalString); StubModule.HaltProcessing = TimeSpan.FromSeconds(0); StubModule.PatchPerson = false; StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } }; var uri = new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1"); var contentType = ContentType.ApplicationX_WWW_Form_UrlEncoded; var body = new RestObjectRequestBody<Person>(new Person { Id = 1, Email = "*****@*****.**" }); //Act using (RestResponse actual = target.Patch(uri, body, contentType)) { //Assert Assert.True(StubModule.PatchPerson); Assert.NotNull(actual); Assert.True(actual.IsSuccessStatusCode); var person = StubModule.TestHarness.Where(x => x.Id == 1).FirstOrDefault(); Assert.NotNull(person); Assert.Equal("*****@*****.**", person.Email); } }
public static RestRequestBuilder CreateRequest(HttpMethod method, RestUri uri) { return(new RestRequestBuilder(method, uri)); }
public static RestRequestBuilder CreateRequest(HttpMethod method, RestUri uri) { return new RestRequestBuilder(method, uri); }
public RestResponse <T> Delete <T>(RestUri uri) { return(DeleteAsync <T>(uri).Result); }
public RestResponse <T> Get <T>(RestUri uri) { return(GetAsync <T>(uri).Result); }
public Task <RestResponse <T> > GetAsync <T>(RestUri uri) { return(InvokeAsync <T>(CreateRestRequest(HttpMethod.GET, uri))); }
public RestResponse Delete(RestUri uri) { return(DeleteAsync(uri).Result); }
public RestResponse <T> Patch <T>(RestUri uri, RestRequestBody requestBody) { return(PatchAsync <T>(uri, requestBody).Result); }
public void Post_overload2() { //Arrange RestInvoker target = new RestInvoker(_MyUri.OriginalString); StubModule.HaltProcessing = TimeSpan.FromSeconds(0); StubModule.PostPerson = false; StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } }; var uri = new RestUri(_MyUri, "/Person"); var body = new RestObjectRequestBody<Person>(new Person { Id = 2, Email = "*****@*****.**" }); //Act using (RestResponse actual = target.Post(uri, body)) { //Assert Assert.True(StubModule.PostPerson); Assert.NotNull(actual); Assert.True(actual.IsSuccessStatusCode); var person = StubModule.TestHarness.Where(x => x.Id == 2).FirstOrDefault(); Assert.NotNull(person); Assert.Equal("*****@*****.**", person.Email); } }
public void PatchAsync_overload2() { //Arrange RestInvoker target = new RestInvoker(_MyUri.OriginalString); StubModule.HaltProcessing = TimeSpan.FromSeconds(0); StubModule.PatchPerson = false; StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } }; var uri = new RestUri(_MyUri, "/Person/{id}").SetParameter("id", "1"); var body = new RestObjectRequestBody<Person>(new Person { Id = 1, Email = "*****@*****.**" }); //Act target.PatchAsync(uri, body).ContinueWith(task => { using (RestResponse actual = task.Result) { //Assert Assert.True(StubModule.PatchPerson); Assert.NotNull(actual); Assert.True(actual.IsSuccessStatusCode); var person = StubModule.TestHarness.Where(x => x.Id == 1).FirstOrDefault(); Assert.NotNull(person); Assert.Equal("*****@*****.**", person.Email); } }).Wait(); }
public void PostAsync_overload1() { //Arrange RestInvoker target = new RestInvoker(_MyUri.OriginalString); StubModule.HaltProcessing = TimeSpan.FromSeconds(0); StubModule.PostPerson = false; StubModule.TestHarness = new List<Person> { new Person { Id = 1, Email = "*****@*****.**" } }; var uri = new RestUri(_MyUri, "/Person"); var contentType = ContentType.ApplicationX_WWW_Form_UrlEncoded; var body = new RestObjectRequestBody<Person>(new Person { Id = 2, Email = "*****@*****.**" }); //Act target.PostAsync(uri, body, contentType).ContinueWith(task => { using (RestResponse actual = task.Result) { //Assert Assert.True(StubModule.PostPerson); Assert.NotNull(actual); Assert.True(actual.IsSuccessStatusCode); var person = StubModule.TestHarness.Where(x => x.Id == 2).FirstOrDefault(); Assert.NotNull(person); Assert.Equal("*****@*****.**", person.Email); } }).Wait(); }