예제 #1
0
        public void CurrentWeathercalls()
        {
            CurrentWeather TestWeather = new CurrentWeather();

            WeatherAPI api = new WeatherAPI();
            api.isTest = true;
            var CurrentWeather = api.GetCurrentWeather("7839644").Result;
            Assert.AreEqual(CurrentWeather.MainData.Temp, "16.7");
            Assert.AreEqual(CurrentWeather.MainData.Humidity, "63");
            Assert.AreEqual(CurrentWeather.MainData.Humidity, "63");
            Assert.AreEqual(CurrentWeather.MainData.TemperatureMax, "18.33");
            Assert.AreEqual(CurrentWeather.MainData.TemperatureMin, "14.44");
            Assert.AreEqual(CurrentWeather.WeatherData[0].Description, "broken clouds");
            Assert.AreEqual(CurrentWeather.WeatherData[0].Main, "Clouds");
        }
예제 #2
0
        private void CurrentWeather()
        {
            ObservableCollection <CurrentWeather> weathers = new ObservableCollection <CurrentWeather>();

            foreach (KeyValuePair <string, string> city in CityToID.Instance.australianCities)
            {
                WeatherAPI     api     = new WeatherAPI();
                CurrentWeather weather = api.GetCurrentWeather(city.Value).Result;
                if (weather == null)
                {
                    AustralianCurrentWeatherProgressRing.IsActive = false;
                    if (api.errType == "Internet")
                    {
                        ErrorText.Text = "No response: Please check your internet connection";
                        return;
                    }
                    else if (api.errType == "WebsiteError")
                    {
                        ErrorText.Text = "Reponse error: Please contact support for further information";
                        return;
                    }
                    else if (api.errType == "APIParameterChange")
                    {
                        ErrorText.Text = "Response Error: please contact support for further information";
                        return;
                    }
                }
                //check if deserializing of json data is yielded useful information
                try
                {
                    string checker = weather.WeatherDescription;
                }
                catch (NullReferenceException)
                {
                    AustralianCurrentWeatherProgressRing.IsActive = false;
                    ErrorText.Text = "Response Error: please contact support for further information";
                    return;
                }
                weather.Location = city.Key;
                weathers.Add(weather);
            }


            AustralianCurrentWeatherProgressRing.IsActive = false;
            listview.ItemsSource = weathers;
            Logger.Instance.LogSuccessFullLoad();
        }