public async Task Returns_OpenWeatherException_When_Unauthorized() { var opts = OptionsBuilder.OpenWeatherConfig(); var clientFactory = ClientBuilder.OpenWeatherClientFactory(OpenWeatherResponses.UnauthorizedResponse, HttpStatusCode.Unauthorized); var sut = new OpenWeatherService(opts, clientFactory); var result = await Assert.ThrowsAsync <OpenWeatherException>(() => sut.GetFiveDayForecastAsync("Chicago")); Assert.Equal(401, (int)result.StatusCode); }
public void Return_openweatherexception_when_unauthorized_access() { var handler = new HttpMessageHandlerMock(OpenWeatherResponses.UnauthorizedResponse, HttpStatusCode.Unauthorized); var client = new HttpClient(handler); _clientFactory = Substitute.For <IHttpClientFactory>(); _clientFactory.CreateClient().Returns <HttpClient>(client); _openWeatherService = new OpenWeatherService(_openWeatherConfiguration, _clientFactory); var sut = new OpenWeatherService(_openWeatherConfiguration, _clientFactory); var response = Assert.ThrowsAsync <OpenWeatherException>(async() => await sut.GetFiveDayForecastAsync("Chicago")); response.StatusCode.Should().Be(401); /*Func<Task> act = async () => { await sut.GetFiveDayForecastAsync("Chicago").ThrowAsync<ArgumentException>(); }; */}