Exemplo n.º 1
0
        public async Task RefreshCurrentWeather_Success()
        {
            double lat             = 0;
            double lon             = 0;
            var    expectedWeather = new LocationWeather();

            mockLocationService.Setup(s => s.GetCurrentLocation())
            .ReturnsAsync((lat, lon));

            mockWeatherService.Setup(s => s.GetWeatherForLocation(lat, lon))
            .ReturnsAsync(expectedWeather, TimeSpan.FromMilliseconds(50));

            Assert.IsFalse(vm.IsBusy);
            Assert.IsNull(vm.CurrentWeather);

            var refreshTask = vm.RefreshCurrentWeatherCommand.ExecuteAsync();

            Assert.IsTrue(vm.IsBusy, "Should be busy while fetching weather.");

            await refreshTask;

            mockLocationService.Verify(s => s.GetCurrentLocation(), Times.Once);
            mockLocationService.VerifyNoOtherCalls();

            mockWeatherService.Verify(s => s.GetWeatherForLocation(lat, lon), Times.Once);
            mockWeatherService.VerifyNoOtherCalls();

            Assert.IsFalse(vm.IsBusy);
            Assert.AreEqual(expectedWeather, vm.CurrentWeather);
            Assert.IsEmpty(vm.Error);
        }
Exemplo n.º 2
0
        public LocationWeatherListViewModel(IWeatherService weatherService, ILocationSearchService locationSearchServiceService)
        {
            _weatherService = weatherService;
            _locationSearchServiceService = locationSearchServiceService;
            Title = "Browse Weather";
            LocationWeatherList = new ObservableCollection <LocationWeather>();
            LoadItemsCommand    = new Command(async() => await ExecuteLoadLocationListFromDataStoreCommandAsync());

            RemoveItemCommand = new Command <string>(async(key) => await ExecuteRemoveItemFromDataStoreCommandAsync(key));

            MessagingCenter.Subscribe <SearchLocationListPage, Location>(this, "AddItem", async(obj, location) =>
            {
                var weatherList     = await _weatherService.GetCurrentWeatherByLocationAsync(location.Key);
                var locationWeather = new LocationWeather
                {
                    Location       = location,
                    CurrentWeather = weatherList.FirstOrDefault()
                };

                var locationIsPresented = LocationWeatherList.Any(lw => lw?.Location?.Key == location.Key);
                if (!locationIsPresented)
                {
                    LocationWeatherList.Add(locationWeather);
                }

                await _locationSearchServiceService.AddLocationAsync(location);
            });
        }
Exemplo n.º 3
0
        public async Task <object> Get(string location)
        {
            try
            {
                var httpClient = clientFactory.CreateClient();

                var httpReq = new Uri($"https://api.openweathermap.org/data/2.5/weather?q={location}&appid={apiKey}&units=metric");
                var httpRes = await httpClient.GetAsync(httpReq);

                var responseData = await httpRes.Content.ReadAsStringAsync();

                LocationWeather locWeatherData = JsonSerializer.Deserialize <LocationWeather>(responseData);

                switch (Convert.ToInt32(httpRes.StatusCode))
                {
                case 404:
                    return(new Exception("404"));

                case 200:
                    return(locWeatherData);

                default:
                    return(new Exception("400"));
                }
            } catch (HttpRequestException exception)
            {
                return(exception);
            }
        }
        public void LoadItemsCommand_ServicesReternsLocationWeather_AddReternedByServicesToLocationWeatherList()
        {
            var locationWeather = new LocationWeather
            {
                Location       = _locationKyiv,
                CurrentWeather = _weather
            };

            _locationSearchServiceMoc
            .Setup(service => service.GetLocationList())
            .Returns(new List <Location>
            {
                _locationKyiv
            });

            _weatherServiceMoc
            .Setup(service => service.GetCurrentWeatherByLocationAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <Weather>
            {
                _weather
            });


            var locationWeatherListViewModel = new LocationWeatherListViewModel(_weatherServiceMoc.Object, _locationSearchServiceMoc.Object);

            locationWeatherListViewModel.LoadItemsCommand.Execute(null);
            var locationWeatherListResult = locationWeatherListViewModel.LocationWeatherList;

            Assert.AreEqual(locationWeather.Location, locationWeatherListResult.FirstOrDefault()?.Location);
            Assert.AreEqual(locationWeather.CurrentWeather, locationWeatherListResult.FirstOrDefault()?.CurrentWeather);
        }
Exemplo n.º 5
0
        public static int GetWeather(GameLocation location)
        {
            // special case: day events override weather in the valley
            if (!(location is IslandLocation))
            {
                if (Utility.isFestivalDay(Game1.dayOfMonth, Game1.currentSeason) || (SaveGame.loaded?.weddingToday ?? Game1.weddingToday))
                {
                    return(Game1.weather_sunny);
                }
            }

            // get from weather data
            LocationWeather model = Game1.netWorldState.Value.GetWeatherForLocation(location.GetLocationContext());

            if (model != null)
            {
                if (model.isSnowing.Value)
                {
                    return(Game1.weather_snow);
                }
                if (model.isRaining.Value)
                {
                    return(model.isLightning.Value ? Game1.weather_lightning : Game1.weather_rain);
                }
                if (model.isDebrisWeather.Value)
                {
                    return(Game1.weather_debris);
                }
            }
            return(Game1.weather_sunny);
        }
