public void OpenWeatherMapGoodJsonParseTest() { var json = new JObject( new JProperty("coord", new JObject(new JProperty("lon", 30.24), new JProperty("lat", 59.94))), new JProperty("weather", new JArray(new JObject(new JProperty("id", 800), new JProperty("main", "Clear"), new JProperty("description", "clear sky"), new JProperty("icon", "01d")))), new JProperty("base", "stations"), new JProperty("main", new JObject(new JProperty("temp", 273.15), new JProperty("feels_like", 284.72), new JProperty("temp_min", 286.21), new JProperty("temp_max", 286.21), new JProperty("pressure", 1024), new JProperty("humidity", 0))), new JProperty("visibility", 10000), new JProperty("wind", new JObject(new JProperty("speed", 0), new JProperty("deg", 360))), new JProperty("clouds", new JObject(new JProperty("all", 0))), new JProperty("dt", 1650470597), new JProperty("sys", new JObject(new JProperty("type", 1), new JProperty("id", 8926), new JProperty("country", "RU"), new JProperty("sunrise", 1650421705), new JProperty("sunset", 1650475630))), new JProperty("timezone", 10800), new JProperty("id", 536203), new JProperty("name", "Saint Petersburg"), new JProperty("cod", 200)).ToString(); var weather = new Weather(); OpenWeatherMapParser.Parse(weather, json); Assert.AreEqual(0, weather.TempInCelsius); Assert.AreEqual(32, weather.TempInFahrenheit); Assert.AreEqual(0, weather.Humidity); Assert.AreEqual(0, weather.Cloudiness); Assert.AreEqual("North", weather.WindDirection); Assert.AreEqual(0, weather.WindSpeed); Assert.AreEqual("Clear", weather.Precipitation); }
private void RefreshData() { // Start thread to get and load data to tomorrow.io new Thread(() => { try { var weather = new TomorrowIoParser(WebParser.Instance).CollectData(); tomorrowIoData.LoadWeatherData(weather); } catch { tomorrowIoData.LoadWeatherData(null); } }).Start(); // Start thread to get and load data to openweathermap.org new Thread(() => { try { var weather = new OpenWeatherMapParser(WebParser.Instance).CollectData(); openWeatherMapData.LoadWeatherData(weather); } catch { openWeatherMapData.LoadWeatherData(null); } }).Start(); }
public MainForm() { InitializeComponent(); tioLabel = new WeatherDataLabel(tioPanel); owmLabel = new WeatherDataLabel(owmPanel); owmParser = new OpenWeatherMapParser(WebParser.Instance); tioParser = new TomorrowIoParser(WebParser.Instance); RefreshData(); }
public void OpenWeatherMapBadJsonParseTest() { string?json = null; var weather = new Weather(); OpenWeatherMapParser.Parse(weather, json); var props = typeof(Weather).GetProperties(); foreach (var prop in props) { Assert.IsNull(prop.GetValue(weather)); } }
public void OpenWeatherMapBadResponceTest() { var fakeWebParser = new Mock <IWebParser>(); fakeWebParser.Setup(m => m.GetData(It.IsAny <string>())).Returns("{Some : super : strange : and : incorrect : data}"); OpenWeatherMapParser parser = new OpenWeatherMapParser(fakeWebParser.Object); try { parser.CollectData(); } catch (EmptyWeatherDataException) { Assert.Pass(); } Assert.Fail(); }
public void OpenWeatherMapGoodResponceTest() { var fakeWebParser = new Mock <IWebParser>(); fakeWebParser.Setup(m => m.GetData(It.IsAny <string>())).Returns("{\"coord\":{\"lon\":30.2642,\"lat\":59.8944},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01d\"}],\"base\":\"stations\",\"main\":{\"temp\":280,\"feels_like\":279,\"temp_min\":281.51,\"temp_max\":282.23,\"pressure\":1015,\"humidity\":58},\"visibility\":10000,\"wind\":{\"speed\":5,\"deg\":60},\"clouds\":{\"all\":0},\"dt\":1650707877,\"sys\":{\"type\":2,\"id\":197864,\"country\":\"RU\",\"sunrise\":1650680395,\"sunset\":1650735260},\"timezone\":10800,\"id\":498817,\"name\":\"Saint Petersburg\",\"cod\":200}"); OpenWeatherMapParser parser = new OpenWeatherMapParser(fakeWebParser.Object); WeatherData data = parser.CollectData(); var correctResponce = @"Source: openweathermap.org Temp (F): 44,33 Temp (C): 6,85 Cloud coverage(%): 0 Humidity: 58 Precipitation: Clear Wind Direction: 60 Wind Speed: 5"; Assert.AreEqual(correctResponce, data.ToString()); Assert.Pass(); }