public void ParseForecast() { var input = GetResource("Input.OpenWeatherMap.forecast.json"); var provider = new OpenWeatherMapProvider(); var forecast = provider.ParseForecast(input); Assert.AreEqual(5, forecast.Count); }
public async Task GetWeatherAsync() { var provider = new OpenWeatherMapProvider(API_KEY); string city = "appleton", state = "wi", country = "us"; var weather = await provider.GetWeatherAsync(city, state, country); Assert.IsNotNull(weather); }
public WeatherService() { _weatherProvider = new OpenWeatherMapProvider(); _weatherIdsMap = new Dictionary <int, Weather>() { { 200, Weather.ThunderStorm }, { 300, Weather.Drizzle }, { 500, Weather.Rain }, { 600, Weather.Snow }, { 800, Weather.Sunny }, { 802, Weather.Cloudy } }; }
public MainWindow() { var provider = new OpenWeatherMapProvider(); Weather = provider.ParseCurrentWeather(weatherJsonString); var forecast = provider.ParseForecast(forecastJsonString); WeatherInfo = new WeatherInfo() { Current = Weather, Forecast = forecast }; InitializeComponent(); }
public void ParseCurrentWeather() { var input = GetResource("Input.OpenWeatherMap.weather.json"); var provider = new OpenWeatherMapProvider(); var day = provider.ParseCurrentWeather(input); Assert.AreEqual(new DateTime(2019, 6, 4, 15, 52, 57), day.Date); Assert.AreEqual(day.Temperature.Celsius, 29.42, 0.01); Assert.AreEqual(WeatherCondition.FewClouds, day.Condition); Assert.AreEqual(RelativeHumidity.FromPercentage(0.6).Percentage, day.Humidity.Percentage, 0.1); Assert.IsNotNull(day.ApparentTemperature); var wind = day.Wind; Assert.AreEqual(Direction.East, wind.Direction); Assert.AreEqual(3.6, wind.Speed.KilometersPerHour, 0.1); }
/// <summary> /// The init. /// </summary> public void Init() { switch (this.WeatherProviderType) { case WeatherProviderType.OpenWeatherMap: var weatherProv = new OpenWeatherMapProvider(this.ApiKey); this.ForecastProvider = new ForecastProvider( weatherProv, cityName: this.City, countryCode: this.CountryCode, format: this.Format); break; default: throw new ArgumentOutOfRangeException(); } }
// Static Methods public static WeatherProviderImpl GetProvider(string API) { WeatherProviderImpl providerImpl = null; switch (API) { case WeatherAPI.Yahoo: providerImpl = new YahooWeatherProvider(); break; case WeatherAPI.WeatherUnderground: providerImpl = new WeatherUndergroundProvider(); break; case WeatherAPI.Here: providerImpl = new HEREWeatherProvider(); break; case WeatherAPI.OpenWeatherMap: providerImpl = new OpenWeatherMapProvider(); break; case WeatherAPI.MetNo: providerImpl = new MetnoWeatherProvider(); break; default: break; } if (providerImpl == null) { throw new ArgumentNullException(nameof(API), "Invalid API name! This API is not supported"); } return(providerImpl); }
public ActionResult Weather(string city) { IDataProvider dataProvider = new OpenWeatherMapProvider(); return(View(dataProvider.GetData(city))); }