private void DumpGetDirectoryNameWithoutRoot(bool isLocal) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network); const string neDir = "Non-Existing Directory"; const string sys32 = "system32"; var fullPath = Path.Combine(Environment.SystemDirectory, neDir); if (!isLocal) { fullPath = Path.LocalToUnc(fullPath); } UnitTestConstants.StopWatcher(true); var directoryNameWithoutRoot = Path.GetDirectoryNameWithoutRoot(fullPath); Console.WriteLine("\nInput Path: [{0}]\n\tGetDirectoryNameWithoutRoot() (Should be: [{1}]): [{2}]", fullPath, sys32, directoryNameWithoutRoot); Assert.IsTrue(directoryNameWithoutRoot.Equals(sys32, StringComparison.OrdinalIgnoreCase)); fullPath = Path.Combine(fullPath, "Non-Existing file.txt"); if (!isLocal) { fullPath = Path.LocalToUnc(fullPath); } UnitTestConstants.StopWatcher(true); directoryNameWithoutRoot = Path.GetDirectoryNameWithoutRoot(fullPath); Console.WriteLine("\nInput Path: [{0}]\n\tGetDirectoryNameWithoutRoot() (Should be: [{1}]): [{2}]", fullPath, neDir, directoryNameWithoutRoot); Assert.IsTrue(directoryNameWithoutRoot.Equals(neDir, StringComparison.OrdinalIgnoreCase)); fullPath = UnitTestConstants.SysRoot; if (!isLocal) { fullPath = Path.LocalToUnc(fullPath); } UnitTestConstants.StopWatcher(true); directoryNameWithoutRoot = Path.GetDirectoryNameWithoutRoot(fullPath); Console.WriteLine("\nInput Path: [{0}]\n\tGetDirectoryNameWithoutRoot() (Should be: [null]): [{1}]", fullPath, directoryNameWithoutRoot ?? "null"); Assert.AreEqual(null, directoryNameWithoutRoot); Console.WriteLine("\n"); }
public void GetDirectoryNameWithoutRoot_OnPathPrefixSlash() { var a = Path.GetDirectoryNameWithoutRoot(@"\Data"); Assert.That(a, Is.EqualTo(null)); }