示例#1
0
        void GetForecast(string city, string apiKey)
        {
            int    cnt = 7;
            string url = string.Format("https://api.openweathermap.org/data/2.5/forecast?q={0}&units=metric&cnt={1}&appid={2}", city, cnt, apiKey);

            string[] lblNamesTab    = { "lbl_day", "lbl_condition", "lbl_description", "lbl_windSpeed", "lbl_temp" };
            string[] addToStringTab = { "", "", "", " km/h", " \u00B0 C" };

            using (WebClient web = new WebClient())
            {
                var            json       = web.DownloadString(url);
                var            jsonObject = JsonConvert.DeserializeObject <WeatherForcast>(json);
                WeatherForcast forcast    = jsonObject;


                for (int i = 1; i < cnt; i++)
                {
                    string[] weatherInfoTab = { (getDate(forcast.list[i].dt)).ToString(), forcast.list[i].weather[0].main, forcast.list[i].weather[0].description, (forcast.list[i].wind.speed).ToString(), (forcast.list[i].main.temp).ToString() };

                    for (int j = 0; j < lblNamesTab.Length; j++)
                    {
                        findAndChangeTextInLabel(lblNamesTab[j], i - 1, addToStringTab[j], weatherInfoTab[j]);
                    }

                    object image = Resources.ResourceManager.GetObject("_" + forcast.list[i].weather[0].icon);
                    ((PictureBox)this.Controls["pictureBox" + (i - 1)]).Image = (Image)image;
                }
            }
        }
        public void GetForcast_TDD()
        {
            var injection = new FakeWeatherForcastRepository();
            IWeatherForcast forcast= new WeatherForcast(injection);

            Assert.IsNotNull(forcast);
        }
        public void GetForcast_TDD()
        {
            var weather = new WeatherForcast();

            var forcast = weather.GetForcast(57.999628, 16.017767);

            Assert.IsNotNull(forcast);
        }
        public void GetForcast_Counting_ReturnValue()
        {
            var injection = new FakeWeatherForcastRepository();
            IWeatherForcast forcast = new WeatherForcast(injection);

            var count = forcast.GetForcast(34.44, 234.34).Count();

            Assert.AreEqual(count, 70);
        }
        public void GetForcast_Assert_ReturningValue()
        {
            var weather = new WeatherForcast(new FakeWeatherForcastRepository());
            var forcast = weather.GetForcast(88.44, 85.55).AsQueryable();

            Assert.AreEqual(forcast.Select(s => s.ApprovedTime).First().ToString(), "2015-05-01 05:10:39");
            Assert.AreEqual(forcast.Select(s=>s.MSL).First(), 1008.0);
            Assert.AreEqual(forcast.Select(m=>m.SPP).First(), -9);
            Assert.AreEqual(forcast.Select(m=>m.PMEDIAN).First(), 0);
        }