public async Task GetWeatherForecastAsync_ReturnsNull_WhenAnExceptionOccurs() { var config = new ExternalServicesConfig { Url = "http://www.example.com", MinsToCache = 0 }; var mockOptions = new Mock <IOptionsMonitor <ExternalServicesConfig> >(); mockOptions.Setup(x => x.Get(It.IsAny <string>())).Returns(config); var client = new HttpClient(new ExceptionHandler()); var sut = new WeatherApiClient(client, mockOptions.Object, NullLogger <WeatherApiClient> .Instance); var result = await sut.GetWeatherForecastAsync(); Assert.Null(result); }
public async Task GetWeatherForecastAsync_ReturnsWeatherApiResult_WhenHttpRequestSucceeds() { var config = new ExternalServicesConfig { Url = "http://www.example.com", MinsToCache = 0 }; var mockOptions = new Mock <IOptionsMonitor <ExternalServicesConfig> >(); mockOptions.Setup(x => x.Get(It.IsAny <string>())).Returns(config); var client = new HttpClient(new SuccessHandler()); var sut = new WeatherApiClient(client, mockOptions.Object, NullLogger <WeatherApiClient> .Instance); var result = await sut.GetWeatherForecastAsync(); Assert.IsType <WeatherApiResult>(result); Assert.Equal("London", result.City); }