public async Task <IActionResult> ImportFile(IFormFile file) { ImportFileCommand command = new ImportFileCommand(); command.File = file; var result = await _mediator.Send(command); return(Redirect(GetTransactionsUrl)); }
public void ImportFileCommand_ShouldLogReceivedFile() { // Arrange var filePath = @"C:\test.json"; var command = new ImportFileCommand(_databaseMock.Object, _entityReaderMock.Object, _loggerMock.Object, _fileSystemWrapperMock.Object); // Act command.ImportEntity(@"C:\test.json"); // Assert _loggerMock.Verify(x => x.WriteLine($"Received file to import: {filePath}...")); }
public void ImportFileCommand_ShouldReadFile() { // Arrange var filePath = @"C:\test.json"; var command = new ImportFileCommand(_databaseMock.Object, _entityReaderMock.Object, _loggerMock.Object, _fileSystemWrapperMock.Object); // Act command.ImportEntity(@"C:\test.json"); // Assert _fileSystemWrapperMock.Verify(x => x.ReadFile(filePath)); }
public void ImportFileCommand_ShouldReturnImportingStatusSuccess() { // Arrange // Arrange File.WriteAllText(@"C:\test.json", _json); var command = new ImportFileCommand(); // Act var result = command.ImportEntity(@"C:\test.json"); // Assert Assert.AreEqual(ImportingStatus.Success, result); }
public void ImportFileCommand_ShouldReturnImportingStatusSuccess() { // Arrange var filePath = @"C:\test.json"; var command = new ImportFileCommand(_databaseMock.Object, _entityReaderMock.Object, _loggerMock.Object, _fileSystemWrapperMock.Object); _fileSystemWrapperMock.Setup(x => x.ReadFile(filePath)).Returns(_json); _entityReaderMock.Setup(x => x.ReadEntity(_json)).Returns(_expectedEntity); // Act var result = command.ImportEntity(@"C:\test.json"); // Assert Assert.AreEqual(ImportingStatus.Success, result); }
public void ImportFileCommand_ShouldSaveDatabase() { // Arrange var filePath = @"C:\test.json"; var command = new ImportFileCommand(_databaseMock.Object, _entityReaderMock.Object, _loggerMock.Object, _fileSystemWrapperMock.Object); _fileSystemWrapperMock.Setup(x => x.ReadFile(filePath)).Returns(_json); _entityReaderMock.Setup(x => x.ReadEntity(_json)).Returns(_expectedEntity); // Act command.ImportEntity(@"C:\test.json"); // Assert _databaseMock.Verify(x => x.SaveEntity(_expectedEntity)); }
public void ImportFileCommand_ShouldReturnImportingStatusSuccess() { // Arrange string json = @"{ ""id"": 1, ""name"": ""Test Name"", ""type"": 1 }"; File.WriteAllText(@"C:\test.json", json); var file = new FileInfo(@"C:\test.json"); var command = new ImportFileCommand(); // Act var result = command.ImportEntity(file.FullName); // Assert Assert.AreEqual(ImportingStatus.Success, result); }
public async Task <FileResult> Import(IFormFile FormFile) { //Use of the Mediatr design pattern ImportFileCommand command = new ImportFileCommand() { FormFile = FormFile }; ExportDataFile fileToExport = await Mediator.Send(command); HttpContext.Response.ContentType = fileToExport.ContentType; HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); FileResult fileContentResult = fileToExport.ExportVmToFileResult(); return(fileContentResult); }
public string ImportFile() { bool hasFiles = false; StringBuilder returnMessages = new StringBuilder(); if (_directoryReadService.ValidateDirectory()) { hasFiles = _directoryReadService.HasFiles(); } if (hasFiles) { string[] files = _directoryReadService.GetFiles(); foreach (var item in files) { string[] fileArray = item.Split("\\"); string fileName = fileArray[fileArray.Length - 1]; string[] lines = _fileReadService.GetLinesFromFile(_dirIn, fileName); var command = new ImportFileCommand() { FileName = fileName, FilePath = _dirOut, FileReader = lines, }; var result = _importFileHendler.ExecuteHendler(command); returnMessages.AppendLine($"Sucess: {result.Sucess} - Mensagem: {result.Message}"); } return(returnMessages.ToString()); } return($"Sucess: {hasFiles} - Mensagem: Arquivos Inexistentes"); }
void LibraryTreeView_MouseClick(object sender, MouseEventArgs e) { // Update library element, not undoable so no command stack ILibraryTreeNode ltn = (ILibraryTreeNode)GetNodeAt(e.Location); if (ltn != null && ltn.NeedsUpdate && ltn.UpdateRectangle.Contains(e.Location)) { ltn.NeedsUpdate = false; isMouseDown = false; Rectangle r = updateHoverNode.UpdateRectangle; updateHoverNode = null; InvalidateUpdate(r); // todo: move import off the UI thread string path = MainForm.CurrentStage.WorkingFolderFull + GetNodePath((TreeNode)ltn); ImportFileCommand ifc = new ImportFileCommand(path); ifc.Execute(); ltn.ResetDate(); MainForm.CurrentLibraryView.Invalidate(); MainForm.CurrentStage.InvalidateAll(); } }