예제 #1
0
        public void GetWeatherForecasTest_returnErroSearch(string city, string dtInitial, string dtFinal, char unit)
        {
            FilterWeatherForecast filter = FilterSearch(city, dtInitial, dtFinal, unit);

            var result = _calculoController.GetWeatherForecast(filter);

            Assert.IsFalse(result.IsOk);
        }
예제 #2
0
        private static FilterWeatherForecast FilterSearch(string city, string dtInitial, string dtFinal, char unit)
        {
            var dtFinalArray   = dtFinal.Split('/').Select(x => int.Parse(x)).ToArray();
            var dtInitialArray = dtInitial.Split('/').Select(x => int.Parse(x)).ToArray();

            var filter = new FilterWeatherForecast()
            {
                Cities    = new string[] { city },
                Unit      = unit,
                DtFinal   = new DateTime(dtFinalArray[2], dtFinalArray[1], dtFinalArray[0]),
                DtInitial = new DateTime(dtInitialArray[2], dtInitialArray[1], dtInitialArray[0])
            };

            return(filter);
        }
예제 #3
0
        public IEnumerable <WeatherForecastDomain> GetWeatherForecast(FilterWeatherForecast filter)
        {
            try
            {
                if (!filter.HasCities)
                {
                    _msgs.ErrorList.Add("City is required.");
                }
                if (!filter.IsValidInitialDate)
                {
                    _msgs.ErrorList.Add("Initial date is invalid.");
                }
                if (!filter.IsValidFinalDate)
                {
                    _msgs.ErrorList.Add("Initial date is invalid.");
                }

                if (!_msgs.ExistError)
                {
                    var weatherForecastReturn = new List <WeatherForecastDomain>();
                    var weatherForecast       = new WeatherForecastDomain();

                    foreach (var city in filter.Cities)
                    {
                        weatherForecast = this.ReturnObject <WeatherForecastDomain>(city, _projectConfiguration.Forecast, "POST", filter.UnitText);
                        //Apply filter date
                        weatherForecast.ForecastList = weatherForecast.ForecastList.Where(x => x.Date >= filter.DtInitial.Date && x.Date <= filter.DtFinal.Date);

                        weatherForecast.ForecastCurrent = this.ReturnObject <ForecastDomain>(city, _projectConfiguration.Weather, "GET", filter.UnitText);
                        weatherForecastReturn.Add(weatherForecast);
                    }

                    return(weatherForecastReturn);
                }
            }
            catch (Exception ex)
            {
                _msgs.ErrorList.Add(string.Format("Has error: {0} ", ex.Message));
            }

            return(null);
        }