public async Task GetJokeAsync_WhenSucessRequest_ReturnJoke() { // Arrange var jokeContent = JsonConvert.SerializeObject(_fixture.Create <JokeResponse>()); var statusCode = HttpStatusCode.OK; var handler = new HttpMessageHandlerTest(statusCode, jokeContent); var httpClient = new HttpClient(handler); _httpClientFactory.CreateClient(Arg.Any <string>()).Returns(httpClient); var controller = new LegacyJokeController(_httpClientFactory, _logger); // Act var result = await controller.GetJokeAsync(); result.Should().NotBeNull(); }
public void GetJokeAsync_WhenBadRequest_ThrowException() { // Arrange var jokeContent = JsonConvert.SerializeObject(_fixture.Create <JokeResponse>()); var statusCode = HttpStatusCode.BadRequest; var handler = new HttpMessageHandlerTest(statusCode, jokeContent); var httpClient = new HttpClient(handler); _httpClientFactory.CreateClient(Arg.Any <string>()).Returns(httpClient); var controller = new LegacyJokeController(_httpClientFactory, _logger); // Act Action action = () => controller.GetJokeAsync().GetAwaiter().GetResult(); action.Should().ThrowExactly <Exception>(); }