Ejemplo n.º 1
0
        public async Task <ViewResult> Index(WeatherInputModel inputModel)
        {
            if (ModelState.IsValid)
            {
                HttpResponseMessage reponse = await _openWeatherHttpService.SendRequest(_serviceUrl, inputModel.Country, inputModel.City);

                if (reponse.StatusCode == HttpStatusCode.BadRequest)
                {
                    return(View("Error", new ErrorModel {
                        Input = inputModel, Message = Resources.InvalidInputData
                    }));
                }

                if (!reponse.IsSuccessStatusCode)
                {
                    return(View("Error", new ErrorModel {
                        Input = inputModel, Message = Resources.UnexpectedError
                    }));
                }

                WeatherDetails weather = await _openWeatherHttpService.GetData(reponse.Content);

                WeatherDetailsModel model = Mapper.Map <WeatherDetailsModel>(weather);
                model.ShowDetails = true;

                return(View("Details", model));
            }

            return(View(inputModel));
        }
Ejemplo n.º 2
0
        public async Task WhenISubmitTheForm()
        {
            //Get data from Web.API
            _response = await _weatherService.SendRequest(_webApiUrl, _country, _city);

            if (_response == null || _response.StatusCode != HttpStatusCode.OK)
            {
                ScenarioContext.Current.Pending();
            }
        }