public void MovedWithMoveStringsInRightOrder() { var mock = new Mock <IRobot>(MockBehavior.Strict); mock.Setup(r => r.Initialize(new Point(10, 22))); var processor = new InputFileProcessor("./fixtures/input1.txt", mock.Object); var seq = new MockSequence(); mock.InSequence(seq).Setup(m => m.Move(MoveDirection.E, 2)); mock.InSequence(seq).Setup(m => m.Move(MoveDirection.N, 1)); processor.process(); }
public async Task <IActionResult> UploadFileAsync(FileModel file) { var result = new ResultModel(); // check if file is empty if (file.FileUpload.FileData == null || file.FileUpload.FileData.Length <= 0) { result.ErrorMessage = "Empty file"; return(View("Index", result)); } // check if file is a ".txt" file - task requirement if (!Path.GetExtension(file.FileUpload.FileData.FileName).Equals(".txt", StringComparison.OrdinalIgnoreCase)) { result.ErrorMessage = "File should be .txt"; return(View("Index", result)); } try { // download file in temp location var filePath = Path.GetTempFileName(); using (var stream = new FileStream(filePath, FileMode.Create)) { await file.FileUpload.FileData.CopyToAsync(stream); } // process uploaded file - use temporary saved location var inputFileProcessor = new InputFileProcessor(); result.employeesCouples = inputFileProcessor.ProcessFile(filePath); } catch (InvalidDataException ex) { result.ErrorMessage = "Incorrect data in file. Error while parsing."; return(View("Index", result)); } catch (Exception ex) { result.ErrorMessage = "Oops. Something went wrong on server side."; return(View("Index", result)); } return(View("Index", result)); }
public InputFileProcessor_input1() { mock = new Mock <IRobot>(); processor = new InputFileProcessor("./fixtures/input1.txt", mock.Object); }