public void CanMoveDirectory() { string dir1 = dllPath.CombineAssert("a"); string dir2 = dllPath.Combine("b"); Assert.That(Directory.Exists(dir2), Is.False); Assert.That(File.Exists(dir2), Is.False, "Lingering files should not be allowed to disrupt the testing."); string aFile = dir1.Combine("file"); File.WriteAllText(aFile, "I should also be moved."); infosCreated.Add(aFile); using (var t = new FileTransaction("moving tx")) { t.Begin(); (t as IDirectoryAdapter).Move(dir1, dir2); Assert.IsFalse(Directory.Exists(dir2), "The directory should not yet exist."); t.Commit(); Assert.That(Directory.Exists(dir2), "Now after committing it should."); infosCreated.Add(dir2); Assert.That(File.Exists(dir2.Combine(Path.GetFileName(aFile))), "And so should the file in the directory."); } }
void IFileAdapter.Move(string originalFilePath, string newFilePath) { // case 1, the new file path is a folder if (((IDirectoryAdapter)this).Exists(newFilePath)) { MoveFileTransacted(originalFilePath, newFilePath.Combine(Path.GetFileName(originalFilePath)), IntPtr.Zero, IntPtr.Zero, MoveFileFlags.CopyAllowed, _TransactionHandle); return; } // case 2, its not a folder, so assume it's a file. MoveFileTransacted(originalFilePath, newFilePath, IntPtr.Zero, IntPtr.Zero, MoveFileFlags.CopyAllowed, _TransactionHandle); }