public void SampleDataFromApiTest()
        {
            var currentWeather = new CurrentWeather("http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1");
            var actual         = currentWeather.Data;

            var expected = new CurrentWeatherData();

            expected.Coord   = new Coordinates(-0.13, 51.51);
            expected.Weather = new List <Weather>
            {
                new Weather(300, "Drizzle", "light intensity drizzle", "09d")
            };
            expected.Base       = "stations";
            expected.Main       = new Main(280.32f, 1012, 81, 279.15f, 281.15f, 0, 0);
            expected.Visibility = 10000;
            expected.Wind       = new Wind(4.1f, 80);
            expected.Clouds     = new Clouds(90);
            expected.Dt         = 1485789600;
            expected.Sys        = new Sys(1, 5091, 0.0103f, "GB", 1485762037, 1485794875);
            expected.Id         = 2643743;
            expected.Name       = "London";
            expected.Cod        = 200;

            actual.ShouldDeepEqual(expected);
        }
Esempio n. 2
0
        public async void GetCurrentWeather_Valid()
        {
            var owmProvider    = Substitute.For <IOWMProvider>();
            var currentWeather = new CurrentWeatherData()
            {
                Timestamp            = new DateTime(2020, 07, 22, 18, 47, 01, DateTimeKind.Utc),
                Sunrise              = new DateTime(2020, 07, 22, 18, 47, 01, DateTimeKind.Utc),
                Sunset               = new DateTime(2020, 07, 22, 18, 47, 01, DateTimeKind.Utc),
                Temperature          = 20.3f,
                TemperatureFeelsLike = 19.72f,
                Pressure             = 971,
                Humidity             = 80,
                UVIndex              = 4.7f,
                Clouds               = 29,
                Visibility           = 8000,
                WindSpeed            = 100,
                WindDirection        = 300,
                Weather              = new WeatherCondition
                {
                    Description = "Many clouds!",
                    IconId      = "10d"
                }
            };

            owmProvider.GetCurrentWeatherAsync().Returns(Task.FromResult(currentWeather));
            var controller = new WeatherController(owmProvider);

            var result = await controller.GetCurrentWeather();

            var okResult      = Assert.IsType <OkObjectResult>(result.Result);
            var resultWeather = Assert.IsType <CurrentWeatherData>(okResult.Value);

            Assert.Equal(currentWeather, resultWeather);
        }
 public void Display(CurrentWeatherData meteorologicData)
 {
     Console.WriteLine("Current conditions are: ");
     Console.WriteLine($"-> Atmosferic Pressure: {meteorologicData.Pressure}");
     Console.WriteLine($"-> Temperature: {meteorologicData.Temperature}");
     Console.WriteLine($"-> Humidity: {meteorologicData.Humidity}");
 }
Esempio n. 4
0
 public WeatherForecastController(ILogger <WeatherForecastController> logger, IConfiguration configuration,
                                  CurrentWeatherData currentWeatherData, EmailService emailService, CityList cityList)
 {
     _logger             = logger;
     _configuration      = configuration;
     _currentWeatherData = currentWeatherData;
     _emailService       = emailService;
     _cityList           = cityList;
 }
Esempio n. 5
0
        private void GetCurrentWeather()
        {
            string weather_request =
                "http://api.openweathermap.org/data/2.5/weather?q="
                + ComboCity.Text
                + "&units=metric&APPID=ea476663b316d6c0007c1bcce2703954";

            currentData = GetWeatherData.GetCurrentWeatherData(weather_request);
        }
Esempio n. 6
0
        public async void GetCurrentWeather_DataNull()
        {
            var owmProvider = Substitute.For <IOWMProvider>();
            CurrentWeatherData currentWeather = null;

            owmProvider.GetCurrentWeatherAsync().Returns(Task.FromResult(currentWeather));
            var controller = new WeatherController(owmProvider);

            var result = await controller.GetCurrentWeather();

            Assert.IsType <NotFoundResult>(result.Result);
        }
Esempio n. 7
0
        public void NotifyObservers()
        {
            var data = _wheaterGetterService
                       .GetCurrentWheaterInformation();

            if (_currentMeteorologicData != null && _currentMeteorologicData.IsSameAs(data))
            {
                return;
            }

            _currentMeteorologicData = data;

            _observers.ForEach(observer =>
                               observer.Update(_currentMeteorologicData));
        }
Esempio n. 8
0
 private bool CompareCurrentData(CurrentWeatherData currentWeatherData, CurrentWeatherResponse response)
 {
     return
         // station
         (currentWeatherData.Station.Latitude == response.lat &&
          currentWeatherData.Station.Longitude == response.lon &&
          currentWeatherData.Station.AltitudeF == response.alt_ft &&
          currentWeatherData.Station.AltitudeM == response.alt_m
          // weather
          && string.Equals(currentWeatherData.Weather.Description, response.wx_desc) &&
          currentWeatherData.Weather.Code == response.wx_code
          //&& string.Equals(currentWeatherData.Weather.Icon, response.wx_icon)
          // temperature
          && currentWeatherData.Temperature.Celcius == response.temp_c &&
          currentWeatherData.Temperature.Fahrenheit == response.temp_f
          // feelslike temperature
          && currentWeatherData.FeelsLikeTemperature.Celcius == response.feelslike_c &&
          currentWeatherData.FeelsLikeTemperature.Fahrenheit == response.feelslike_f
          // wind
          && currentWeatherData.Wind.Speed.Mph == response.windspd_mph &&
          currentWeatherData.Wind.Speed.Kmh == response.windspd_kmh &&
          currentWeatherData.Wind.Speed.Kts == response.windspd_kts &&
          currentWeatherData.Wind.Speed.Ms == response.windspd_ms &&
          currentWeatherData.Wind.DirectionDeg == response.winddir_deg &&
          string.Equals(currentWeatherData.Wind.DirectionCompass, response.winddir_compass)
          // humidity
          && currentWeatherData.Humidity == response.humid_pct
          // cloudtotal
          && currentWeatherData.CloudTotal == response.cloudtotal_pct
          // visibility
          && currentWeatherData.Visibility.Kilometers == response.vis_km &&
          currentWeatherData.Visibility.Miles == response.vis_mi
          // pressure
          && currentWeatherData.Pressure.Inches == response.slp_in &&
          currentWeatherData.Pressure.Millibars == response.slp_mb
          // dewpoint
          && currentWeatherData.DewPoint.Celcius == response.dewpoint_c &&
          currentWeatherData.DewPoint.Fahrenheit == response.dewpoint_f);
 }
 public bool IsSameAs(CurrentWeatherData otherData) =>
 Temperature == otherData.Temperature &&
 Humidity == otherData.Humidity &&
 Pressure == otherData.Pressure;
 public void Update(CurrentWeatherData meteorologicData)
 {
     Console.WriteLine("=========================================");
     Console.WriteLine("The weather information has been Updated!");
     Display(meteorologicData);
 }