public void SendJsonGzip() { using (TestWebHost host = new TestWebHost()) { host.StarWebHost("http://*:14999"); Thread.Sleep(1000); UriBuilder uriBuildr = new UriBuilder("http", "localhost", 14999, "res"); Uri baseUri = uriBuildr.Uri; RestApiClient client = new RestApiClient(null, request => { request.Headers.Add("CustomHeader", "CustomHeaderValue"); RestApiClientExtensions.ApplyAcceptEncodingSettingGZip(request); } ); PurchaseOrder sendObj = new PurchaseOrder(); HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, baseUri, sendObj).Result; string send = RestApiClientExtensions.GetJsonString(sendObj); string json = response.ReadContentAsStringGzip().Result; string rest = host.Message; Assert.Equal(send, json); Assert.Equal(rest, json); string test = response.Headers.GetValues("CustomHeader").First(); Assert.Contains(response.Content.Headers.ContentEncoding, x => x.ToLower() == "gzip"); Assert.Equal("CustomHeaderValue", test); } }
public void SendJsonAbsolute() { using (TestWebHost host = new TestWebHost()) { host.StarWebHost("http://*:15000"); Thread.Sleep(1000); UriBuilder uriBuildr = new UriBuilder("http", "localhost", 15000, "res"); Uri baseUri = uriBuildr.Uri; RestApiClient client = new RestApiClient(null, request => { request.Headers.Add("CustomHeader", "CustomHeaderValue"); } ); PurchaseOrder sendObj = new PurchaseOrder(); HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, baseUri, sendObj).Result; string send = RestApiClientExtensions.GetJsonString(sendObj); string json = response.Content.ReadAsStringAsync().Result; string rest = host.Message; PurchaseOrder respObj = response.DeseriaseJsonResponse <PurchaseOrder>(); Assert.Equal(send, json); Assert.Equal(rest, json); string test = response.Headers.GetValues("CustomHeader").First(); Assert.Equal("CustomHeaderValue", test); } }
public void SendJson() { using (TestWebHost host = new TestWebHost()) { host.StarWebHost("http://*:15001"); Thread.Sleep(1000); Uri baseUri = new Uri("http://localhost:15001"); RestApiClient client = new RestApiClient(baseUri, request => { request.Headers.Add("CustomHeader", "CustomHeaderValue"); } ); PurchaseOrder sendObj = new PurchaseOrder(); Uri relUri = new Uri(RequestPathAttribute.GetRestApiPath(sendObj), UriKind.Relative); HttpResponseMessage response = client.SendJsonRequest(HttpMethod.Post, relUri, sendObj).Result; string send = RestApiClientExtensions.GetJsonString(sendObj); string json = response.Content.ReadAsStringAsync().Result; string rest = host.Message; PurchaseOrder respObj = response.DeseriaseJsonResponse <PurchaseOrder>(); Assert.Equal(send, json); Assert.Equal(rest, json); string test = response.Headers.GetValues("CustomHeader").First(); Assert.Equal("CustomHeaderValue", test); } }