[PlatformSpecific(TestPlatforms.Windows)] // testing mounting volumes and reparse points public static void runTest() { try { Stopwatch watch; const string MountPrefixName = "LaksMount"; string mountedDirName; string dirNameWithoutRoot; string dirNameReferedFromMountedDrive; string dirName; string[] expectedFiles; string[] files; string[] expectedDirs; string[] dirs; List <string> list; watch = new Stopwatch(); watch.Start(); try { //Scenario 1: Vanilla - Different drive is mounted on the current drive Console.WriteLine("Scenario 1 - Vanilla: Different drive is mounted on the current drive: {0}", watch.Elapsed); string otherDriveInMachine = IOServices.GetNtfsDriveOtherThanCurrent(); if (FileSystemDebugInfo.IsCurrentDriveNTFS() && otherDriveInMachine != null) { mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(Path.DirectorySeparatorChar.ToString(), MountPrefixName)); try { Console.WriteLine("Creating directory " + mountedDirName); Directory.CreateDirectory(mountedDirName); MountHelper.Mount(otherDriveInMachine.Substring(0, 2), mountedDirName); dirName = ManageFileSystem.GetNonExistingDir(otherDriveInMachine, ManageFileSystem.DirPrefixName); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 3, 100)) { dirNameWithoutRoot = dirName.Substring(3); dirNameReferedFromMountedDrive = Path.Combine(mountedDirName, dirNameWithoutRoot); //Files expectedFiles = fileManager.GetAllFiles(); list = new List <string>(); //We will only test the filenames since they are unique foreach (string file in expectedFiles) { list.Add(Path.GetFileName(file)); } files = Directory.GetFiles(dirNameReferedFromMountedDrive, "*.*", SearchOption.AllDirectories); Eval(files.Length == list.Count, "Err_3947g! wrong count"); for (int i = 0; i < expectedFiles.Length; i++) { if (Eval(list.Contains(Path.GetFileName(files[i])), "Err_582bmw! No file found: {0}", files[i])) { list.Remove(Path.GetFileName(files[i])); } } if (!Eval(list.Count == 0, "Err_891vut! wrong count: {0}", list.Count)) { Console.WriteLine(); foreach (string fileName in list) { Console.WriteLine(fileName); } } //Directories expectedDirs = fileManager.GetAllDirectories(); list = new List <string>(); foreach (string dir in expectedDirs) { list.Add(dir.Substring(dirName.Length)); } dirs = Directory.GetDirectories(dirNameReferedFromMountedDrive, "*.*", SearchOption.AllDirectories); Eval(dirs.Length == list.Count, "Err_813weq! wrong count"); for (int i = 0; i < dirs.Length; i++) { string exDir = dirs[i].Substring(dirNameReferedFromMountedDrive.Length); if (Eval(list.Contains(exDir), "Err_287kkm! No file found: {0}", exDir)) { list.Remove(exDir); } } if (!Eval(list.Count == 0, "Err_921mhs! wrong count: {0}", list.Count)) { Console.WriteLine(); foreach (string value in list) { Console.WriteLine(value); } } } } finally { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } } else { Console.WriteLine("Skipping since drive is not NTFS and there is no other drive on the machine"); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_768lme! Exception caught in scenario: {0}", ex); } //Scenario 2: Current drive is mounted on a different drive Console.WriteLine(Environment.NewLine + "Scenario 2 - Current drive is mounted on a different drive: {0}", watch.Elapsed); try { string otherDriveInMachine = IOServices.GetNtfsDriveOtherThanCurrent(); if (otherDriveInMachine != null) { mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(otherDriveInMachine.Substring(0, 3), MountPrefixName)); try { Directory.CreateDirectory(mountedDirName); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); dirName = ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), ManageFileSystem.DirPrefixName); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 3, 100)) { dirNameWithoutRoot = dirName.Substring(3); dirNameReferedFromMountedDrive = Path.Combine(mountedDirName, dirNameWithoutRoot); //Files expectedFiles = fileManager.GetAllFiles(); list = new List <string>(); //We will only test the filenames since they are unique foreach (string file in expectedFiles) { list.Add(Path.GetFileName(file)); } files = Directory.GetFiles(dirNameReferedFromMountedDrive, "*.*", SearchOption.AllDirectories); Eval(files.Length == list.Count, "Err_689myg! wrong count"); for (int i = 0; i < expectedFiles.Length; i++) { if (Eval(list.Contains(Path.GetFileName(files[i])), "Err_894vhm! No file found: {0}", files[i])) { list.Remove(Path.GetFileName(files[i])); } } if (!Eval(list.Count == 0, "Err_952qkj! wrong count: {0}", list.Count)) { Console.WriteLine(); foreach (string fileName in list) { Console.WriteLine(fileName); } } //Directories expectedDirs = fileManager.GetAllDirectories(); list = new List <string>(); foreach (string dir in expectedDirs) { list.Add(dir.Substring(dirName.Length)); } dirs = Directory.GetDirectories(dirNameReferedFromMountedDrive, "*.*", SearchOption.AllDirectories); Eval(dirs.Length == list.Count, "Err_154vrz! wrong count"); for (int i = 0; i < dirs.Length; i++) { string exDir = dirs[i].Substring(dirNameReferedFromMountedDrive.Length); if (Eval(list.Contains(exDir), "Err_301sao! No file found: {0}", exDir)) { list.Remove(exDir); } } if (!Eval(list.Count == 0, "Err_630gjj! wrong count: {0}", list.Count)) { Console.WriteLine(); foreach (string value in list) { Console.WriteLine(value); } } } } finally { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } } else { Console.WriteLine("Skipping since drive is not NTFS and there is no other drive on the machine"); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_231vwf! Exception caught in scenario: {0}", ex); } //scenario 3.1: Current drive is mounted on current drive Console.WriteLine(Environment.NewLine + "Scenario 3.1 - Current drive is mounted on current drive: {0}", watch.Elapsed); try { if (FileSystemDebugInfo.IsCurrentDriveNTFS()) { mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(Path.DirectorySeparatorChar.ToString(), MountPrefixName)); try { Directory.CreateDirectory(mountedDirName); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); dirName = ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), ManageFileSystem.DirPrefixName); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 3, 100)) { dirNameWithoutRoot = dirName.Substring(3); dirNameReferedFromMountedDrive = Path.Combine(mountedDirName, dirNameWithoutRoot); //Files expectedFiles = fileManager.GetAllFiles(); list = new List <string>(); //We will only test the filenames since they are unique foreach (string file in expectedFiles) { list.Add(Path.GetFileName(file)); } files = Directory.GetFiles(dirNameReferedFromMountedDrive, "*.*", SearchOption.AllDirectories); Eval(files.Length == list.Count, "Err_213fuo! wrong count"); for (int i = 0; i < expectedFiles.Length; i++) { if (Eval(list.Contains(Path.GetFileName(files[i])), "Err_499oxz! No file found: {0}", files[i])) { list.Remove(Path.GetFileName(files[i])); } } if (!Eval(list.Count == 0, "Err_301gtz! wrong count: {0}", list.Count)) { Console.WriteLine(); foreach (string fileName in list) { Console.WriteLine(fileName); } } //Directories expectedDirs = fileManager.GetAllDirectories(); list = new List <string>(); foreach (string dir in expectedDirs) { list.Add(dir.Substring(dirName.Length)); } dirs = Directory.GetDirectories(dirNameReferedFromMountedDrive, "*.*", SearchOption.AllDirectories); Eval(dirs.Length == list.Count, "Err_771dxv! wrong count"); for (int i = 0; i < dirs.Length; i++) { string exDir = dirs[i].Substring(dirNameReferedFromMountedDrive.Length); if (Eval(list.Contains(exDir), "Err_315jey! No file found: {0}", exDir)) { list.Remove(exDir); } } if (!Eval(list.Count == 0, "Err_424opm! wrong count: {0}", list.Count)) { Console.WriteLine(); foreach (string value in list) { Console.WriteLine(value); } } } } finally { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } } else { Console.WriteLine("Drive is not NTFS. Skipping scenario"); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_493ojg! Exception caught in scenario: {0}", ex); } //scenario 3.2: Current drive is mounted on current directory Console.WriteLine(Environment.NewLine + "Scenario 3.2 - Current drive is mounted on current directory: {0}", watch.Elapsed); try { if (FileSystemDebugInfo.IsCurrentDriveNTFS()) { mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), MountPrefixName)); try { Directory.CreateDirectory(mountedDirName); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); dirName = ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), ManageFileSystem.DirPrefixName); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 3, 100)) { dirNameWithoutRoot = dirName.Substring(3); dirNameReferedFromMountedDrive = Path.Combine(mountedDirName, dirNameWithoutRoot); //Files expectedFiles = fileManager.GetAllFiles(); list = new List <string>(); //We will only test the filenames since they are unique foreach (string file in expectedFiles) { list.Add(Path.GetFileName(file)); } files = Directory.GetFiles(dirNameReferedFromMountedDrive, "*.*", SearchOption.AllDirectories); Eval(files.Length == list.Count, "Err_253yit! wrong count"); for (int i = 0; i < expectedFiles.Length; i++) { if (Eval(list.Contains(Path.GetFileName(files[i])), "Err_798mjs! No file found: {0}", files[i])) { list.Remove(Path.GetFileName(files[i])); } } if (!Eval(list.Count == 0, "Err_141lgl! wrong count: {0}", list.Count)) { Console.WriteLine(); foreach (string fileName in list) { Console.WriteLine(fileName); } } //Directories expectedDirs = fileManager.GetAllDirectories(); list = new List <string>(); foreach (string dir in expectedDirs) { list.Add(dir.Substring(dirName.Length)); } dirs = Directory.GetDirectories(dirNameReferedFromMountedDrive, "*.*", SearchOption.AllDirectories); Eval(dirs.Length == list.Count, "Err_512oxq! wrong count"); for (int i = 0; i < dirs.Length; i++) { string exDir = dirs[i].Substring(dirNameReferedFromMountedDrive.Length); if (Eval(list.Contains(exDir), "Err_907zbr! No file found: {0}", exDir)) { list.Remove(exDir); } } if (!Eval(list.Count == 0, "Err_574raf! wrong count: {0}", list.Count)) { Console.WriteLine(); foreach (string value in list) { Console.WriteLine(value); } } } } finally { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } } else { Console.WriteLine("Drive is not NTFS. Skipping scenario"); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_432qcp! Exception caught in scenario: {0}", ex); } Console.WriteLine("Completed {0}", watch.Elapsed); } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_234rsgf! Uncaught exception in RunTest: {0}", ex); } Assert.True(s_pass); }
[PlatformSpecific(PlatformID.Windows)] // testing volumes / mounts / drive letters public static void RunTest() { try { const String MountPrefixName = "LaksMount"; String mountedDirName; String dirName; String dirNameWithoutRoot; String dirNameReferedFromMountedDrive; //Adding debug info since this test hangs sometime in RTS runs String debugFileName = "Co7604Delete_MountVolume_Debug.txt"; DeleteFile(debugFileName); String scenarioDescription; scenarioDescription = "Scenario 1: Vanilla - Different drive is mounted on the current drive"; try { File.AppendAllText(debugFileName, String.Format("{0}{1}", scenarioDescription, Environment.NewLine)); string otherDriveInMachine = IOServices.GetNtfsDriveOtherThanCurrent(); //out labs use UIP tools in one drive and dont expect this drive to be used by others. We avoid this problem by not testing if the other drive is not NTFS if (FileSystemDebugInfo.IsCurrentDriveNTFS() && otherDriveInMachine != null) { Console.WriteLine(scenarioDescription); mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(Path.DirectorySeparatorChar.ToString(), MountPrefixName)); try { Directory.CreateDirectory(mountedDirName); File.AppendAllText(debugFileName, String.Format("Mounting on {0}{1}{2}", otherDriveInMachine.Substring(0, 2), mountedDirName, Environment.NewLine)); MountHelper.Mount(otherDriveInMachine.Substring(0, 2), mountedDirName); dirName = ManageFileSystem.GetNonExistingDir(otherDriveInMachine, ManageFileSystem.DirPrefixName); File.AppendAllText(debugFileName, String.Format("Creating a sub tree at: {0}{1}", dirName, Environment.NewLine)); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 3, 100)) { Eval(Directory.Exists(dirName), "Err_3974g! Directory {0} doesn't exist: {1}", dirName, Directory.Exists(dirName)); //Lets refer to these via mounted drive and check dirNameWithoutRoot = dirName.Substring(3); dirNameReferedFromMountedDrive = Path.Combine(mountedDirName, dirNameWithoutRoot); Directory.Delete(dirNameReferedFromMountedDrive, true); Task.Delay(300).Wait(); Eval(!Directory.Exists(dirName), "Err_20387g! Directory {0} still exist: {1}", dirName, Directory.Exists(dirName)); } } finally { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } File.AppendAllText(debugFileName, String.Format("Completed scenario {0}", Environment.NewLine)); } else { File.AppendAllText(debugFileName, String.Format("Scenario 1 - Vanilla - NOT RUN: Different drive is mounted on the current drive {0}", Environment.NewLine)); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_768lme! Exception caught in scenario: {0}", ex); } scenarioDescription = "Scenario 2: Current drive is mounted on a different drive"; Console.WriteLine(scenarioDescription); File.AppendAllText(debugFileName, String.Format("{0}{1}", scenarioDescription, Environment.NewLine)); try { string otherDriveInMachine = IOServices.GetNtfsDriveOtherThanCurrent(); if (otherDriveInMachine != null) { mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(otherDriveInMachine.Substring(0, 3), MountPrefixName)); try { Directory.CreateDirectory(mountedDirName); File.AppendAllText(debugFileName, String.Format("Mounting on {0}{1}{2}", Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName, Environment.NewLine)); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); dirName = ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), ManageFileSystem.DirPrefixName); File.AppendAllText(debugFileName, String.Format("Creating a sub tree at: {0}{1}", dirName, Environment.NewLine)); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 3, 100)) { Eval(Directory.Exists(dirName), "Err_239ufz! Directory {0} doesn't exist: {1}", dirName, Directory.Exists(dirName)); //Lets refer to these via mounted drive and check dirNameWithoutRoot = dirName.Substring(3); dirNameReferedFromMountedDrive = Path.Combine(mountedDirName, dirNameWithoutRoot); Directory.Delete(dirNameReferedFromMountedDrive, true); Task.Delay(300).Wait(); Eval(!Directory.Exists(dirName), "Err_794aiu! Directory {0} still exist: {1}", dirName, Directory.Exists(dirName)); } } finally { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } File.AppendAllText(debugFileName, String.Format("Completed scenario {0}", Environment.NewLine)); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_231vwf! Exception caught in scenario: {0}", ex); } //scenario 3.1: Current drive is mounted on current drive scenarioDescription = "Scenario 3.1 - Current drive is mounted on current drive"; try { if (FileSystemDebugInfo.IsCurrentDriveNTFS()) { File.AppendAllText(debugFileName, String.Format("{0}{1}", scenarioDescription, Environment.NewLine)); mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(Path.DirectorySeparatorChar.ToString(), MountPrefixName)); try { Directory.CreateDirectory(mountedDirName); File.AppendAllText(debugFileName, String.Format("Mounting on {0}{1}{2}", Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName, Environment.NewLine)); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); dirName = ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), ManageFileSystem.DirPrefixName); File.AppendAllText(debugFileName, String.Format("Creating a sub tree at: {0}{1}", dirName, Environment.NewLine)); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 3, 100)) { Eval(Directory.Exists(dirName), "Err_324eez! Directory {0} doesn't exist: {1}", dirName, Directory.Exists(dirName)); //Lets refer to these via mounted drive and check dirNameWithoutRoot = dirName.Substring(3); dirNameReferedFromMountedDrive = Path.Combine(mountedDirName, dirNameWithoutRoot); Directory.Delete(dirNameReferedFromMountedDrive, true); Task.Delay(300).Wait(); Eval(!Directory.Exists(dirName), "Err_195whv! Directory {0} still exist: {1}", dirName, Directory.Exists(dirName)); } } finally { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } File.AppendAllText(debugFileName, String.Format("Completed scenario {0}", Environment.NewLine)); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_493ojg! Exception caught in scenario: {0}", ex); } //scenario 3.2: Current drive is mounted on current directory scenarioDescription = "Scenario 3.2 - Current drive is mounted on current directory"; try { if (FileSystemDebugInfo.IsCurrentDriveNTFS()) { File.AppendAllText(debugFileName, String.Format("{0}{1}", scenarioDescription, Environment.NewLine)); mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), MountPrefixName)); try { Directory.CreateDirectory(mountedDirName); File.AppendAllText(debugFileName, String.Format("Mounting on {0}{1}{2}", Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName, Environment.NewLine)); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); dirName = ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), ManageFileSystem.DirPrefixName); File.AppendAllText(debugFileName, String.Format("Creating a sub tree at: {0}{1}", dirName, Environment.NewLine)); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 3, 100)) { Eval(Directory.Exists(dirName), "Err_951ipb! Directory {0} doesn't exist: {1}", dirName, Directory.Exists(dirName)); //Lets refer to these via mounted drive and check dirNameWithoutRoot = dirName.Substring(3); dirNameReferedFromMountedDrive = Path.Combine(mountedDirName, dirNameWithoutRoot); Directory.Delete(dirNameReferedFromMountedDrive, true); Task.Delay(300).Wait(); Eval(!Directory.Exists(dirName), "Err_493yin! Directory {0} still exist: {1}", dirName, Directory.Exists(dirName)); } } finally { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } File.AppendAllText(debugFileName, String.Format("Completed scenario {0}", Environment.NewLine)); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_432qcp! Exception caught in scenario: {0}", ex); } //@WATCH - potentially dangerous code - can delete the whole drive!! //scenario 3.3: we call delete on the mounted volume - this should only delete the mounted drive? //Current drive is mounted on current directory scenarioDescription = "Scenario 3.3 - we call delete on the mounted volume"; try { if (FileSystemDebugInfo.IsCurrentDriveNTFS()) { File.AppendAllText(debugFileName, String.Format("{0}{1}", scenarioDescription, Environment.NewLine)); mountedDirName = Path.GetFullPath(ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), MountPrefixName)); try { Directory.CreateDirectory(mountedDirName); File.AppendAllText(debugFileName, String.Format("Mounting on {0}{1}{2}", Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName, Environment.NewLine)); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); Directory.Delete(mountedDirName, true); Task.Delay(300).Wait(); } finally { if (!Eval(!Directory.Exists(mountedDirName), "Err_001yph! Directory {0} still exist: {1}", mountedDirName, Directory.Exists(mountedDirName))) { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } } File.AppendAllText(debugFileName, String.Format("Completed scenario {0}", Environment.NewLine)); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_386rpj! Exception caught in scenario: {0}", ex); } //@WATCH - potentially dangerous code - can delete the whole drive!! //scenario 3.4: we call delete on parent directory of the mounted volume, the parent directoriy will have some other directories and files //Current drive is mounted on current directory scenarioDescription = "Scenario 3.4 - we call delete on parent directory of the mounted volume, the parent directoriy will have some other directories and files"; try { if (FileSystemDebugInfo.IsCurrentDriveNTFS()) { File.AppendAllText(debugFileName, String.Format("{0}{1}", scenarioDescription, Environment.NewLine)); mountedDirName = null; try { dirName = ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), ManageFileSystem.DirPrefixName); File.AppendAllText(debugFileName, String.Format("Creating a sub tree at: {0}{1}", dirName, Environment.NewLine)); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 2, 20)) { Eval(Directory.Exists(dirName), "Err_469yvh! Directory {0} doesn't exist: {1}", dirName, Directory.Exists(dirName)); String[] dirs = fileManager.GetDirectories(1); mountedDirName = Path.GetFullPath(dirs[0]); if (Eval(Directory.GetDirectories(mountedDirName).Length == 0, "Err_974tsg! the sub directory has directories: {0}", mountedDirName)) { foreach (String file in Directory.GetFiles(mountedDirName)) { File.Delete(file); } if (Eval(Directory.GetFiles(mountedDirName).Length == 0, "Err_13ref! the mounted directory has files: {0}", mountedDirName)) { File.AppendAllText(debugFileName, String.Format("Mounting on {0}{1}{2}", Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName, Environment.NewLine)); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); //now lets call delete on the parent directory Directory.Delete(dirName, true); Task.Delay(300).Wait(); Eval(!Directory.Exists(dirName), "Err_006jsf! Directory {0} still exist: {1}", dirName, Directory.Exists(dirName)); Console.WriteLine("Completed Scenario 3.4"); } } } } finally { if (!Eval(!Directory.Exists(mountedDirName), "Err_625ckx! Directory {0} still exist: {1}", mountedDirName, Directory.Exists(mountedDirName))) { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } } File.AppendAllText(debugFileName, String.Format("Completed scenario {0}", Environment.NewLine)); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_578tni! Exception caught in scenario: {0}", ex); } //@WATCH - potentially dangerous code - can delete the whole drive!! //scenario 3.5: we call delete on parent directory of the mounted volume, the parent directoriy will have some other directories and files //we call a different directory than the first //Current drive is mounted on current directory scenarioDescription = "Scenario 3.5 - we call delete on parent directory of the mounted volume, the parent directoriy will have some other directories and files"; try { if (FileSystemDebugInfo.IsCurrentDriveNTFS()) { File.AppendAllText(debugFileName, String.Format("{0}{1}", scenarioDescription, Environment.NewLine)); mountedDirName = null; try { dirName = ManageFileSystem.GetNonExistingDir(Directory.GetCurrentDirectory(), ManageFileSystem.DirPrefixName); File.AppendAllText(debugFileName, String.Format("Creating a sub tree at: {0}{1}", dirName, Environment.NewLine)); using (ManageFileSystem fileManager = new ManageFileSystem(dirName, 2, 30)) { Eval(Directory.Exists(dirName), "Err_715tdq! Directory {0} doesn't exist: {1}", dirName, Directory.Exists(dirName)); String[] dirs = fileManager.GetDirectories(1); mountedDirName = Path.GetFullPath(dirs[0]); if (dirs.Length > 1) { mountedDirName = Path.GetFullPath(dirs[1]); } if (Eval(Directory.GetDirectories(mountedDirName).Length == 0, "Err_492qwl! the sub directory has directories: {0}", mountedDirName)) { foreach (String file in Directory.GetFiles(mountedDirName)) { File.Delete(file); } if (Eval(Directory.GetFiles(mountedDirName).Length == 0, "Err_904kij! the mounted directory has files: {0}", mountedDirName)) { File.AppendAllText(debugFileName, String.Format("Mounting on {0}{1}{2}", Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName, Environment.NewLine)); MountHelper.Mount(Directory.GetCurrentDirectory().Substring(0, 2), mountedDirName); //now lets call delete on the parent directory Directory.Delete(dirName, true); Task.Delay(300).Wait(); Eval(!Directory.Exists(dirName), "Err_900edl! Directory {0} still exist: {1}", dirName, Directory.Exists(dirName)); Console.WriteLine("Completed Scenario 3.5: {0}", mountedDirName); } } } } finally { if (!Eval(!Directory.Exists(mountedDirName), "Err_462xtc! Directory {0} still exist: {1}", mountedDirName, Directory.Exists(mountedDirName))) { MountHelper.Unmount(mountedDirName); DeleteDir(mountedDirName, true); } } File.AppendAllText(debugFileName, String.Format("Completed scenario {0}", Environment.NewLine)); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_471jli! Exception caught in scenario: {0}", ex); } } catch (Exception ex) { s_pass = false; Console.WriteLine("Err_234rsgf! Uncaught exception in RunTest: {0}", ex); } finally { Assert.True(s_pass); } }