private CurrentWeather MapCurrentConditionsResponse(CurrentConditionsResponse openWeatherApiResponse)
        {
            var currentConditions = new CurrentWeather()
            {
                Success      = true,
                ErrorMessage = String.Empty,
                Location     = new CurrentWeather.LocationData()
                {
                    Name      = openWeatherApiResponse.Name,
                    Latitude  = openWeatherApiResponse.Coordintates.Latitude,
                    Longitude = openWeatherApiResponse.Coordintates.Longitude
                },
                ObservationTime    = DateTimeOffset.FromUnixTimeSeconds(openWeatherApiResponse.ObservationTime + openWeatherApiResponse.TimezoneOffset).DateTime,
                ObservationTimeUtc = DateTimeOffset.FromUnixTimeSeconds(openWeatherApiResponse.ObservationTime).DateTime,
                CurrentConditions  = new CurrentWeather.WeatherData()
                {
                    Conditions            = openWeatherApiResponse.ObservedConditions.FirstOrDefault()?.Conditions,
                    ConditionsDescription = openWeatherApiResponse.ObservedConditions.FirstOrDefault()?.ConditionsDetail,
                    Visibility            = openWeatherApiResponse.Visibility / 1609.0, // Visibility always comes back in meters, even when imperial requested
                    CloudCover            = openWeatherApiResponse.Clouds.CloudCover,
                    Temperature           = openWeatherApiResponse.ObservationData.Temperature,
                    Humidity             = openWeatherApiResponse.ObservationData.Humidity,
                    Pressure             = openWeatherApiResponse.ObservationData.Pressure * 0.0295301, // Pressure always comes back in millibars, even when imperial requested
                    WindSpeed            = openWeatherApiResponse.WindData.Speed,
                    WindDirection        = CompassDirection.GetDirection(openWeatherApiResponse.WindData.Degrees),
                    WindDirectionDegrees = openWeatherApiResponse.WindData.Degrees,
                    RainfallOneHour      = (openWeatherApiResponse.Rain?.RainfallOneHour ?? 0.0) * 0.03937008
                },
                FetchTime = DateTime.Now
            };

            return(currentConditions);
        }
示例#2
0
        public void CheckBoundaryBearingsReturCorrectDirectionForIntercardinalDirections(double bearing, string expectedDirection)
        {
            // Act
            var direction = CompassDirection.GetDirection(bearing);

            // Assert
            direction.Abbreviation.Should().Be(expectedDirection,
                                               $"Expected direction of {expectedDirection} but got {direction.Abbreviation} for bearing {bearing}");
        }
示例#3
0
        public void CheckBearingsResultInCorrectCompassDirection(double bearing, string expectedDirection)
        {
            // Act
            var direction = CompassDirection.GetDirection(bearing);

            // Assert
            direction.Abbreviation.Should().Be(expectedDirection,
                                               $"Expected direction of {expectedDirection} but got {direction.Abbreviation} for bearing {bearing}");
        }
    private LocationForecast MapForecastResponse(ForecastResponse openWeatherApiResponse)
    {
        var locationForecast = new LocationForecast()
        {
            Success      = true,
            ErrorMessage = String.Empty,
            Location     = new ForecastLocation()
            {
                Name      = openWeatherApiResponse.Location.Name,
                Latitude  = openWeatherApiResponse.Location.Coordinates.Latitude,
                Longitude = openWeatherApiResponse.Location.Coordinates.Longitude
            },
            FetchTime = DateTime.Now
        };

        foreach (var openWeatherForecast in openWeatherApiResponse.ForecastPoints)
        {
            WeatherForecast forecast = new()
            {
                Conditions            = openWeatherForecast.Conditions.FirstOrDefault()?.main,
                ConditionsDescription = openWeatherForecast.Conditions.FirstOrDefault()?.description,
                Temperature           = openWeatherForecast.WeatherData.Temperature,
                Humidity             = openWeatherForecast.WeatherData.Humidity,
                Pressure             = openWeatherForecast.WeatherData.pressure * 0.0295301, // Pressure always comes back in millibars, even when imperial requested,
                ForecastTime         = DateTimeOffset.FromUnixTimeSeconds(openWeatherForecast.Date + openWeatherApiResponse.Location.TimezoneOffset).DateTime,
                CloudCover           = openWeatherForecast.Clouds.CloudCover,
                WindSpeed            = openWeatherForecast.Wind.WindSpeed,
                WindDirectionDegrees = openWeatherForecast.Wind.WindDirectionDegrees,
                WindDirection        = CompassDirection.GetDirection(openWeatherForecast.Wind.WindDirectionDegrees),
                ExpectedRainfall     = (openWeatherForecast.Rain?.RainfallThreeHours ?? 0.0) * 0.03937008,
                ExpectedSnowfall     = (openWeatherForecast.Snow?.SnowfallThreeHours ?? 0.0) * 0.03937008
            };

            locationForecast.Forecasts.Add(forecast);
        }

        return(locationForecast);
    }
示例#5
0
 public void GetDirectionThrowsExceptionWhenIllegalBearingPassedIn(double bearing)
 {
     // Act And Assert
     Assert.Throws <ArgumentException>(() => CompassDirection.GetDirection(bearing));
 }