public void TestUncBehaviourOfGetPathRoot() { if (!Platform.IsClientWindows) { return; } var root = @"C:" + Util.DirectorySeparatorString; var filename = "test.txt"; var filePath = root + filename; var filePathWithExtendedDevicePathPrefix = SystemIOWindows.AddExtendedDevicePathPrefix(filePath); var filePathWithExtendedDevicePathPrefixRoot = SystemIO.IO_WIN.GetPathRoot(filePathWithExtendedDevicePathPrefix); //Prefixed with extended device path prefix remains prefixed Assert.AreEqual(SystemIOWindows.AddExtendedDevicePathPrefix(root), filePathWithExtendedDevicePathPrefixRoot); //Without extended device path prefix, no prefix. var filePathRoot = SystemIO.IO_WIN.GetPathRoot(filePath); Assert.AreEqual(root, filePathRoot); }
public void TestAddExtendedDevicePathPrefixInWindowsClient() { if (!Platform.IsClientWindows) { return; } var testCasesLeavingPathUnchanged = new[] { // Normalization of basic relative paths, with both kinds of slashes @".", @"temp", @"temp\file.txt", @"\", @"/", @"\temp", @"/temp", @"/temp/file.txt", // Normalization of full qualified paths, but with relative components, with both kinds of slashes @"C:\temp\.", @"C:/temp/.", @"C:\temp\..", @"C:/temp/..", @"C:\temp\..\folder", @"C:/temp/../folder", @"C:\temp\.\file.txt", @"C:/temp/./file.txt", @"\\example.com\share\.", @"//example.com/share/.", @"\\example.com\share\..", @"//example.com/share/..", @"\\example.com\share\..\folder", @"//example.com/share/../folder", @"\\example.com\share\.\file.txt", @"//example.com/share/./file.txt", // Normalization disabled for paths with @"\\?\" prefix @"\\?\C:\", @"\\?\C:\temp", @"\\?\C:\temp\file.txt", @"\\?\C:\temp.", @"\\?\C:\temp.\file.txt", @"\\?\C:\temp.\file.txt.", @"\\?\C:\temp ", @"\\?\C:\temp\file.txt ", @"\\?\C:\", @"\\?\UNC\example.com\share", @"\\?\UNC\example.com\share\file.txt", @"\\?\UNC\example.com\share.", @"\\?\UNC\example.com\share.\file.txt", @"\\?\UNC\example.com\share.\file.txt.", @"\\?\UNC\example.com\share ", @"\\?\UNC\example.com\share\file.txt " }; foreach (var path in testCasesLeavingPathUnchanged) { var actual = SystemIOWindows.AddExtendedDevicePathPrefix(path); var expected = path; Assert.AreEqual(expected, actual, $"Path: {path}"); } var testCasesWherePrefixIsApplied = new Dictionary <string, string>() { // Fully qualified paths with no relative components, with both kinds of slashes { @"C:\", @"\\?\C:\" }, { @"C:/", @"\\?\C:\" }, { @"C:\temp", @"\\?\C:\temp" }, { @"C:/temp", @"\\?\C:\temp" }, { @"C:\temp\file.txt", @"\\?\C:\temp\file.txt" }, { @"C:/temp/file.txt", @"\\?\C:\temp\file.txt" }, { @"\\example.com\share", @"\\?\UNC\example.com\share" }, { @"//example.com/share", @"\\?\UNC\example.com\share" }, { @"\\example.com\share\file.txt", @"\\?\UNC\example.com\share\file.txt" }, { @"//example.com/share/file.txt", @"\\?\UNC\example.com\share\file.txt" }, // Fully qualified paths with no relative components, but with problematic names, with both kinds of slashes { @"C:\temp.", @"\\?\C:\temp." }, { @"C:/temp.", @"\\?\C:\temp." }, { @"C:\temp.\file.txt", @"\\?\C:\temp.\file.txt" }, { @"C:/temp./file.txt", @"\\?\C:\temp.\file.txt" }, { @"C:\temp.\file.txt.", @"\\?\C:\temp.\file.txt." }, { @"C:/temp./file.txt.", @"\\?\C:\temp.\file.txt." }, { @"C:\temp ", @"\\?\C:\temp " }, { @"C:/temp ", @"\\?\C:\temp " }, { @"C:\temp\file.txt ", @"\\?\C:\temp\file.txt " }, { @"C:/temp/file.txt ", @"\\?\C:\temp\file.txt " }, { @"\\example.com\share.", @"\\?\UNC\example.com\share." }, { @"//example.com/share.", @"\\?\UNC\example.com\share." }, { @"\\example.com\share\file.txt.", @"\\?\UNC\example.com\share\file.txt." }, { @"//example.com/share./file.txt.", @"\\?\UNC\example.com\share.\file.txt." }, { @"\\example.com\share ", @"\\?\UNC\example.com\share " }, { @"//example.com/share ", @"\\?\UNC\example.com\share " }, { @"\\example.com\share\file.txt ", @"\\?\UNC\example.com\share\file.txt " }, { @"//example.com/share/file.txt ", @"\\?\UNC\example.com\share\file.txt " } }; foreach (var keyValuePair in testCasesWherePrefixIsApplied) { var path = keyValuePair.Key; var actual = SystemIOWindows.AddExtendedDevicePathPrefix(path); var expected = keyValuePair.Value; Assert.AreEqual(expected, actual, $"Path: {path}"); } }