public void DailyForecast_ReturnsExpectedResult_NotSunny() { FiveDayForecastResponse response = JsonSerializer.Deserialize <FiveDayForecastResponse>(testResponse); WeatherOutlook weatherOutlook = new WeatherOutlook(response, 50, 50); Assert.IsFalse(weatherOutlook.forecasts.FirstOrDefault().Sunny); }
public void DailyForecast_ReturnsExpectedResult_AverageTemperature() { FiveDayForecastResponse response = JsonSerializer.Deserialize <FiveDayForecastResponse>(testResponse); WeatherOutlook weatherOutlook = new WeatherOutlook(response, 50, 50); Assert.AreEqual(weatherOutlook.forecasts.FirstOrDefault()?.AverageTemperature, 60); }
private static WeatherOutlook GetWeatherOutlook(FiveDayForecastResponse fiveDayForecast) { var sunnyThreshold = Int32.Parse(ApplicationSettings.GetInstance().GetSettingValue(ConfigurableSettings.SunnyThreshold)); var rainyThreshold = Int32.Parse(ApplicationSettings.GetInstance().GetSettingValue(ConfigurableSettings.RainyThreshold)); WeatherOutlook weatherOutlook = new WeatherOutlook(fiveDayForecast, sunnyThreshold, rainyThreshold); return(weatherOutlook); }
public void DailyForecast_ReturnsExpectedResult_NotRainy() { FiveDayForecastResponse response = JsonSerializer.Deserialize <FiveDayForecastResponse>(testResponse); //Set rainy threshold higher than our test data returns to ensure thresholds are mapped correctly WeatherOutlook weatherOutlook = new WeatherOutlook(response, 50, 90); Assert.IsFalse(weatherOutlook.forecasts.FirstOrDefault().Rainy); }
public override void Execute() { FiveDayForecastResponse fiveDayForecast = GetForecast(); if (fiveDayForecast != null) { WeatherOutlook weatherOutlook = GetWeatherOutlook(fiveDayForecast); EngagementRecommendation recommendation = new EngagementRecommendation(weatherOutlook); recommendation.WritePlan(); } }
/// <summary> /// Constructor which populates the daily forecast with only the variables we care about based on the OpenWeatherAPI 5 day forecast response /// </summary> /// <param name="response">OpenWeatherAPI 5 day forecast</param> public WeatherOutlook(FiveDayForecastResponse response, int sunshineThreshold, int rainyThreshold) { forecasts = (from weatherItem in response.list group weatherItem by UnixEpoch.AddSeconds(weatherItem.dt).Date into forecastDate select new DailyForecast { ForecastDate = forecastDate.Key, AverageTemperature = GetAverageTemperature(forecastDate), Sunny = CheckIfSunny(sunshineThreshold, forecastDate), Rainy = CheckIfRainy(rainyThreshold, forecastDate) }).ToList(); }
private static FiveDayForecastResponse GetForecast() { IRestResponse response = CallOpenWeatherApi(); FiveDayForecastResponse fiveDayForecast = null; if (response.StatusCode != HttpStatusCode.OK) { Console.WriteLine($"API Error: {response.StatusCode} - {response.Content}", Color.Red); } else // Only attempt to deserialize if we got an okay response { try { fiveDayForecast = JsonSerializer.Deserialize <FiveDayForecastResponse>(response.Content); } catch (Exception ex) { Console.WriteLine($"Deserialization error: {ex.Message}", Color.Red); } } return(fiveDayForecast); }