Exemplo n.º 1
0
        public async Task GetCurrentWeatherAsync_IfApiKeyEmptyOrNull_ThrowArgumentException()
        {
            ApiHelper.InitializeClient();

            _sut.ApiKey = null;

            await Assert.ThrowsAsync <ArgumentException>(() => _sut.GetCurrentWeatherAsync());
        }
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            TemperatureModel tm = new TemperatureModel();

            if (temp.Cod == 401)
            {
                MessageBox.Show("Clé invalide !");
            }
            else if (temp.Cod == 404)
            {
                MessageBox.Show("Ville introuvable !");
            }
            else
            {
                tm = new TemperatureModel
                {
                    DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                    Temperature = temp.Main.Temperature
                };
            }

            return(tm);
        }
Exemplo n.º 3
0
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            if (temp.Cod == 401)
            {
                MessageBox.Show("Please make sure your ApiKey is valid and authorized!");
                return(null);
            }
            else if (temp.Cod == 404)
            {
                MessageBox.Show("The city that you have enter is invalid!");
                return(null);
            }
            else
            {
                var result = new TemperatureModel
                {
                    DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                    Temperature = temp.Main.Temperature
                };

                return(result);
            }
        }
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            if (temp.Cod == 401)
            {
                MessageBox.Show("ApiKey not authorize");
                throw new UnauthorizedAccessException();
            }
            if (temp.Cod == 404)
            {
                MessageBox.Show("City not found");
                throw new FormatException();
            }


            var result = new TemperatureModel
            {
                DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                Temperature = temp.Main.Temperature
            };

            return(result);


            ;
        }
Exemplo n.º 5
0
 public async Task GetCurrentWeatherAsync_IfApiKeyEmptyOrNull_ThrowArgumentException()
 {
     _sut        = OpenWeatherProcessor.Instance;
     _sut.ApiKey = null;
     //_sut.ApiKey = "";
     await Assert.ThrowsAsync <ArgumentException>(() => _sut.GetCurrentWeatherAsync());
 }
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            if (temp.Cod == 404)
            {
                MessageBox.Show("Please be sure you've set a valid City name. \n Code Error = 404");
                return(new TemperatureModel());
            }
            else if (temp.Cod == 401)
            {
                MessageBox.Show("Please be sure you've set a valid ApiKey. \n Code Error = 401");
                return(new TemperatureModel());
            }
            else if (temp == null || temp.Cod == 400)
            {
                MessageBox.Show("There was an error while loading temperature. Nothing to geocode. \n Code Error = 400");
                return(new TemperatureModel());
            }
            else
            {
                var result = new TemperatureModel
                {
                    DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                    Temperature = temp.Main.Temperature
                };
                return(result);
            }
        }
        public async Task <TemperatureModel> GetTempAsync()
        {
            var current = await owp.GetCurrentWeatherAsync();

            LastTemp.DateTime    = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(current.DateTime).ToLocalTime();
            LastTemp.Temperature = current.Main.Temperature;
            return(LastTemp);
        }
Exemplo n.º 8
0
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            var result = new TemperatureModel
            {
                DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                Temperature = temp.Main.Temperature
            };

            return(result);
        }
        public async Task <TemperatureModel> GetTempAsync()
        {
            ///https://github.com/dotnet/runtime/issues/23747
            var result = await owp.GetCurrentWeatherAsync();

            long longDate = result.DateTime;

            LastTemp.DateTime    = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(longDate).ToLocalTime();
            LastTemp.Temperature = result.Main.Temperature;

            return(LastTemp);
        }
        public async Task <TemperatureModel> GetTempAsync()
        {
            var weather = await owp.GetCurrentWeatherAsync();

            DateTime date1 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            LastTemp             = new TemperatureModel();
            LastTemp.DateTime    = date1.AddSeconds(weather.DateTime).ToLocalTime();
            LastTemp.Temperature = weather.Main.Temperature;

            return(LastTemp);
        }
Exemplo n.º 11
0
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            //error bubbling...
            //https://social.technet.microsoft.com/wiki/contents/articles/36836.exception-bubbling-in-c.aspx

            var result = new TemperatureModel
            {
                DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                Temperature = temp.Main.Temperature
            };

            return(result);
        }
Exemplo n.º 12
0
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            try
            {
                var result = new TemperatureModel
                {
                    DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                    Temperature = temp.Main.Temperature
                };
                return(result);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(temp.Message);
            }
        }
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            if (temp == null)
            {
                MessageBox.Show("Assurez vous d'avoir une clé valide et une ville valide");
                return(new TemperatureModel());
            }
            else
            {
                var result = new TemperatureModel
                {
                    DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                    Temperature = temp.Main.Temperature
                };

                return(result);
            }
        }
Exemplo n.º 14
0
        public async Task <TemperatureModel> GetTempAsync()
        {
            var currentweather = await owp.GetCurrentWeatherAsync();

            TemperatureModel temperature = new TemperatureModel();

            DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            temperature.DateTime = start.AddSeconds(currentweather.DateTime).ToLocalTime();

            temperature.Temperature = currentweather.Main.Temperature;

            TemperatureConverter.FahrenheitInCelsius(temperature.Temperature);

            temperature.Temperature = Math.Round(temperature.Temperature, 0);

            LastTemp = temperature;


            return(temperature);
        }
Exemplo n.º 15
0
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            var result = new TemperatureModel();

            if (temp != null)
            {
                result = new TemperatureModel
                {
                    DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                    Temperature = temp.Main.Temperature
                };
            }
            else
            {
                MessageBox.Show("La clee API ou la ville est invalide  ");
            }


            return(result);
        }
Exemplo n.º 16
0
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            var result = new TemperatureModel();

            if (temp.Cod == 400 || temp.Cod == 404)
            {
                result.Temperature = -400;
                return(result);
            }
            else if (temp.Cod == 401)
            {
                result.Temperature = -401;
                return(result);
            }
            else
            {
                result.DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime);
                result.Temperature = temp.Main.Temperature;
                return(result);
            };
        }
Exemplo n.º 17
0
        public async Task <TemperatureModel> GetTempAsync()
        {
            var temp = await owp.GetCurrentWeatherAsync();

            if (temp.Cod == 401)
            {
                MessageBox.Show("mauvais apikey");
                return(null);
            }
            else if (temp.Cod == 404 || temp.Cod == 400)
            {
                MessageBox.Show("ville non trouvé");
                return(null);
            }
            else
            {
                var result = new TemperatureModel
                {
                    DateTime    = DateTime.UnixEpoch.AddSeconds(temp.DateTime),
                    Temperature = temp.Main.Temperature
                };
                return(result);
            }
        }
Exemplo n.º 18
0
 public async Task GetCurrentWeatherAsync_IfApiHelperNotInitialized_ThrowArgumentException()
 {
     _sut = OpenWeatherProcessor.Instance;
     ApiHelper.ApiClient = null;
     await Assert.ThrowsAsync <ArgumentException>(() => _sut.GetCurrentWeatherAsync());
 }