public void SubdirectoryOnNotReadyDriveAsPath_ThrowsIOException() { var drive = IOServices.GetNotReadyDrive(); if (drive == null) { Console.WriteLine("Skipping test. Unable to find a not-ready drive, such as CD-Rom with no disc inserted."); return; } // 'Device is not ready' Assert.Throws <IOException>(() => { Create(Path.Combine(drive, "Subdirectory")); }); }
public static void CreateDirectory_DirectoryEqualToMaxDirectory_CanBeCreated() { // Recursively creates directories right up to the maximum directory length ("247 chars not including null") using (TemporaryDirectory directory = new TemporaryDirectory()) { PathInfo path = IOServices.GetPath(directory.Path, IOInputs.MaxDirectory); // First create 'C:\AAA...AA', followed by 'C:\AAA...AAA\AAA...AAA', etc foreach (string subpath in path.SubPaths) { DirectoryInfo result = Directory.CreateDirectory(subpath); Assert.Equal(subpath, result.FullName); Assert.True(Directory.Exists(result.FullName)); } } }
public static void CreateDirectory_NonExistentDriveAsPath_ThrowsDirectoryNotFoundException() { var drive = IOServices.GetNonExistentDrive(); if (drive == null) { Console.WriteLine("Skipping test. Unable to find a non-existent drive."); return; } Assert.Throws <DirectoryNotFoundException>(() => { Directory.CreateDirectory(drive); }); }
private void Copy(List <SourceTarget> fileInfos) { Boolean taskCancelled = false; try { foreach (SourceTarget fileInfo in fileInfos) { if (CancellationToken.IsCancellationRequested) { UIServices.ShowMessageBox("The Copy process was aborted.", String.Empty, Buttons.OK, Icon.Warning); taskCancelled = true; return; } if (PreserveSubFolders) { EnsureSubFolders(fileInfo); } else { fileInfo.TargetFolder = IOServices.GetFolderInfo(TargetLocation); } } taskCancelled = CommenceCopy(fileInfos); } catch (System.IO.IOException ioEx) { UIServices.ShowMessageBox(ioEx.Message, "?!?", Buttons.OK, Icon.Error); } catch (Exception ex) { UIServices.ShowMessageBox(ex.Message, "?!?", Buttons.OK, Icon.Error); } finally { ProgressChanged?.Invoke(this, EventArgs.Empty); if (taskCancelled == false) { UIServices.ShowMessageBox("Copy Finished.", String.Empty, Buttons.OK, Icon.Information); } } }
public static string java(string className, params string[] args) { #if CF || SILVERLIGHT return(null); #else return(IOServices.Exec(WorkspaceServices.JavaPath(), "-cp", IOServices.JoinQuotedArgs( Path.PathSeparator, JavaTempPath, Db4oCoreJarPath(), Db4oJarPath("-optional"), Db4oJarPath("-cs")), className, IOServices.JoinQuotedArgs(args))); #endif }
public static void CreateDirectory_ValidPathWithTrailingSlash_CanBeCreated() { using (TemporaryDirectory directory = new TemporaryDirectory()) { var components = IOInputs.GetValidPathComponentNames(); foreach (var component in components) { string path = IOServices.AddTrailingSlashIfNeeded(Path.Combine(directory.Path, component)); DirectoryInfo result = Directory.CreateDirectory(path); Assert.Equal(path, result.FullName); Assert.True(Directory.Exists(result.FullName)); } } }
public void EnumerateFilesDirectoryOverLegacyMaxPath() { // Check enumerating when the entire path is over MAX_PATH string directory = IOServices.GetPath(GetTestFilePath(), 270); Assert.Equal(270, directory.Length); Assert.True(Directory.CreateDirectory(directory).Exists); for (int i = 0; i < 6; i++) { string testFile = Path.Combine(directory, new string((char)('0' + i), i + 7)); File.Create(testFile).Dispose(); } string[] files = GetEntries(directory); Assert.Equal(6, files.Length); }
public static string javac(string srcFile) { #if CF || SILVERLIGHT return(null); #else Assert.IsTrue(File.Exists(JavaServices.Db4oCoreJarPath()), string.Format("'{0}' not found. Make sure the jar was built before running this test.", JavaServices.Db4oCoreJarPath())); Assert.IsTrue(File.Exists(JavaServices.Db4oJarPath("-optional")), string.Format("'{0}' not found. Make sure the jar was built before running this test.", JavaServices.Db4oJarPath("-optional"))); Assert.IsTrue(File.Exists(JavaServices.Db4oJarPath("-cs")), string.Format("'{0}' not found. Make sure the jar was built before running this test.", JavaServices.Db4oJarPath("-cs"))); return(IOServices.Exec(WorkspaceServices.JavacPath(), "-classpath", IOServices.JoinQuotedArgs( Path.PathSeparator, Db4oCoreJarPath(), Db4oJarPath("-optional"), Db4oJarPath("-cs")), srcFile)); #endif }
public void EnumerateFilesOverLegacyMaxPath() { // We want to test that directories under the legacy MAX_PATH (260 characters, including the null) can iterate files // even if the full path is over 260. string directory = IOServices.GetPath(GetTestFilePath(), 250); Assert.Equal(250, directory.Length); Assert.True(Directory.CreateDirectory(directory).Exists); for (int i = 0; i < 6; i++) { string testFile = Path.Combine(directory, new string((char)('0' + i), i + 7)); File.Create(testFile).Dispose(); } string[] files = GetEntries(directory); Assert.Equal(6, files.Length); }
public Db4oLibraryEnvironment(File file, File additionalAssembly) { _targetAssembly = file.GetAbsolutePath(); #if !CF && !SILVERLIGHT _assemblyVersion = AssemblyVersionFor(_targetAssembly); _baseDirectory = IOServices.BuildTempPath("migration-domain-" + _assemblyVersion); _domain = CreateDomain(SetUpBaseDirectory()); try { SetUpAssemblyResolver(); SetUpLegacyAdapter(); } catch (Exception x) { Dispose(); throw new Exception("Failed to setup environment for '" + _targetAssembly + "'", x); } #endif }
public void ReadXml(String fileName) { try { using (System.IO.Stream fs = IOServices.GetFileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { RecentFiles recentFiles = Serializer <RecentFiles> .Deserialize(fs); foreach (String file in recentFiles.Files) { if (IOServices.File.Exists(file)) { HashedEntries.Add(file); } } } } catch (Exception ex) { UIServices.ShowMessageBox(ex.Message, "Error", Buttons.OK, Icon.Error); } }
private void EnsureSubFolders(SourceTarget fileInfo) { String directoryName = fileInfo.SourceFile.FolderName; String newPath; if (directoryName.StartsWith(Properties.Settings.Default.SourcePath)) { newPath = directoryName.Replace(Properties.Settings.Default.SourcePath, String.Empty); } else { Int32 indexOfFirstBackSlash; indexOfFirstBackSlash = directoryName.IndexOf(@"\"); newPath = directoryName.Substring(indexOfFirstBackSlash + 1); } if (IgnoreResolutionFolders) { if ((newPath.EndsWith(@"\SD")) || (newPath.EndsWith(@"\HD"))) { newPath = newPath.Substring(0, newPath.Length - 3); } } String path = IOServices.Path.Combine(TargetLocation, newPath); fileInfo.TargetFolder = IOServices.GetFolderInfo(path); if (fileInfo.TargetFolder.Exists == false) { fileInfo.TargetFolder.Create(); } }
private static string GetLongPath(int characterCount) { return(IOServices.GetPath(characterCount).FullPath); }
private static string GetLongPath(int characterCount, bool extended = false) { return(IOServices.GetPath(characterCount, extended).FullPath); }
public void NonExistentFile() { Assert.Throws <FileNotFoundException>(() => Set(GetTestFilePath(), FileAttributes.Normal)); Assert.Throws <FileNotFoundException>(() => Set(IOServices.AddTrailingSlashIfNeeded(GetTestFilePath()), FileAttributes.Normal)); Assert.Throws <FileNotFoundException>(() => Set(IOServices.RemoveTrailingSlash(GetTestFilePath()), FileAttributes.Normal)); }
[PlatformSpecific(TestPlatforms.Windows)] // drive labels public void SubdirectoryOnNonExistentDriveAsPath_ReturnsFalse() { Assert.False(Exists(Path.Combine(IOServices.GetNonExistentDrive(), "nonexistentsubdir"))); }
[PlatformSpecific(TestPlatforms.Windows)] // drive labels public void DriveAsPath() { Assert.False(Exists(IOServices.GetNonExistentDrive())); Assert.Contains(IOServices.GetReadyDrives(), drive => Exists(drive)); }
public static void runTest() { int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; try { DirectoryInfo dir = null; String strDirName = ""; // [] Create a directory and check the creation time strLoc = "Loc_r8r7j"; strDirName = Path.Combine(TestInfo.CurrentDirectory, "TestDir"); dir = Directory.CreateDirectory(strDirName); iCountTestcases++; try { if (Math.Abs((Directory.GetCreationTime(strDirName) - DateTime.Now).TotalSeconds) > 3) { iCountErrors++; printerr("Error_20hjx! Creation time should be within 3 seconds of now"); } } catch (Exception exc) { iCountErrors++; printerr("Error_20fhd! Unexpected exceptiont thrown: " + exc.ToString()); } dir.Delete(true); // remote directory test moved to RemoteIOTests.cs // [] Check the creation time for an existing file. strLoc = "Loc_20er"; strDirName = Path.Combine(TestInfo.CurrentDirectory, "blah"); dir = Directory.CreateDirectory(strDirName); Task.Delay(2000).Wait(); iCountTestcases++; try { if ((DateTime.Now - Directory.GetCreationTime(strDirName)).Seconds > 3) { iCountErrors++; printerr("Eror_3123! Creation time is off"); } } catch (Exception exc) { iCountErrors++; printerr("Error_3543! Unexpected exception thrown: " + exc.ToString()); } dir.Delete(true); #if !TEST_WINRT //#469226 - DirectoryInfo.CreationTime throws System.ArgumentOutOfRangeException for directories on CDs //postponed but we will add the scenario try { IEnumerable <string> drives = IOServices.GetReadyDrives(); foreach (string drive in drives) { String[] dirs = Directory.GetDirectories(drive); int count = 10; if (dirs.Length < count) { count = dirs.Length; } for (int i = 0; i < count; i++) { try { DateTime time = Directory.GetCreationTime(dirs[i]); } catch (ArgumentOutOfRangeException) { Console.WriteLine("Info_9237tgfasd: #469226? drive: {0}, directory: {1}", drive, dirs[i]); } } } } catch (Exception ex) { ++iCountErrors; Console.WriteLine("Err_734g@! exception thrown: {0}", ex); } #endif } catch (Exception exc_general) { ++iCountErrors; printerr("Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general.ToString()); } if (iCountErrors != 0) { Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString()); } Assert.Equal(0, iCountErrors); }
private string DataFilePath() { return(IOServices.BuildTempPath(GetType().Name + ".db4o")); }
public static string GetUnusedDrive() { return(IOServices.GetNonExistentDrive()); }
[PlatformSpecific(TestPlatforms.Windows)] // drive labels public void ExtendedDriveAsPath() { Assert.False(Exists(IOInputs.ExtendedPrefix + IOServices.GetNonExistentDrive())); Assert.Contains(IOServices.GetReadyDrives(), drive => Exists(IOInputs.ExtendedPrefix + drive)); }
private static string GetLongPath(string rootPath, int characterCount, bool extended = false) { return(IOServices.GetPath(rootPath, characterCount, extended)); }
public void PathAlreadyExistsAsFile() { string path = GetTestFileName(); File.Create(Path.Combine(TestDirectory, path)).Dispose(); Assert.Throws <IOException>(() => new DirectoryInfo(TestDirectory).CreateSubdirectory(path)); Assert.Throws <IOException>(() => new DirectoryInfo(TestDirectory).CreateSubdirectory(IOServices.AddTrailingSlashIfNeeded(path))); Assert.Throws <IOException>(() => new DirectoryInfo(TestDirectory).CreateSubdirectory(IOServices.RemoveTrailingSlash(path))); }
public static bool IsCurrentDriveNTFS() { return(IOServices.IsDriveNTFS(IOServices.GetCurrentDrive())); }
private static void CopyTo(string fname, string dir) { IOServices.CopyTo(fname, dir); }
private static void CopyNecessaryAssembliesTo(string basePath) { IOServices.CopyEnclosingAssemblyTo(typeof (Db4oFactory), basePath); IOServices.CopyEnclosingAssemblyTo(typeof (Assert), basePath); CopyTo(Assembly.GetExecutingAssembly().Location, basePath); }
[PlatformSpecific(TestPlatforms.Windows)] // drive labels public void NonExistentDriveAsPath_ReturnsFalse() { Assert.False(Exists(IOServices.GetNonExistentDrive())); }
[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); } }
private static string GetJavaDataFile() { return(IOServices.BuildTempPath("java.yap")); }