public void GetDirectoryRoot_WithRelativePath_ReturnsCurrentDirRoot() { var originalDir = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(@"C:\Windows\"); var root = Directory.GetDirectoryRoot(@"\Windows"); Assert.That(root, Is.EqualTo(@"C:\")); Directory.SetCurrentDirectory(originalDir); }
public void GetDiskFreeSpace() { const string path = @"C:\temp"; var dsi = Volume.GetDiskFreeSpace(path, false); Console.WriteLine($"FreeBytesAvailable {dsi.FreeBytesAvailable}"); Console.WriteLine($"TotalNumberOfBytes {dsi.TotalNumberOfBytes}"); var p = Directory.GetDirectoryRoot(path); Console.WriteLine($"GetDirectoryRoot {path} => {p}"); }
public void GetFullPath_GetDirectoryRoot_Behave_Like_SystemIO() { // BUG in AlphaFS. Path.FullGetPath() // BUG in AlphaFS. Path.GetDirectoryRoot() // if G: is G:\Test then it returns G: // if G: is G:\ then it returns G: // Where as System.IO.Path // if G: is G:\Test then it returns G:\Test // if G: is G:\ then it returns G:\ var originalDir = Directory.GetCurrentDirectory(); Console.WriteLine($"0 Directory.GetCurrentDirectory() {Directory.GetCurrentDirectory()}"); Console.WriteLine(); var alphaFP = Path.GetFullPath(@"C:"); var ioFP = System.IO.Path.GetFullPath(@"C:"); Console.WriteLine($"0 Alphaleonis.Win32.Filesystem.Path.GetFullPath(@\"C:\") {alphaFP}"); Console.WriteLine($"0 System.IO.Path.GetFullPath(@\"C:\") {ioFP}"); Console.WriteLine(); Assert.That(alphaFP, Is.EqualTo(ioFP)); Console.WriteLine( $"0 Alphaleonis.Win32.Filesystem.Directory.GetDirectoryRoot(@\"C:\") {Directory.GetDirectoryRoot(@"C:")}"); Console.WriteLine( $"0 System.IO.Directory.GetDirectoryRoot(@\"C:\") {System.IO.Directory.GetDirectoryRoot(@"C:")}"); Console.WriteLine(); Assert.That(Directory.GetDirectoryRoot(@"C:"), Is.EqualTo(System.IO.Directory.GetDirectoryRoot(@"C:"))); Directory.SetCurrentDirectory(@"C:\Windows\"); Console.WriteLine($"1 Directory.GetCurrentDirectory() {Directory.GetCurrentDirectory()}"); Console.WriteLine($"1 Alphaleonis.Win32.Filesystem.Path.GetFullPath(@\"C:\") {Path.GetFullPath(@"C:")}"); Console.WriteLine($"1 System.IO.Path.GetFullPath(@\"C:\") {System.IO.Path.GetFullPath(@"C:")}"); Console.WriteLine(); Assert.That(Path.GetFullPath(@"C:"), Is.EqualTo(System.IO.Path.GetFullPath(@"C:"))); Directory.SetCurrentDirectory(@"C:\"); Console.WriteLine($"2 Directory.GetCurrentDirectory() {Directory.GetCurrentDirectory()}"); Console.WriteLine($"2 Alphaleonis.Win32.Filesystem.Path.GetFullPath(@\"C:\") {Path.GetFullPath(@"C:")}"); Console.WriteLine($"2 System.IO.Path.GetFullPath(@\"C:\") {System.IO.Path.GetFullPath(@"C:")}"); Console.WriteLine(); Assert.That(Path.GetFullPath(@"C:"), Is.EqualTo(System.IO.Path.GetFullPath(@"C:"))); Directory.SetCurrentDirectory(originalDir); Console.WriteLine($"3 Directory.GetCurrentDirectory() {Directory.GetCurrentDirectory()}"); Console.WriteLine($"3 Alphaleonis.Win32.Filesystem.Path.GetFullPath(@\"C:\") {Path.GetFullPath(@"C:")}"); Console.WriteLine($"3 System.IO.Path.GetFullPath(@\"C:\") {System.IO.Path.GetFullPath(@"C:")}"); Console.WriteLine(); Assert.That(Path.GetFullPath(@"C:"), Is.EqualTo(System.IO.Path.GetFullPath(@"C:"))); }
public void Directory_GetDirectoryRoot() { Console.WriteLine("Directory.GetDirectoryRoot()"); var pathCnt = 0; var errorCnt = 0; #region ArgumentException var gotException = false; try { Directory.GetDirectoryRoot(@"\\\\.txt"); } catch (Exception ex) { var exName = ex.GetType().Name; gotException = exName.Equals("ArgumentException", StringComparison.OrdinalIgnoreCase); Console.WriteLine("\n\tCaught {0} Exception: [{1}] {2}", gotException ? "EXPECTED" : "UNEXPECTED", exName, ex.Message); } Assert.IsTrue(gotException, "The exception is not caught, but is expected to."); Console.WriteLine(); #endregion // ArgumentException UnitTestConstants.StopWatcher(true); foreach (var path in UnitTestConstants.InputPaths) { string expected = null; string actual = null; var skipAssert = false; Console.WriteLine("\n#{0:000}\tInput Path: [{1}]", ++pathCnt, path); // System.IO try { expected = System.IO.Directory.GetDirectoryRoot(path); } catch (Exception ex) { skipAssert = ex is ArgumentException; Console.WriteLine("\tCaught [System.IO] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t System.IO : [{0}]", expected ?? "null"); // AlphaFS try { actual = Directory.GetDirectoryRoot(path); if (!skipAssert) { Assert.AreEqual(expected, actual); } } catch (Exception ex) { errorCnt++; Console.WriteLine("\tCaught [AlphaFS] {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } Console.WriteLine("\t AlphaFS : [{0}]", actual ?? "null"); } Console.WriteLine("\n{0}", UnitTestConstants.Reporter(true)); Assert.AreEqual(0, errorCnt, "Encountered paths where AlphaFS != System.IO"); }