public void TomorrowIoGoodJsonParseTest()
        {
            var json =
                new JObject(new JProperty("data",
                                          new JObject(new JProperty("timelines",
                                                                    new JArray(new JObject(new JProperty("timestep", "current"),
                                                                                           new JProperty("endTime", "2022-04-20T16:51:00Z"),
                                                                                           new JProperty("startTime", "2022-04-20T16:51:00Z"),
                                                                                           new JProperty("intervals",
                                                                                                         new JArray(new JObject(new JProperty("startTime", "2022-04-20T16:51:00Z"),
                                                                                                                                new JProperty("values",
                                                                                                                                              new JObject(new JProperty("cloudCover", 0), new JProperty("humidity", 0),
                                                                                                                                                          new JProperty("precipitationType", 0), new JProperty("temperature", 0),
                                                                                                                                                          new JProperty("windDirection", 360),
                                                                                                                                                          new JProperty("windSpeed", 0)))))))))))).ToString();


            var weather = new Weather();

            TomorrowIoParser.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);
        }
예제 #2
0
 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();
 }
예제 #3
0
        public MainForm()
        {
            InitializeComponent();

            tioLabel = new WeatherDataLabel(tioPanel);
            owmLabel = new WeatherDataLabel(owmPanel);

            owmParser = new OpenWeatherMapParser(WebParser.Instance);
            tioParser = new TomorrowIoParser(WebParser.Instance);

            RefreshData();
        }
        public void TomorrowIoBadJsonParseTest()
        {
            string?json    = null;
            var    weather = new Weather();

            TomorrowIoParser.Parse(weather, json);
            var props = typeof(Weather).GetProperties();

            foreach (var prop in props)
            {
                Assert.IsNull(prop.GetValue(weather));
            }
        }
        public void TomorrowIoBadResponceTest()
        {
            var fakeWebParser = new Mock <IWebParser>();

            fakeWebParser.Setup(m => m.GetData(It.IsAny <string>())).Returns("{Some : super : strange : and : incorrect : data}");

            TomorrowIoParser parser = new TomorrowIoParser(fakeWebParser.Object);

            try
            {
                parser.CollectData();
            }
            catch (EmptyWeatherDataException)
            {
                Assert.Pass();
            }

            Assert.Fail();
        }
        public void TomorrowIoGoodResponceTest()
        {
            var fakeWebParser = new Mock <IWebParser>();

            fakeWebParser.Setup(m => m.GetData(It.IsAny <string>())).Returns("{\"data\":{\"timelines\":[{\"timestep\":\"current\",\"endTime\":\"2022-04-19T19:46:00Z\",\"startTime\":\"2022-04-19T19:46:00Z\",\"intervals\":[{\"startTime\":\"2022-04-19T19:46:00Z\",\"values\":{\"cloudCover\":10,\"humidity\":20,\"precipitationType\":1,\"temperature\":30,\"windDirection\":40,\"windSpeed\":50}}]}]}}");

            TomorrowIoParser parser = new TomorrowIoParser(fakeWebParser.Object);

            WeatherData data            = parser.CollectData();
            var         correctResponce = @"Source: tomorrow.io
Temp (F): 86,00
Temp (C): 30,00
Cloud coverage(%): 10
Humidity: 20
Precipitation: Rain
Wind Direction: 40
Wind Speed: 50";

            Assert.AreEqual(correctResponce, data.ToString());

            Assert.Pass();
        }