public void CanGetJsonEnumerable() { var client = new HttpClient() { BaseAddress = ApiConfig.ApiBaseAddress }; client.DefaultRequestHeaders.Add("Accept", AcceptType.Json); var response = client.GetAsync("persons").Result; var persons = response.Content.ReadAsAsync<IEnumerable<Person>>().Result.ToList(); Assert.IsTrue(persons.Count == 5); }
public void CanGetStringContent() { var client = new HttpClient() { BaseAddress = ApiConfig.ApiBaseAddress }; var response = client.GetAsync("persons").Result; Assert.IsTrue(response.StatusCode == HttpStatusCode.OK); var content = response.Content.ReadAsStringAsync().Result; Assert.IsNotNull(content); Assert.IsTrue(content.Length > 0); }
public void CanGetXmlContent() { var client = new HttpClient() { BaseAddress = ApiConfig.ApiBaseAddress }; client.DefaultRequestHeaders.Add("Accept", AcceptType.Xml); var response = client.GetAsync("persons/1").Result; var person = response.Content.ReadAsAsync<Person>().Result; Assert.IsTrue(person.Id == 1); Assert.IsTrue(person.FirstName == "John"); Assert.IsTrue(person.LastName == "Smith"); }
public void CancelationTest() { TimeoutManager.TimeoutInMilliseconds = 0; var client = new HttpClient() { BaseAddress = BaseApiUriAddress }; var response = client.GetAsync("persons"); Thread.Sleep(2000); try { Assert.IsNotNull(response.Result); } catch (AggregateException exception) { Assert.AreEqual(exception.InnerExceptions.Count, 1); var requestException = exception.InnerException.InnerException as WebException; Assert.IsNotNull(requestException); Assert.AreEqual(requestException.Status, WebExceptionStatus.RequestCanceled); } TimeoutManager.TimeoutInMilliseconds = 100 * 1000; }