public void WeatherByCityTestGood() { var request = new GetWeatherModel { City = "Warsaw", Country = "Poland" }; IWeatherService weatherService; weatherService = Substitute.For <IWeatherService>(); weatherService.GetCurrentWeather(Arg.Any <GetWeatherModel>()).Returns(new Weather.Core.Models.Responses.CurrentWeatherResponseModel { humidity = 4, location = new Weather.Core.Models.Responses.ResponseLocation { city = "Warsaw", country = "Poland" }, temperature = new Weather.Core.Models.Responses.ResponseTemperature { format = "test", value = 4 } }); WeatherController controller = new WeatherController(weatherService); var res = controller.WeatherByCity(new GetWeatherRequest { City = "Warsaw", Country = "Poland" }); Assert.IsType <OkNegotiatedContentResult <CurrentWeatherResponseModel> >(res); }
public string F5Days([FromBody()] GetWeatherModel getWeatherModel) { CreateWeatherRepo(getWeatherModel.WidgetId); var model = _weatherRepository.getF5Days(); return(model); }
public void CurrentWeatherPostFormTestGood() { var request = new GetWeatherModel { City = "Warsaw", Country = "Poland" }; IWeatherService weatherService; weatherService = Substitute.For <IWeatherService>(); weatherService.GetCurrentWeather(Arg.Any <GetWeatherModel>()).Returns(new Weather.Core.Models.Responses.CurrentWeatherResponseModel { humidity = 4, location = new Weather.Core.Models.Responses.ResponseLocation { city = "Warsaw", country = "Poland" }, temperature = new Weather.Core.Models.Responses.ResponseTemperature { format = "test", value = 4 } }); WeatherUIController controller = new WeatherUIController(weatherService); var res = controller.CurrentWeather(new GetCurrentWeather { City = "Warsaw", Country = "Poland" }); var viewResult = res as ViewResult; var viewModel = viewResult.Model as GetCurrentWeather; Assert.Equal(4, viewModel.TemperatureValue); }
public CurrentWeatherResponseModel GetCurrentWeather(GetWeatherModel model) { WeatherModel weather = weatherRepository.GetCurrentWeatherByCity(model.City); if (weather == null) { return(null); } if (model.Country.ToLower() != weather.Location.Country.ToLower()) { return(null); } CurrentWeatherResponseModel responseWeather = new CurrentWeatherResponseModel { humidity = weather.Current.Humidity, location = new ResponseLocation { city = weather.Location.Name, country = weather.Location.Country }, temperature = new ResponseTemperature { format = "Celsius", value = weather.Current.Temp_c } }; return(responseWeather); }