コード例 #1
0
        public async Task <IActionResult> ImportFile(IFormFile file)
        {
            ImportFileCommand command = new ImportFileCommand();

            command.File = file;
            var result = await _mediator.Send(command);

            return(Redirect(GetTransactionsUrl));
        }
コード例 #2
0
        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}..."));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
ファイル: Example2Tests.cs プロジェクト: rsobon/TestableCode
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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");
        }
コード例 #10
0
        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();
            }
        }