public IActionResult Index(int id) { var file = _csvLoader.GetFileById(id); string outputFileName = _csvOutput.GetOutputFileName(file.Name); return(View(new SuccessModel() { Id = file.Id, Name = file.Name, OutputFileName = outputFileName })); }
public IActionResult ProcessFile(int id) { /* * This solution assumes that this web application is running on an intranet (not the public internet) and none of the users are malicious * There is basic protection insofar as this method does not accept any string inputs * However if this were to go on the public internet, a security review might first be needed */ var file = _csvLoader.GetFileById(id); if (file == null) { throw new System.Exception("File Not Found"); } var records = _csvLoader.LoadCsvFile(_inputFilesPath + "\\" + file.Name); IncrementalValue.DefaultNullsToZeroes(records); var defects = _fileValidator.Validate(file, records); if (defects != null && defects.Errors.Any()) { return(RedirectToAction("Index", "Failure", defects)); } if (records != null) { MinAndMaxYears minAndMaxYears = new MinAndMaxYears { Minimum = records.Min(p => p.OriginYear), Maximum = records.Max(p => p.OriginYear) }; var recordsPerProduct = _recordsPerProduct.SortRecordsByProduct(records); recordsPerProduct = new MissingYears().Add(recordsPerProduct, minAndMaxYears); string outputFileName = _csvOutput.GetOutputFileName(file.Name); _csvOutput.Write(recordsPerProduct, outputFileName); } return(RedirectToAction("Index", "Success", new { id = file.Id, fileName = file.Name })); }
public void ResultContainsSuccessModel() { // Arrange int id = 1; _csvLoader.GetFileById(1).Returns(new FileModel { Id = id, Name = "test.csv" }); _csvOutput.GetOutputFileName("test.csv").Returns("testOutput.csv"); // Act var result = (ViewResult)_target.Index(id); var successModel = (SuccessModel)result.Model; // Assert Assert.That(successModel.Id, Is.EqualTo(1)); Assert.That(successModel.Name, Is.EqualTo("test.csv")); Assert.That(successModel.OutputFileName, Is.EqualTo("testOutput.csv")); }