Beispiel #1
0
        public async void GetForecast_CityIsNull_Null()
        {
            //arrange
            var param = getForecastParam();

            _cityService.Setup(x => x.GeCityByName(It.IsAny <string>())).Returns((Models.ForecastService.City)null);
            //act
            var result = await _forecastService.GetForecast(param);

            //assert
            Assert.IsNull(result);
        }
 public async Task <WeatherForecast> Handle(GetForecastByZipQuery request, CancellationToken cancellationToken)
 => await _forecastService.GetForecast(_weatherClient.GetForecastByZipcode,
                                       _weatherClient.GetCurrentWeatherByCity,
                                       request.Zipcode,
                                       request.Country,
                                       request.Unit
                                       );
        public void Get_Forecast_Verify_Current_Weather_Mapper_Call()
        {
            _mockMapper.Setup(x => x.Map <WeatherForecast>(_mockWeatherForecastResponse)).Returns(new WeatherForecast
            {
                DailyForecasts = new List <ForecastDetails>()
            });

            _forecastService = new ForecastService(_openWeatherMapConfig, _mockMapper.Object);

            _mockGetForecastFunc.Setup(x => x.Invoke(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(_mockWeatherForecastResponse));

            _mockGetCurrentWeatherFunc.Setup(x => x.Invoke(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(_mockCurrentWeatherResponse));

            var response = _forecastService.GetForecast(_mockGetForecastFunc.Object,
                                                        _mockGetCurrentWeatherFunc.Object,
                                                        It.IsAny <string>(),
                                                        It.IsAny <string>(),
                                                        It.IsAny <string>());


            _mockGetForecastFunc.Verify(x => x.Invoke(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            _mockGetCurrentWeatherFunc.Verify(x => x.Invoke(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);

            _mockMapper.Verify(x => x.Map <WeatherForecast>(It.IsAny <WeatherForecastResponse>()), Times.Once);
            _mockMapper.Verify(x => x.Map <ForecastDetails>(It.IsAny <CurrentWeatherResponse>()), Times.Once);
            Assert.IsNull(response.Result);
        }
Beispiel #4
0
        public static Forecast GetForecastByIP(string ipAddress, IForecastService forecastService)
        {
            var client = new RestClient("http://ip-api.com");

            var request = new RestRequest($"/json/{ipAddress}", Method.GET);

            var response = client.Execute <IpApiResponse>(request);

            return(forecastService.GetForecast(response.Data.Lat, response.Data.Lon));
        }
        public async Task <string> GetForecast([FromUri] ForecastParam param)
        {
            if (param == null)
            {
                return(null);
            }
            var result = await _forecastService.GetForecast(param);

            return(JsonConvert.SerializeObject(result));
        }
        /// <summary>
        /// Load forecasts
        /// </summary>
        public List <Forecast> GetForecast(int cityId, DateTime targetDate)
        {
            var forecasts = ServiceChannel.GetForecast(cityId, targetDate);

            if (!forecasts.Any())
            {
                return(new List <Forecast>(0));
            }

            return(forecasts);
        }
        public void Get_Forecast_Verify_Forecast_Func_Call()
        {
            _forecastService = new ForecastService(_openWeatherMapConfig, _mockMapper.Object);

            _mockGetForecastFunc.Setup(x => x.Invoke(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(It.IsAny <WeatherForecastResponse>()));

            var response = _forecastService.GetForecast(_mockGetForecastFunc.Object,
                                                        It.IsAny <Func <string, string, string, Task <CurrentWeatherResponse> > >(),
                                                        It.IsAny <string>(),
                                                        It.IsAny <string>(),
                                                        It.IsAny <string>());

            _mockGetForecastFunc.Verify(x => x.Invoke(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            Assert.IsNull(response.Result);
        }
Beispiel #8
0
        public IHttpActionResult Get([FromUri] decimal latitude, [FromUri] decimal longitude)
        {
            var clientIp = HttpContext.Current.Request.UserHostAddress;

            var ipLocationForecast = RequestHelper.GetForecastByIP(clientIp, _forecastService);

            ipLocationForecast.Description = "Prognoza za lokaciju na osnovu IP adrese";

            var forecastOnLocationSentByUser = _forecastService.GetForecast(latitude, longitude);

            forecastOnLocationSentByUser.Description = $"Prognoza za lokaciju: latidute: {latitude}, longitude: {longitude}";

            return(Json(new List <Forecast> {
                ipLocationForecast, forecastOnLocationSentByUser
            }));
        }
        public void Get_Forecast_Verify_Response()
        {
            _forecastService = new ForecastService(_openWeatherMapConfig, _mapper);

            _mockGetForecastFunc.Setup(x => x.Invoke(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(_mockWeatherForecastResponse));

            _mockGetCurrentWeatherFunc.Setup(x => x.Invoke(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(_mockCurrentWeatherResponse));

            var response = _forecastService.GetForecast(_mockGetForecastFunc.Object,
                                                        _mockGetCurrentWeatherFunc.Object,
                                                        It.IsAny <string>(),
                                                        It.IsAny <string>(),
                                                        It.IsAny <string>());

            Assert.IsInstanceOfType(response.Result, typeof(WeatherForecast));
            Assert.AreEqual(_mockWeatherForecastResponse.CityData.Name, response.Result.City);
            Assert.AreEqual(_mockWeatherForecastResponse.CityData.Country, response.Result.Country);
            Assert.IsTrue(response.Result.DailyForecasts.Count > 0);
        }
        public virtual async Task <Forecast> GetForecast(float latitude, float longitude)
        {
            var forecast = await _forecastContext.Forecasts.FirstOrDefaultAsync(f => f.Latitude == latitude &&
                                                                                f.Longitude == longitude);

            if (forecast != null && forecast.Date.Date != DateTime.Today)
            {
                _forecastContext.Forecasts.Remove(forecast);
                await _forecastContext.SaveChangesAsync();

                forecast = null;
            }

            if (forecast == null)
            {
                forecast = await _forecastService.GetForecast(latitude, longitude);

                _forecastContext.Forecasts.Add(forecast);
                await _forecastContext.SaveChangesAsync();
            }

            return(forecast);
        }
 public async Task <ForecastGroupModel> GetForecast(int cityId)
 {
     return(await _forecastService.GetForecast(cityId));
 }
 public ActionResult <IEnumerable <Forecast> > GetForecast([FromQuery] int days, [FromQuery] string[] stations)
 {
     return(new ActionResult <IEnumerable <Forecast> >(forecastService.GetForecast(days, stations)));
 }
 public ActionResult <WeatherForecast[]> GetWeatherForecasts()
 {
     return(_forecastService.GetForecast());
 }
 public Task <ForecastModel> GetForecast(string city, string zipCode)
 {
     return(_service.GetForecast(city, zipCode));
 }
 public async Task OnGet()
 {
     ViewData["ApiResult"] = await _forecastService.GetForecast();
 }
Beispiel #16
0
        public async Task <IActionResult> Get([FromQuery] string cityCode)
        {
            var response = await _forecastService.GetForecast(cityCode);

            return(new JsonResult(response));
        }