public void Should_return_weather_forecasts_form_weather_source_when_cache_does_not_contain_city() { var result = new WeatherForecastResult { Status = Status.Success, WeatherForecast = new List <WeatherInfo>() }; weatherSource.GetWeatherFor(query.City, query.DaysCount) .Returns(result); var weatherForecastResult = watherController.WeatherForecasts(query).Result; weatherForecastResult.Should().BeEquivalentTo(result); }
public void SetUp() { cache = Substitute.For <IForecastsCache>(); cache.TryGetForecasts(DefaultCity, out _).Returns(false); weatherSource = Substitute.For <IWeatherSource>(); weatherSource.GetWeatherFor(Arg.Any <string>(), Arg.Any <int>()) .Returns(new WeatherForecastResult()); watherController = new WeatherController(weatherSource, cache); query = new WeatherQuery { City = DefaultCity, DaysCount = 10 }; }
public async Task <WeatherForecastResult> WeatherForecasts([FromQuery] WeatherQuery weatherQuery) { if (cache.TryGetForecasts(weatherQuery.City, out var cachedForecasts)) { return(WeatherForecastResult.Successfull(cachedForecasts)); } var weatherForecastResult = await weatherSource.GetWeatherFor(weatherQuery.City, weatherQuery.DaysCount); if (weatherForecastResult.Status == Status.Success) { cache.UpdateCache(weatherQuery.City, weatherForecastResult.WeatherForecast); } return(weatherForecastResult); }