public void DefineDosDevice() { Console.WriteLine("Volume.DefineDosDevice()"); if (!IsAdmin()) { Assert.Fail(); } #region Regular Drive Mapping string drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); StopWatcher(true); // Create Regular drive mapping. bool actionIsTrue = false; try { Volume.DefineDosDevice(drive, TempFolder); actionIsTrue = true; } catch { } Console.WriteLine("\nCreated Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", actionIsTrue, drive, TempFolder, Reporter(true)); Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been created."); DriveInfo di = new DriveInfo(drive); System.IO.DriveInfo diSysIo = new System.IO.DriveInfo(drive); try { Assert.IsTrue(Dump(di, -21)); // A Regular drive mapping that should be visible immediately in Explorer. // Seems to be invisible in Explorer on Windows 8, but visibile in an elevated cmd shell. //Assert.IsTrue(Directory.Exists(_driveLetter), "Drive letter not visible."); Console.WriteLine("\nDrive Letter: [{0}]\tGetVolumeDevice(): [{1}]", drive, Volume.GetVolumeDeviceName(drive)); Assert.AreEqual(diSysIo.IsReady, di.IsReady); } finally { StopWatcher(true); // Remove Regular drive mapping. actionIsTrue = false; try { Volume.DeleteDosDevice(drive); actionIsTrue = true; } catch { } Console.WriteLine("\n\nRemoved Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\n\t{2}\n", actionIsTrue, drive, Reporter(true)); Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been removed."); Assert.IsFalse(Directory.Exists(drive), "Drive letter should not be visible."); } #endregion // Regular Drive Mapping #region Symbolic Link Drive Mapping try { drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(true), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); StopWatcher(true); // Create Symbolic Link. bool createSymbolicLink = false; try { Volume.DefineDosDevice(drive, TempFolder, DosDeviceAttributes.RawTargetPath); createSymbolicLink = true; } catch { } Console.WriteLine("\n\nCreated Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", createSymbolicLink, drive, TempFolder, Reporter(true)); Assert.IsTrue(createSymbolicLink); di = new DriveInfo(drive); Assert.IsTrue(Dump(di, -21)); // The link is created in the NT Device Name namespace and thus not visibile in Explorer. // Remove Symbolic Link, no exact match: fail. StopWatcher(true); bool removeSymbolicLink = false; try { Volume.DeleteDosDevice(drive, "NonExistingFolder", true); removeSymbolicLink = true; } catch { } Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be False): [{0}]\nDrive letter: [{1}] has NOT been set free.\tNo exactMatch MS-DOS device name found.\n\t{2}", removeSymbolicLink, drive, Reporter(true)); Assert.IsFalse(removeSymbolicLink); } finally { StopWatcher(true); // Remove Symbolic Link, exact match: success. bool removeSymbolicLink = false; try { Volume.DeleteDosDevice(drive, TempFolder, true); removeSymbolicLink = true; } catch { } Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\tFound exactMatch MS-DOS device name.\n\t{2}", removeSymbolicLink, drive, Reporter(true)); Assert.IsTrue(removeSymbolicLink); Assert.IsFalse(Directory.Exists(drive)); } #endregion // Symbolic Link Drive Mapping }
public void DefineDosDevice() { Console.WriteLine("Volume.DefineDosDevice()"); if (!IsAdmin()) Assert.Fail(); #region Regular Drive Mapping string drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); StopWatcher(true); // Create Regular drive mapping. bool actionIsTrue = false; try { Volume.DefineDosDevice(drive, TempFolder); actionIsTrue = true; } catch { } Console.WriteLine("\nCreated Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", actionIsTrue, drive, TempFolder, Reporter(true)); Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been created."); DriveInfo di = new DriveInfo(drive); System.IO.DriveInfo diSysIo = new System.IO.DriveInfo(drive); try { Assert.IsTrue(Dump(di, -21)); // A Regular drive mapping that should be visible immediately in Explorer. // Seems to be invisible in Explorer on Windows 8, but visibile in an elevated cmd shell. //Assert.IsTrue(Directory.Exists(_driveLetter), "Drive letter not visible."); Console.WriteLine("\nDrive Letter: [{0}]\tGetVolumeDevice(): [{1}]", drive, Volume.GetVolumeDeviceName(drive)); Assert.AreEqual(diSysIo.IsReady, di.IsReady); } finally { StopWatcher(true); // Remove Regular drive mapping. actionIsTrue = false; try { Volume.DeleteDosDevice(drive); actionIsTrue = true; } catch { } Console.WriteLine("\n\nRemoved Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\n\t{2}\n", actionIsTrue, drive, Reporter(true)); Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been removed."); Assert.IsFalse(Directory.Exists(drive), "Drive letter should not be visible."); } #endregion // Regular Drive Mapping #region Symbolic Link Drive Mapping try { drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(true), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); StopWatcher(true); // Create Symbolic Link. bool createSymbolicLink = false; try { Volume.DefineDosDevice(drive, TempFolder, DosDeviceAttributes.RawTargetPath); createSymbolicLink = true; } catch { } Console.WriteLine("\n\nCreated Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", createSymbolicLink, drive, TempFolder, Reporter(true)); Assert.IsTrue(createSymbolicLink); di = new DriveInfo(drive); Assert.IsTrue(Dump(di, -21)); // The link is created in the NT Device Name namespace and thus not visibile in Explorer. // Remove Symbolic Link, no exact match: fail. StopWatcher(true); bool removeSymbolicLink = false; try { Volume.DeleteDosDevice(drive, "NonExistingFolder", true); removeSymbolicLink = true; } catch { } Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be False): [{0}]\nDrive letter: [{1}] has NOT been set free.\tNo exactMatch MS-DOS device name found.\n\t{2}", removeSymbolicLink, drive, Reporter(true)); Assert.IsFalse(removeSymbolicLink); } finally { StopWatcher(true); // Remove Symbolic Link, exact match: success. bool removeSymbolicLink = false; try { Volume.DeleteDosDevice(drive, TempFolder, true); removeSymbolicLink = true; } catch { } Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\tFound exactMatch MS-DOS device name.\n\t{2}", removeSymbolicLink, drive, Reporter(true)); Assert.IsTrue(removeSymbolicLink); Assert.IsFalse(Directory.Exists(drive)); } #endregion // Symbolic Link Drive Mapping }
private static void DumpClassDriveInfo(bool isLocal, string drive) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? Local : Network); string tempPath = drive; if (!isLocal) tempPath = Path.LocalToUnc(tempPath); StopWatcher(true); DriveInfo actual = new DriveInfo(tempPath); Console.WriteLine("\nInput Path: [{0}]{1}", tempPath, Reporter()); #region Local Drive if (isLocal) { // System.IO.DriveInfo() can not handle UNC paths. System.IO.DriveInfo expected = new System.IO.DriveInfo(tempPath); //Dump(expected, -21); // Even 1 byte more or less results in failure, so do these tests asap. Assert.AreEqual(expected.AvailableFreeSpace, actual.AvailableFreeSpace, "AvailableFreeSpace AlphaFS != System.IO"); Assert.AreEqual(expected.TotalFreeSpace, actual.TotalFreeSpace, "TotalFreeSpace AlphaFS != System.IO"); Assert.AreEqual(expected.TotalSize, actual.TotalSize, "TotalSize AlphaFS != System.IO"); Assert.AreEqual(expected.DriveFormat, actual.DriveFormat, "DriveFormat AlphaFS != System.IO"); Assert.AreEqual(expected.DriveType, actual.DriveType, "DriveType AlphaFS != System.IO"); Assert.AreEqual(expected.IsReady, actual.IsReady, "IsReady AlphaFS != System.IO"); Assert.AreEqual(expected.Name, actual.Name, "Name AlphaFS != System.IO"); Assert.AreEqual(expected.RootDirectory.ToString(), actual.RootDirectory.ToString(), "RootDirectory AlphaFS != System.IO"); Assert.AreEqual(expected.VolumeLabel, actual.VolumeLabel, "VolumeLabel AlphaFS != System.IO"); } #region Class Equality ////int getHashCode1 = actual.GetHashCode(); //DriveInfo driveInfo2 = new DriveInfo(tempPath); ////int getHashCode2 = driveInfo2.GetHashCode(); //DriveInfo clone = actual; ////int getHashCode3 = clone.GetHashCode(); //bool isTrue1 = clone.Equals(actual); //bool isTrue2 = clone == actual; //bool isTrue3 = !(clone != actual); //bool isTrue4 = actual == driveInfo2; //bool isTrue5 = !(actual != driveInfo2); ////Console.WriteLine("\n\t\t actual.GetHashCode() : [{0}]", getHashCode1); ////Console.WriteLine("\t\t clone.GetHashCode() : [{0}]", getHashCode3); ////Console.WriteLine("\t\tdriveInfo2.GetHashCode() : [{0}]\n", getHashCode2); ////Console.WriteLine("\t\t obj clone.ToString() == [{0}]", clone.ToString()); ////Console.WriteLine("\t\t obj clone.Equals() == [{0}] : {1}", TextTrue, isTrue1); ////Console.WriteLine("\t\t obj clone == == [{0}] : {1}", TextTrue, isTrue2); ////Console.WriteLine("\t\t obj clone != == [{0}]: {1}\n", TextFalse, isTrue3); ////Console.WriteLine("\t\tdriveInfo == driveInfo2 == [{0}] : {1}", TextTrue, isTrue4); ////Console.WriteLine("\t\tdriveInfo != driveInfo2 == [{0}] : {1}", TextFalse, isTrue5); //Assert.IsTrue(isTrue1, "clone.Equals(actual)"); //Assert.IsTrue(isTrue2, "clone == actual"); //Assert.IsTrue(isTrue3, "!(clone != actual)"); //Assert.IsTrue(isTrue4, "actual == driveInfo2"); //Assert.IsTrue(isTrue5, "!(actual != driveInfo2)"); #endregion // Class Equality #endregion // Local Drive StopWatcher(true); Dump(actual, -21); Dump(actual.DiskSpaceInfo, -26); //if (expected != null) Dump(expected.RootDirectory, -17); //Dump(actual.RootDirectory, -17); Dump(actual.VolumeInfo, -26); Console.WriteLine(Reporter()); Console.WriteLine(); }
private void DumpClassDriveInfo(bool isLocal, string drive) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network); var tempPath = drive; if (!isLocal) { tempPath = Path.LocalToUnc(tempPath); } UnitTestConstants.StopWatcher(true); var actual = new DriveInfo(tempPath); Console.WriteLine("\nInput Path: [{0}]{1}", tempPath, UnitTestConstants.Reporter()); #region UnitTestConstants.Local Drive if (isLocal) { // System.IO.DriveInfo() can not handle UNC paths. var expected = new System.IO.DriveInfo(tempPath); //Dump(expected, -21); // Even 1 byte more or less results in failure, so do these tests asap. Assert.AreEqual(expected.AvailableFreeSpace, actual.AvailableFreeSpace, "AvailableFreeSpace AlphaFS != System.IO"); Assert.AreEqual(expected.TotalFreeSpace, actual.TotalFreeSpace, "TotalFreeSpace AlphaFS != System.IO"); Assert.AreEqual(expected.TotalSize, actual.TotalSize, "TotalSize AlphaFS != System.IO"); Assert.AreEqual(expected.DriveFormat, actual.DriveFormat, "DriveFormat AlphaFS != System.IO"); Assert.AreEqual(expected.DriveType, actual.DriveType, "DriveType AlphaFS != System.IO"); Assert.AreEqual(expected.IsReady, actual.IsReady, "IsReady AlphaFS != System.IO"); Assert.AreEqual(expected.Name, actual.Name, "Name AlphaFS != System.IO"); Assert.AreEqual(expected.RootDirectory.ToString(), actual.RootDirectory.ToString(), "RootDirectory AlphaFS != System.IO"); Assert.AreEqual(expected.VolumeLabel, actual.VolumeLabel, "VolumeLabel AlphaFS != System.IO"); } #region Class Equality ////int getHashCode1 = actual.GetHashCode(); //DriveInfo driveInfo2 = new DriveInfo(tempPath); ////int getHashCode2 = driveInfo2.GetHashCode(); //DriveInfo clone = actual; ////int getHashCode3 = clone.GetHashCode(); //bool isTrue1 = clone.Equals(actual); //bool isTrue2 = clone == actual; //bool isTrue3 = !(clone != actual); //bool isTrue4 = actual == driveInfo2; //bool isTrue5 = !(actual != driveInfo2); ////Console.WriteLine("\n\t\t actual.GetHashCode() : [{0}]", getHashCode1); ////Console.WriteLine("\t\t clone.GetHashCode() : [{0}]", getHashCode3); ////Console.WriteLine("\t\tdriveInfo2.GetHashCode() : [{0}]\n", getHashCode2); ////Console.WriteLine("\t\t obj clone.ToString() == [{0}]", clone.ToString()); ////Console.WriteLine("\t\t obj clone.Equals() == [{0}] : {1}", TextTrue, isTrue1); ////Console.WriteLine("\t\t obj clone == == [{0}] : {1}", TextTrue, isTrue2); ////Console.WriteLine("\t\t obj clone != == [{0}]: {1}\n", TextFalse, isTrue3); ////Console.WriteLine("\t\tdriveInfo == driveInfo2 == [{0}] : {1}", TextTrue, isTrue4); ////Console.WriteLine("\t\tdriveInfo != driveInfo2 == [{0}] : {1}", TextFalse, isTrue5); //Assert.IsTrue(isTrue1, "clone.Equals(actual)"); //Assert.IsTrue(isTrue2, "clone == actual"); //Assert.IsTrue(isTrue3, "!(clone != actual)"); //Assert.IsTrue(isTrue4, "actual == driveInfo2"); //Assert.IsTrue(isTrue5, "!(actual != driveInfo2)"); #endregion // Class Equality #endregion // UnitTestConstants.Local Drive UnitTestConstants.StopWatcher(true); UnitTestConstants.Dump(actual, -21); UnitTestConstants.Dump(actual.DiskSpaceInfo, -26); //if (expected != null) Dump(expected.RootDirectory, -17); //Dump(actual.RootDirectory, -17); UnitTestConstants.Dump(actual.VolumeInfo, -26); Console.WriteLine(UnitTestConstants.Reporter()); Console.WriteLine(); }