public void WeatherLoop_SuccessfulCitySearch_DisplaysWeatherDetailsAndSavesCity() { // Assemble var cityName = "TestCity"; var stateName = "TestState"; var id = 1; var key = "ABC"; var searchCityDto = SearchCityBuilder.Build(cityName, stateName, id, key); var weatherDate = DateTime.Now; var weatherDescription = "Sunny and cloudy and rainy and dry"; var tempValue = "24"; var tempUnit = "C"; var weatherDto = CurrentWeatherBuilder.Build(weatherDescription, tempValue, tempUnit, weatherDate); _weatherClient.CitySearch(cityName).Returns(new List <SearchCityDto> { searchCityDto }); _consoleWrapper.ReadLine().Returns(cityName); _weatherClient.GetWeather(key).Returns(weatherDto); // Act _sut.WeatherLoop(); // Assert _cityDataAccess.Received(1).SaveCity(searchCityDto); _weatherClient.Received(1).GetWeather(key); _consoleWrapper.Received(1).WriteLine($"{weatherDto.LocalObservationDateTime.ToShortTimeString()} - {weatherDto.LocalObservationDateTime.ToShortDateString()}{Environment.NewLine}" + $"{weatherDto.WeatherText} {weatherDto.Temperature.Metric.Value}{weatherDto.Temperature.Metric.Unit}{Environment.NewLine}"); }
private void CitySearch(string searchString) { int cityId = 0; var isCityId = int.TryParse(searchString, out cityId); IEnumerable <SearchCityDto> results; if (isCityId) { results = _cityDataAccess.GetAllCities().Where(x => x.Id == cityId); } else { results = _weatherClient.CitySearch(searchString); } if (results.Any()) { foreach (var city in results) { _consoleWrapper.WriteLine($"City found: {city.LocalizedName}, {city.ParentCity.LocalizedName}"); _consoleWrapper.WriteLine($"Getting current weather..."); _cityDataAccess.SaveCity(city); var weatherDto = _weatherClient.GetWeather(city.Key); _consoleWrapper.WriteLine($"{weatherDto.LocalObservationDateTime.ToShortTimeString()} - {weatherDto.LocalObservationDateTime.ToShortDateString()}{Environment.NewLine}" + $"{weatherDto.WeatherText} {weatherDto.Temperature.Metric.Value}{weatherDto.Temperature.Metric.Unit}{Environment.NewLine}"); } } else { _consoleWrapper.WriteLine("No results found."); } }
public void Init() { _weatherClient = Substitute.For <IWeatherClient>(); _cityDataAccess = Substitute.For <ICityDataAccess>(); _consoleWrapper = Substitute.For <IConsoleWrapper>(); _weatherClient.CitySearch(Arg.Any <string>()).Returns(new List <SearchCityDto>()); _weatherClient.GetWeather(Arg.Any <string>()).Returns(new CurrentWeatherDto()); _cityDataAccess.GetAllCities().Returns(new List <SearchCityDto>()); _consoleWrapper.WriteLine(Arg.Any <string>()); _consoleWrapper.ReadLine().Returns(string.Empty); _sut = new FrontEndLogic(_weatherClient, _cityDataAccess, _consoleWrapper, 1); }
public async Task <WeatherForecast[]> GetForecastAsync() { return(await weatherClient.GetWeather()); }
public async Task <IEnumerable <WeatherViewModel> > Get() { var results = await _weatherClient.GetWeather(); return(_mapper.Map <List <WeatherViewModel> >(results).ToArray()); }