Exemple #1
0
        public WeatherInfoModel GetCurrentWeatherByLocation(decimal latitude, decimal longitude)
        {
            var weatherService = new OpenWeatherMapWeatherService(_settings.KeyPath);
            var currentWeather = weatherService.GetCurrentWeatherByLocation(latitude, longitude);

            currentWeather.UnitType         = UnitType.Fahrenheit;
            currentWeather.Temperature      = currentWeather.Temperature * 9 / 5 - 459.67m;
            currentWeather.WeatherQueryTime = DateTime.Now;

            return(currentWeather);
        }
        public void HistoricalWeather_ValidLocation_GetWeather()
        {
            // arrange
            var weatherService = new OpenWeatherMapWeatherService(_openWeatherMapKeyPath);

            // act
            var historicalWeather = weatherService.GetHistoricalWeatherByLocation(0, 0);

            // assert
            Assert.Fail("Should have thrown an exception.");
        }
        public void ForecastWeather_ValidLocation_GetWeather()
        {
            // arrange
            var weatherService = new OpenWeatherMapWeatherService(_openWeatherMapKeyPath);

            // act
            var forecastWeather = weatherService.GetForecastWeatherByLocation(0, 0);

            // assert
            Assert.That(forecastWeather.Temperature, Is.Not.EqualTo(0));
        }
        public void OpenWeatherMapWeatherServiceTests()
        {
            var service = new OpenWeatherMapWeatherService();

            var url        = "https://api.openweathermap.org/data/2.5/weather?";
            var parameters = "lat=59.94&lon=30.24&appid=";
            var key        = "e2d900011a6c02deccc3e56e7534ed32";

            typeof(OpenWeatherMapWeatherService).GetField("requestMaker", BindingFlags.Instance | BindingFlags.NonPublic)?
            .SetValue(service, new ApiRequestMaker(url, parameters, key));

            service.ShowWeather();

            Assert.IsNotNull(typeof(OpenWeatherMapWeatherService).GetField("currentWeather", BindingFlags.Instance | BindingFlags.NonPublic));
        }