public void Status_returns_a_status_method()
        {
            IFolder target = new FakeFolder(@"c:\dest\");
            IFolder source = new FakeFolder(@"c:\dest\");
            CreateFolderLinkCommand command = new CreateFolderLinkCommand(target, source);

            Assert.IsNotEmpty(command.UserFeedback);
        }
        public void Undo_no_folder_created_no_delete_attempted()
        {
            FakeFolder folder = new FakeFolder(@"C:\testFolder");

            ICommand createFolderComand = new CreateFolderCommand(folder);
            createFolderComand.Undo();

            Assert.IsFalse(folder.DeleteFolderCalled);
        }
        public void Execute_Creates_Folder()
        {
            FakeFolder folder = new FakeFolder(@"C:\testFolder");

            ICommand createFolderComand = new CreateFolderCommand(folder);
            createFolderComand.Execute();

            Assert.IsTrue(folder.CreateFolderCalled);
        }
        public void Execute_folder_exists_no_create_called()
        {
            FakeFolder folder = new FakeFolder(@"C:\testFolder");
            folder.FolderExistsReturnValue = true;

            ICommand createFolderComand = new CreateFolderCommand(folder);
            createFolderComand.Execute();

            Assert.IsFalse(folder.CreateFolderCalled);
        }
        public void Status_return_status_with_current_folder_name_in()
        {
            String folderName = @"C:\testFolder";
            FakeFolder folder = new FakeFolder(folderName);
            folder.FolderExistsReturnValue = true;

            ICommand createFolderComand = new CreateFolderCommand(folder);
            String status = createFolderComand.UserFeedback;

            Assert.IsTrue(status.Contains(folderName));
        }
        public void Undo_created_folder_deleted()
        {
            FakeFolder folder = new FakeFolder(@"C:\testFolder");

            ICommand createFolderComand = new CreateFolderCommand(folder);

            createFolderComand.Execute();
            createFolderComand.Undo();

            Assert.IsTrue(folder.DeleteFolderCalled);
        }
        public void Undo_folder_existed_before_execute_no_delete_attempted()
        {
            FakeFolder folder = new FakeFolder(@"C:\testFolder");
            folder.FolderExistsReturnValue = true;

            ICommand createFolderComand = new CreateFolderCommand(folder);

            createFolderComand.Execute();
            createFolderComand.Undo();

            Assert.IsFalse(folder.DeleteFolderCalled);
        }
Пример #8
0
 public override bool Equals(object obj)
 {
     if (obj is FakeFolder)
     {
         FakeFolder other = obj as FakeFolder;
         return(this.FolderPath.Equals(other.FolderPath, StringComparison.CurrentCultureIgnoreCase));
     }
     else
     {
         return(base.Equals(obj));
     }
 }
        public void Execute_folder_contains_readonly_files_readonly_attribute_cleared()
        {
            FakeFolder folder = new FakeFolder(@"fakeFolder");
            folder.FolderExistsReturnValue = true;
            folder.FileList = new List<IFile>() {
                                                new FakeFile("file1") { Attributes = System.IO.FileAttributes.ReadOnly },
                                                new FakeFile("file2") { Attributes = System.IO.FileAttributes.ReadOnly },
                                                };

            ICommand command = new DeleteFolderCommand(folder);
            command.Execute();
            Assert.IsTrue(folder.FileList.TrueForAll(f => ((FakeFile)f).Attributes == System.IO.FileAttributes.Normal));
        }
        public void Execute_Folder_contains_files_files_delete_first()
        {
            FakeFolder folder = new FakeFolder(@"fakeFolder");
            folder.FolderExistsReturnValue = true;
            folder.FileList = new List<IFile>() {
                                                new FakeFile("file1"),
                                                new FakeFile("file2"),
                                                };

            ICommand deleteComand = new DeleteFolderCommand(folder);
            deleteComand.Execute();

            Assert.IsTrue(folder.FileList.TrueForAll(f => ((FakeFile)f).DeleteCalled), "Not all the files were deleted before trying to delete the folder!");
        }
        public void Execute_FolderContainsSubFoldersWithFiles_SubFolderFilesDeleted()
        {
            var folder1 = MockRepository.GenerateMock<IFolder>();
            folder1.Stub(f => f.GetSubFolderList()).Return(new List<IFolder>());
            var file = MockRepository.GenerateMock<IFile>();

            folder1.Stub(f => f.GetFileList()).Return(new List<IFile>() { file });

            FakeFolder folder = new FakeFolder(@"fakeFolder");
            folder.FolderExistsReturnValue = true;
            folder.SubFolderList = new List<IFolder>() {
                                                folder1,
                                                };

            ICommand deleteComand = new DeleteFolderCommand(folder);

            deleteComand.Execute();

            file.AssertWasCalled(f => f.Delete());
        }
        public static IFolderFactoryForPath GetFolderFactoryThatReturnsExistsFor(String folderToReturnTrueFor)
        {
            IFolderFactoryForPath folderFactory = (f) =>
            {
                var folderToReturn = new FakeFolder(f);

                folderToReturn.FolderExistsReturnValue = f.Equals(folderToReturnTrueFor);

                return folderToReturn;
            };

            return folderFactory;
        }
        public void GetCommandListForFolderTask_TargetHasSubFolderWithOneWithOverwriteFile_SubfolderAndOneIsMovedCreatedInSource()
        {
            ICommandFactory factory = MockRepository.GenerateMock<ICommandFactory>();
            FakeFolder subFolder = new FakeFolder(@"c:\target\subfolder\");
            subFolder.FileList = new List<IFile> { Helpers.CreateStubHelpers.GetIFileStub("1.txt", @"c:\target\subfolder\") };

            FakeFolder linkTo = new FakeFolder(@"c:\target\") { FolderExistsReturnValue = true };
            linkTo.SubFolderList = new List<IFolder> { subFolder };

            FakeFolder linkFrom = new FakeFolder(@"c:\destination\") { FolderExistsReturnValue = true };

            ICommandDiscovery discoverer = new CommandDiscovery(factory, f => new FakeFile(f), f => new FakeFolder(f) { FolderExistsReturnValue = false });
            discoverer.GetCommandListForFolderTask(linkTo, linkFrom, true, true);

            factory.AssertWasCalled(f => f.MoveFileCommand(
                Arg<IFile>.Matches(source => source.FullFilePath.Equals(@"c:\target\subfolder\1.txt")),
                Arg<IFile>.Matches(target => target.FullFilePath.Equals(@"c:\destination\subfolder\1.txt")),
                Arg<Boolean>.Is.Equal(true)
                ));

        }
        public void GetCommandListForFolderTask_TargetHasEmptySubFolder_SubfolderCreatedInSource()
        {
            ICommandFactory factory = MockRepository.GenerateMock<ICommandFactory>();

            FakeFolder linkTo = new FakeFolder(@"c:\target\") { FolderExistsReturnValue = true };
            linkTo.SubFolderList = new List<IFolder>()
                {
                    new FakeFolder(@"c:\target\subfolder\")
                };

            FakeFolder linkFrom = new FakeFolder(@"c:\destination\") { FolderExistsReturnValue = true };

            ICommandDiscovery discoverer = new CommandDiscovery(factory, f => new FakeFile(f), f => new FakeFolder(f) { FolderExistsReturnValue = false });
            List<ICommand> taskList = discoverer.GetCommandListForFolderTask(linkTo, linkFrom, true, false);

            factory.AssertWasCalled(f => f.CreateFolder(Arg<IFolder>.Matches(folder => folder.FolderPath.Equals(@"c:\destination\subfolder\"))));
            
        }
        public void Undo_Execute_not_called_folder_is_not_created()
        {
            FakeFolder folder = new FakeFolder(@"c:\fakeFolder\");
            folder.FolderExistsReturnValue = true;

            ICommand deleteCommand = new DeleteFolderCommand(folder);
            deleteCommand.Undo();

            Assert.IsFalse(folder.CreateFolderCalled);
        }
        public void GetCommandListForFolderTask_TargetExistsNoFiles_DeleteFolderThenCreateLinkReturned()
        {
            ICommandFactory factory = new MockCommandFactory();
            FakeFolder linkTo = new FakeFolder() { FolderExistsReturnValue = true };
            
            FakeFolder linkFrom = new FakeFolder(@"c:\dest\");
            linkFrom.FolderExistsReturnValue = true;

            ICommandDiscovery discoverer = new CommandDiscovery(factory, s => new FakeFile(s), f => new FakeFolder(f));
            List<ICommand> taskList = discoverer.GetCommandListForFolderTask(linkTo, linkFrom, true, false);

            Assert.IsTrue(taskList.Count() == 2, "There should be three items in the list");
            Assert.IsTrue(((MockCommand)taskList[0]).CommandName.Equals("DeleteFolderCommand"));
            Assert.IsTrue(((MockCommand)taskList[1]).CommandName.Equals("CreateLinkCommand"));
        }
        public void Execute_Folder_deleted()
        {
            FakeFolder folder = new FakeFolder(@"c:\fakeFolder\");
            folder.FolderExistsReturnValue = true;

            ICommand deleteCommand = new DeleteFolderCommand(folder);
            deleteCommand.Execute();

            Assert.IsTrue(folder.DeleteFolderCalled);
        }
        public void UserFeedback_returns_a_status_containing_the_folder_name()
        {
            string folderPath = @"fakeFolder";
            FakeFolder folder = new FakeFolder(folderPath);
            folder.FolderExistsReturnValue = true;

            ICommand deleteCommand = new DeleteFolderCommand(folder);

            StringAssert.Contains(folderPath, deleteCommand.UserFeedback);
        }
        public void Execute_folder_does_not_exist_delete_not_called()
        {
            FakeFolder folder = new FakeFolder(@"c:\fakeFolder\");
            folder.FolderExistsReturnValue = false;

            ICommand deleteCommand = new DeleteFolderCommand(folder);
            deleteCommand.Execute();

            Assert.IsFalse(folder.DeleteFolderCalled);
        }
        public void GetCommandListForFolderTask_SourceDoesNotExists_CreateFolderCommandIsFirst()
        {
            ICommandFactory factory = new MockCommandFactory();
            IFolder linkTo = new FakeFolder(@"c:\target\");

            FakeFolder linkFrom = new FakeFolder(@"c:\destination\");
            linkFrom.FolderExistsReturnValue = false;

            ICommandDiscovery discoverer = new CommandDiscovery(factory, (f) => new FakeFile(f), f => new FakeFolder(f));
            List<ICommand> taskList = discoverer.GetCommandListForFolderTask(linkTo, linkFrom, false, false);
            
            MockCommand mockCommand = (MockCommand)taskList[0];

            Assert.AreEqual("CreateFolder", mockCommand.CommandName);
            Assert.AreEqual(mockCommand.ctorParams[0], linkFrom);   
        }
        public void GetCommandListForFolderTask_TargetExistsOneFiles_MoveFileThenDeleteFolderThenCreateLinkReturned()
        {
            ICommandFactory factory = new MockCommandFactory();
            FakeFolder linkTo = new FakeFolder();
            linkTo.FileList = new List<IFile> { Helpers.CreateStubHelpers.GetIFileStub("1.txt", @"c:\path") };
            linkTo.FolderExistsReturnValue = true;

            FakeFolder linkFrom = new FakeFolder(@"c:\dest\");
            linkFrom.FolderExistsReturnValue = true;

            ICommandDiscovery discoverer = new CommandDiscovery(factory, (f) => new FakeFile(f), f => new FakeFolder(f));
            List<ICommand> taskList = discoverer.GetCommandListForFolderTask(linkTo, linkFrom, true, false);

            Assert.IsTrue(taskList.Count() == 3, "There should be three items in the list");
            Assert.IsTrue(((MockCommand)taskList[0]).CommandName.Equals("MoveFileCommand"));
            Assert.IsTrue(((MockCommand)taskList[1]).CommandName.Equals("DeleteFolderCommand"));
            Assert.IsTrue(((MockCommand)taskList[2]).CommandName.Equals("CreateLinkCommand"));
        }
        public void Undo_Creates_folder_when_undo_is_called_after_execute()
        {
            FakeFolder folder = new FakeFolder(@"c:\fakeFolder\");
            folder.FolderExistsReturnValue = true;

            ICommand deleteCommand = new DeleteFolderCommand(folder);
            deleteCommand.Execute();
            deleteCommand.Undo();

            Assert.IsTrue(folder.CreateFolderCalled);
        }