public async Task WeatherService_WhenCalled_CallsTheRepositoryAndGetsData()
        {
            var result = await _weatherService.GetWeatherForCityAsync(It.IsAny <Int32>(), It.IsAny <string>(), It.IsAny <string>());

            _mockWeatherRepository.Verify(x => x.GetWeatherForCityAsync(It.IsAny <Int32>(), It.IsAny <string>(), It.IsAny <string>()));
            Assert.IsNotNull(result);
        }
        public async Task <IActionResult> GetWeatherForCitiesAsync(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return(BadRequest("File not selected"));
            }

            ICsvFileHelper csvHelper = new CsvFileHelper();
            IEnumerable <WeatherRecord> weatherRecords;
            List <WeatherDetails>       weatherDetails = new List <WeatherDetails>();
            string csvFilepath = string.Empty;
            string strMessage  = string.Empty;

            try
            {
                //Get the list of cities
                var reader = new StreamReader(file.OpenReadStream());
                weatherRecords = csvHelper.GetRecords <WeatherRecord>(reader);

                //Get the weather for the cities
                foreach (var wr in weatherRecords)
                {
                    var weather = await _cityWeatherService.GetWeatherForCityAsync(wr.CityId, _weatherSettings.Value.ApplicationId, _weatherSettings.Value.ApiUrl).ConfigureAwait(false);

                    weatherDetails.Add(weather);
                }

                //write the weather to file
                //Appending the Datetime.Ticks to ensure unique file name. Guid can also be used instead.
                csvFilepath = Path.Combine(Directory.GetCurrentDirectory(), "Files", "Weather_" + DateTime.Now.Ticks.ToString() + ".csv");
                if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Files")))
                {
                    Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "Files"));
                }
                csvHelper.WriteRecords <WeatherDetails>(csvFilepath, weatherDetails);
                strMessage = "Successfully written to " + csvFilepath;
            }
            catch (Exception ex)
            {
                strMessage = "Operation failed with error:" + ex.Message;
            }
            return(Ok(strMessage));
        }