public void HttpClientShouldNotReturnContentOnBadStatusCode() { // ARRANGE var response = ""; DefaultHttpHandlerMock.SetResponse(response, HttpStatusCode.NotFound); // ACT var client = DefaultDaemonHost.Http.CreateHttpClient("test"); // ASSERT var ex = Assert.ThrowsAsync <HttpRequestException>(() => client.GetStringAsync("http://fake.com")); }
public async Task HttpClientShouldReturnCorrectStatusCodeError() { // ARRANGE var response = "{\"json_prop\", \"hello world\"}"; DefaultHttpHandlerMock.SetResponse(response, HttpStatusCode.Forbidden); // ACT var client = DefaultDaemonHost.Http.CreateHttpClient("test"); var httpResponse = await client.GetAsync("http://fake.com").ConfigureAwait(false); // ASSERT Assert.Equal(HttpStatusCode.Forbidden, httpResponse.StatusCode); }
public async Task HttpClientShouldReturnCorrectContent() { // ARRANGE var response = "{\"json_prop\", \"hello world\"}"; DefaultHttpHandlerMock.SetResponse(response); // ACT var client = DefaultDaemonHost.Http.CreateHttpClient("test"); var httpResponseString = await client.GetStringAsync("http://fake.com").ConfigureAwait(false); // ASSERT Assert.Equal(response, httpResponseString); }