コード例 #1
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));
        }
コード例 #2
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));
        }
コード例 #3
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));
        }
コード例 #4
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());
        }