public ActionResult Index(HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { try { if (Path.GetExtension(file.FileName)?.Substring(1) != "csv") { ViewBag.Message = "Please upload a file of type CSV."; return(View()); } string inputContent; using (var inputStreamReader = new StreamReader(file.InputStream)) { inputContent = inputStreamReader.ReadToEnd(); } ViewBag.Message = LabFunctions.GetLeader(inputContent); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message; } } else { ViewBag.Message = "You have not specified a file."; } return(View()); }
public void AssertThatOneIsReturned() { // Arrange var fileContentString = "2,3,4,5,6,2,2,2,2,2,2,2,2"; // Act var result = LabFunctions.GetLeader(fileContentString); // Assert Assert.AreSame(result, "1"); }
public void AssertThatNullMessageReturnedWhenfileContentStringIsNull() { // Arrange string fileContentString = null; // Act var result = LabFunctions.GetLeader(fileContentString); // Assert Assert.AreSame(result, "String is null"); }