public void itShouldRestoreBackupOnUndo() { var fileSysCommand = new MockFileSystemCommand(); var fakeFileSystem = new FakeFileSystem(fileSysCommand); var dirToDelete = @"c:\mainFolder\dummysourcedir"; fakeFileSystem.AddDirectory(dirToDelete); var dirDeleteCommand = new DirectoryDeleteCommand(dirToDelete, @"c:\dummybackupdir", fileSysCommand); dirDeleteCommand.Do(); Assert.IsFalse(fakeFileSystem.DirectoryExists(dirToDelete)); dirDeleteCommand.Undo(); Assert.IsTrue(fakeFileSystem.DirectoryExists(dirToDelete)); }
public void itShouldDeleteBackupFileOnCleanup() { var fileSysCommand = new MockFileSystemCommand(); var fakeFileSystem = new FakeFileSystem(fileSysCommand); var dirToDelete = @"c:\main1\main2\dummysourceDir"; fakeFileSystem.AddDirectory(dirToDelete); var dirDeleteCommand = new DirectoryDeleteCommand(dirToDelete, @"c:\dummybackupdir", fileSysCommand); dirDeleteCommand.Do(); dirDeleteCommand.Cleanup(); Assert.IsFalse(fakeFileSystem.DirectoryExists(dirDeleteCommand.BackedUpDirectory)); }
public void itShouldFailIfDeleteFails() { var fileSysCommand = new MockFileSystemCommand(); var sourceDir = @"c:\dummysourcefile"; var dirDeleteCommand = new DirectoryDeleteCommand(sourceDir, @"c:\dummybackupdir", fileSysCommand); var fakeFileSystem = new FakeFileSystem(fileSysCommand); fileSysCommand.DirectoryDeleteFunc = (filename) => { throw new ApplicationException("Exception raised by MockFileSystemCommand during FileDelete"); }; fakeFileSystem.AddDirectory(sourceDir); dirDeleteCommand.Do(); Assert.IsFalse(dirDeleteCommand.DidCommandSucceed); Assert.IsTrue(fakeFileSystem.DirectoryExists(sourceDir)); }
public void itShouldFailIfBackupFails() { var fileSysCommand = new MockFileSystemCommand(); var sourceDir = @"c:\dummysourceDir"; var dirDeleteCommand = new DirectoryDeleteCommand(sourceDir, @"c:\dummybackupdir", fileSysCommand); var fakeFileSystem = new FakeFileSystem(fileSysCommand); fileSysCommand.DirectoryCopyContentsFunc = (sourceFile, destinationFile, preCopyCallback, postCopyCallback) => { throw new ApplicationException("Exception raised by MockFileSystemCommand during DirectoryCopy"); }; fakeFileSystem.AddDirectory(sourceDir); dirDeleteCommand.Do(); Assert.IsFalse(dirDeleteCommand.DidCommandSucceed); Assert.IsTrue(fakeFileSystem.DirectoryExists(sourceDir)); }
public void itMustDeleteDirectoryContentsOnly() { var fileSysCommand = new MockFileSystemCommand(); var dirToDeleteContents = @"c:\maindir\subdir"; var dirDeleteDirContentsOnlyCommand = new DirectoryDeleteContentsOnlyCommandInternal(dirToDeleteContents, @"c:\dummybackupdir", fileSysCommand); var fakeFileSystem = new FakeFileSystem(fileSysCommand); fakeFileSystem.AddDirectory(dirToDeleteContents); var file1 = dirToDeleteContents + @"\dummyfile1.txt"; var file2 = dirToDeleteContents + @"\dummyfile2.txt"; fakeFileSystem.AddFiles(file1); fakeFileSystem.AddFiles(file2); dirDeleteDirContentsOnlyCommand.Do(); Assert.IsTrue(dirDeleteDirContentsOnlyCommand.DidCommandSucceed); Assert.IsTrue(fakeFileSystem.DirectoryExists(dirToDeleteContents)); Assert.IsFalse(fakeFileSystem.FileExists(file1)); Assert.IsFalse(fakeFileSystem.FileExists(file2)); }