Exemplo n.º 6
0
 public LocationWeather GetWeatherForLocation(int location_context)
 {
     if (!locationWeather.ContainsKey(location_context))
     {
         locationWeather[location_context] = new LocationWeather();
     }
     return(locationWeather[location_context]);
 }
Exemplo n.º 7
0
 public void CopyFrom(LocationWeather other)
 {
     isRaining.Value          = other.isRaining.Value;
     isSnowing.Value          = other.isSnowing.Value;
     isLightning.Value        = other.isLightning.Value;
     bloomDay.Value           = other.bloomDay.Value;
     isDebrisWeather.Value    = other.isDebrisWeather.Value;
     weatherForTomorrow.Value = other.weatherForTomorrow.Value;
 }
Exemplo n.º 8
0
        /// <summary>Initializes a new instance of the <see cref="T:OregonTrailDotNet.Entity.Location.Location" /> class.</summary>
        /// <param name="name">Display name of the location as it should be known to the player.</param>
        /// <param name="climateType">Defines the type of weather the location will have overall.</param>
        protected Location(string name, Climate climateType)
        {
            // Default warning message for the location is based on fresh water status.
            Warning = GameSimulationApp.Instance.Random.NextBool() ? LocationWarning.None : LocationWarning.BadWater;

            // Creates a new system to deal with the management of the weather for this given location.
            _weather = new LocationWeather(climateType);

            // Name of the point as it should be known to the player.
            Name = name;

            // Default location status is not visited by the player or vehicle.
            Status = LocationStatus.Unreached;
        }
Exemplo n.º 9
0
        public async Task GetWeatherForLocation()
        {
            double lat         = 0;
            double lon         = 0;
            var    expectedUrl = WeatherService.WeatherForLocationUrl(lat, lon);

            var expectedResult = new LocationWeather();

            mockRequestProvider.Setup(s => s.GetAsync <LocationWeather>(expectedUrl))
            .ReturnsAsync(expectedResult);

            var result = await service.GetWeatherForLocation(0, 0);

            mockRequestProvider.Verify(s => s.GetAsync <LocationWeather>(expectedUrl), Times.Once);
            mockRequestProvider.VerifyNoOtherCalls();

            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 10
0
        private async Task RefreshLocationWeatherList()
        {
            LocationWeatherList.Clear();
            var locationList = _locationSearchServiceService.GetLocationList();

            foreach (var location in locationList)
            {
                var weatherList = await _weatherService.GetCurrentWeatherByLocationAsync(location.Key);

                var locationWeather = new LocationWeather
                {
                    Location       = location,
                    CurrentWeather = weatherList.FirstOrDefault()
                };

                LocationWeatherList.Add(locationWeather);
            }
        }
        async Task ExecuteLoadLocationListFromDataStoreCommandAsync()
        {
            await ExecuteCommandAsync(async() =>
            {
                LocationWeatherList.Clear();
                var locationList = await _locationSearchServiceService.GetItemListAsync(true);
                foreach (var location in locationList)
                {
                    var weatherList     = await _weatherService.GetCurrentWeatherByLocationAsync(location.Key);
                    var locationWeather = new LocationWeather
                    {
                        Location       = location,
                        CurrentWeather = weatherList.FirstOrDefault()
                    };

                    LocationWeatherList.Add(locationWeather);
                }
            });
        }
Exemplo n.º 12
0
        public static List <WeatherDto> ToWeatherDtoList(this LocationWeather locationWeather)
        {
            if (locationWeather.list == null)
            {
                return(new List <WeatherDto>());
            }
            var grouped     = locationWeather.list.GroupBy(n => n.Day).Take(5);
            var weatherDtos = new List <WeatherDto>();
            var locale      = locationWeather.city.name;
            var localeId    = locationWeather.city.id;

            foreach (var list in grouped)
            {
                var rootItem   = list.First();
                var weatherDto = new WeatherDto
                {
                    WeatherDay  = rootItem.Day.ToString("ddd dd-MMM-yy"),
                    Locale      = locale,
                    LocaleId    = localeId,
                    TimeFetched = DateTimeOffset.Now
                };

                var details = list.Select(x => new TimedWeatherDetail()
                {
                    Temperature      = x.main.temp,
                    Humidity         = x.main?.humidity,
                    Wind             = x.wind?.speed,
                    WindDirection    = x.wind?.deg,
                    ShortDescription = x.weather?.FirstOrDefault()?.description,
                    DayTime          = x.DateTimeOffset,
                    Precipitation    = x.snow?.ThreeHourVolume,
                }).ToArray();

                weatherDto.TimedWeatherDetail = details;
                weatherDtos.Add(weatherDto);
            }

            return(weatherDtos);
        }
Exemplo n.º 13
0
        public async void GetWeather(LocationWeather location)
        {
            WeatherData weather = await WeatherModelView.GetWeather(location.Lat, location.Lon);

            location.Temperature = weather.main.temp.ToCelsius();
        }