public async Task GetUnknownHost() { var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("It worked!") }; var mockHttpMessageHandler = new Mock <HttpMessageHandler>(); SetupSendAsync(mockHttpMessageHandler).ThrowsAsync(new HttpRequestException()); var httpClient = new PlayerHttpClient(new HttpClient(mockHttpMessageHandler.Object)); await Assert.ThrowsAsync <PlayerCommunicationException>(async() => await httpClient.GetAsync("https://anywhere.com", TimeSpan.FromMinutes(5))); }
public async Task GetAsync() { var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("It worked!") }; var mockHttpMessageHandler = new Mock <HttpMessageHandler>(); SetupSendAsync(mockHttpMessageHandler).ReturnsAsync(() => response); var httpClient = new PlayerHttpClient(new HttpClient(mockHttpMessageHandler.Object)); var getResult = await httpClient.GetAsync("https://anywhere.com", TimeSpan.FromMinutes(5)); Assert.Equal(HttpStatusCode.OK, getResult.StatusCode); }
public async Task GetWrongStatusCode() { var response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("Error") }; var mockHttpMessageHandler = new Mock <HttpMessageHandler>(); SetupSendAsync(mockHttpMessageHandler).ReturnsAsync(response); var httpClient = new PlayerHttpClient(new HttpClient(mockHttpMessageHandler.Object)); var ex = await Assert.ThrowsAsync <InvalidStatusCodeException>(async() => await httpClient.GetAsync("https://anywhere.com", TimeSpan.FromMinutes(5))); Assert.Equal("Error", ex.Data[nameof(InvalidStatusCodeException.Content)]); }