public IActionResult Upload() { try { var file = Request.Form.Files[0]; var folderName = Path.Combine("Reports"); var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName); if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var fullPath = Path.Combine(pathToSave, fileName); var dbPath = Path.Combine(folderName, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } var content = Utilities.ReadATextFile(fullPath); var result = _cityWeather.GenerateReportCitiwise(content); return(Ok(new { dbPath, result })); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, "Internal server error")); } }
public void TestGetWithCities() { string city = "london,pune"; var respose = _cityweather.GenerateReportCitiwise(city.Split(',')); dynamic test = JsonConvert.DeserializeObject <dynamic>(respose); foreach (var item in test) { if (item.Name.Equals(item.Name + "_" + DateTime.Now.Date.ToShortDateString())) { Assert.True(true); } else { Assert.False(false); } } }