示例#1
0
        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"));
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }