Exemplo n.º 1
0
        public void Execute_Target_File_Readonly_User_Asked_To_Confirm()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Folder).Return(@"c:\source");
            sourceFile.Stub(s => s.FileName).Return("File1");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(f => f.Exists()).Return(true);
            targetFile.Stub(f => f.GetAttributes()).Return(FileAttributes.ReadOnly);

            Boolean  responseRequested = false;
            ICommand testCopyCommand   = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.AskUser += (question, options) =>
            {
                responseRequested = true;
                return(System.Windows.Forms.DialogResult.OK);
            };

            testCopyCommand.Execute();

            Assert.IsTrue(responseRequested);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles saving the file and moving it to the correct place
        /// </summary>
        /// <param name="command">The command</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns></returns>
        public async Task <SaveIntegrationExportFileCommandResult> Handle(
            SaveIntegrationExportFileCommand command,
            CancellationToken cancellationToken)
        {
            Argument.NotNull(command, nameof(command));

            var commandResult = new SaveIntegrationExportFileCommandResult();

            var factoryCommand = new SaveIntegrationExportFileFactoryCommand
            {
                IntegrationExportId     = command.IntegrationExportId,
                IntegrationFolder       = command.DestinationFolder,
                FileName                = command.FileName,
                IntegrationBackupFolder = command.BackupFolder,
            };

            var factoryResult = _factory.Create(factoryCommand);

            var writeFileCommand = new WriteFileFromStreamCommand
            {
                File     = command.File,
                FileName = factoryResult.DownloadFileName,
                Path     = factoryResult.DownloadFolder,
                Size     = command.FileSize
            };

            var writeFileResult = await _writeFileHandler
                                  .Handle(writeFileCommand, cancellationToken)
                                  .ConfigureAwait(Await.Default);

            if (writeFileResult.Result == WriteFileFromStreamCommandResultKind.Success)
            {
                var moveFileCommand = new MoveFileCommand
                {
                    Source      = factoryResult.DownloadPath,
                    Destination = factoryResult.IntegrationPath,
                    Overwrite   = command.Overwrite,
                    Backup      = factoryResult.BackupPath
                };

                var moveFileResult = await _moveFileHandler
                                     .Handle(moveFileCommand, cancellationToken)
                                     .ConfigureAwait(Await.Default);

                commandResult.FileOverwritten = moveFileResult.FileOverwritten;
                commandResult.BackupFileName  = factoryResult.BackupFileName;
                commandResult.BackupFileSize  = moveFileResult.BackupFileSize;
                commandResult.Result          = SaveIntegrationExportFileCommandResultKind.Success;
            }
            else
            {
                commandResult.Result = SaveIntegrationExportFileCommandResultKind.Failed;
            }

            return(commandResult);
        }
Exemplo n.º 3
0
        public void Status_should_return_status_with_both_filenames_in()
        {
            FakeFile sourceFile = new FakeFile("file1");
            FakeFile targetFile = new FakeFile("file2");

            MoveFileCommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, false);
            String          status          = testCopyCommand.UserFeedback;

            Assert.That(status.Contains("file1"));
            Assert.That(status.Contains("file2"));
        }
Exemplo n.º 4
0
        public void Execute_Target_File_Exists_When_Overwriting_Should_Check_Target_ReadOnly_Flag()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Folder).Return(@"c:\source");
            sourceFile.Stub(s => s.FileName).Return("File1");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(f => f.Exists()).Return(true);
            targetFile.Stub(f => f.GetAttributes()).Return(FileAttributes.Normal);

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.Execute();

            targetFile.AssertWasCalled(f => f.GetAttributes());
        }
Exemplo n.º 5
0
        public void Execute_source_file_should_move_to_target()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Folder).Return(@"c:\source\");
            sourceFile.Stub(s => s.FileName).Return("source");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(s => s.Folder).Return(@"c:\source\");
            targetFile.Stub(s => s.FileName).Return("target");
            targetFile.Stub(s => s.Exists()).Return(false);

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, false);

            testCopyCommand.Execute();

            sourceFile.AssertWasCalled(f => f.MoveFile(Arg <IFile> .Is.Same(targetFile)));
        }
Exemplo n.º 6
0
        public void Execute_target_file_exists_overwrite_target_should_be_overwritten()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Folder).Return(@"c:\source\");
            sourceFile.Stub(s => s.FileName).Return("source");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(s => s.Exists()).Return(true);
            targetFile.Stub(s => s.Folder).Return(@"c:\source\");
            targetFile.Stub(s => s.FileName).Return("target");

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.Execute();

            sourceFile.AssertWasCalled(f => f.MoveFile(targetFile));
        }
Exemplo n.º 7
0
        public void Execute_target_file_exists_no_overwrite_copy_not_attempted()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Folder).Return(@"c:\source\");
            sourceFile.Stub(s => s.FileName).Return("source");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(s => s.Exists()).Return(true);
            targetFile.Stub(s => s.Folder).Return(@"c:\source\");
            targetFile.Stub(s => s.FileName).Return("target");

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, false);

            testCopyCommand.Execute();

            sourceFile.AssertWasNotCalled(f => f.CopyFile(Arg <IFile> .Is.Anything, Arg <Boolean> .Is.Anything));
        }
Exemplo n.º 8
0
        public void Undo_Does_nothing_if_executed_has_not_been_called_first()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Exists()).Return(false);
            sourceFile.Stub(s => s.Folder).Return(@"c:\source\");
            sourceFile.Stub(s => s.FileName).Return("source");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(s => s.Exists()).Return(true);
            targetFile.Stub(s => s.Folder).Return(@"c:\source\");
            targetFile.Stub(s => s.FileName).Return("target");

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.Undo();

            targetFile.AssertWasNotCalled(t => t.CopyFile(Arg <IFile> .Is.Anything, Arg <Boolean> .Is.Anything));
        }
Exemplo n.º 9
0
        public void Execute_target_file_exists_overwrite_specified_target_deleted()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Exists()).Return(false);
            sourceFile.Stub(s => s.Folder).Return(@"c:\source\");
            sourceFile.Stub(s => s.FileName).Return("source");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(s => s.Exists()).Return(true);
            targetFile.Stub(s => s.Folder).Return(@"c:\source\");
            targetFile.Stub(s => s.FileName).Return("target");

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.Execute();


            targetFile.AssertWasCalled(t => t.Delete());
        }
Exemplo n.º 10
0
        public void Undo_Copy_success_deletes_target_file_when_undoing()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Exists()).Return(false);
            sourceFile.Stub(s => s.Folder).Return(@"c:\source\");
            sourceFile.Stub(s => s.FileName).Return("source");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(s => s.Exists()).Return(true);
            targetFile.Stub(s => s.Folder).Return(@"c:\source\");
            targetFile.Stub(s => s.FileName).Return("target");

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.Execute();
            testCopyCommand.Undo();

            targetFile.AssertWasCalled(t => t.Delete());
        }
Exemplo n.º 11
0
        public void Undo_Does_not_copy_target_to_source_if_source_exists()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Exists()).Return(true);
            sourceFile.Stub(s => s.Folder).Return(@"c:\source\");
            sourceFile.Stub(s => s.FileName).Return("source");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(s => s.Exists()).Return(true);
            targetFile.Stub(s => s.Folder).Return(@"c:\source\");
            targetFile.Stub(s => s.FileName).Return("target");

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.Execute();

            testCopyCommand.Undo();

            targetFile.AssertWasNotCalled(x => x.CopyFile(Arg <IFile> .Is.Same(sourceFile), Arg <Boolean> .Is.Anything));
        }
Exemplo n.º 12
0
        public void Undo_Copies_target_back_to_source_when_source_does_not_exist()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Exists()).Return(false);
            sourceFile.Stub(s => s.Folder).Return(@"c:\source\");
            sourceFile.Stub(s => s.FileName).Return("source");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(s => s.Exists()).Return(true);
            targetFile.Stub(s => s.Folder).Return(@"c:\source\");
            targetFile.Stub(s => s.FileName).Return("target");

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.Execute();

            testCopyCommand.Undo();

            targetFile.AssertWasCalled(x => x.MoveFile(Arg <IFile> .Is.Same(sourceFile)));
        }
Exemplo n.º 13
0
        public void Execute_Target_File_Readonly_User_No_Read_Only_Not_Cleared_File_Is_Not_Deleted()
        {
            IFile sourceFile = MockRepository.GenerateStub <IFile>();

            sourceFile.Stub(s => s.Folder).Return(@"c:\source");
            sourceFile.Stub(s => s.FileName).Return("File1");

            IFile targetFile = MockRepository.GenerateStub <IFile>();

            targetFile.Stub(f => f.Exists()).Return(true);
            targetFile.Stub(f => f.GetAttributes()).Return(FileAttributes.ReadOnly);

            ICommand testCopyCommand = new MoveFileCommand(sourceFile, targetFile, true);

            testCopyCommand.AskUser += (question, options) =>
            {
                return(System.Windows.Forms.DialogResult.No);
            };

            testCopyCommand.Execute();

            targetFile.AssertWasNotCalled(t => t.Delete());
        }