public void FinalPathNameLongPathPrefixRoundTripBehavior() { using (var cleaner = new TestFileCleaner(false)) { string longPath = PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500); string filePath = Paths.Combine(longPath, Path.GetRandomFileName()); IFileService system = new FileService(); system.CreateDirectory(longPath); system.WriteAllText(filePath, "FinalPathNameLongPathPrefixRoundTripBehavior"); // The wrapper for create file will add \\?\, we shouldn't get it back using (var handle = NativeMethods.FileManagement.CreateFile(filePath, FileAccess.Read, FileShare.ReadWrite, FileMode.Open, 0)) { handle.IsInvalid.Should().BeFalse(); NativeMethods.FileManagement.GetFinalPathName(handle, NativeMethods.FileManagement.FinalPathFlags.FILE_NAME_NORMALIZED) .Should().Be(filePath); NativeMethods.FileManagement.GetFinalPathName(handle, NativeMethods.FileManagement.FinalPathFlags.FILE_NAME_OPENED) .Should().Be(filePath); NativeMethods.FileManagement.GetFinalPathName(handle, NativeMethods.FileManagement.FinalPathFlags.VOLUME_NAME_DOS) .Should().Be(filePath); NativeMethods.FileManagement.GetFinalPathName(handle, NativeMethods.FileManagement.FinalPathFlags.VOLUME_NAME_GUID) .Should().StartWith(@"Volume"); NativeMethods.FileManagement.GetFinalPathName(handle, NativeMethods.FileManagement.FinalPathFlags.VOLUME_NAME_NT) .Should().StartWith(@"\Device\"); NativeMethods.FileManagement.GetFinalPathName(handle, NativeMethods.FileManagement.FinalPathFlags.VOLUME_NAME_NONE) .Should().Be(filePath.Substring(2)); } } }
public void LongPathFileExistsTests() { using (var cleaner = new TestFileCleaner(false)) { string longPath = PathGenerator.CreatePathOfLength(cleaner.TempFolder, 500); string filePath = Paths.Combine(longPath, Path.GetRandomFileName()); IFileService system = new FileService(); system.CreateDirectory(longPath); system.WriteAllText(filePath, "FileExists"); NativeMethods.FileManagement.FileExists(filePath).Should().BeTrue(); NativeMethods.FileManagement.PathExists(filePath).Should().BeTrue(); NativeMethods.FileManagement.DirectoryExists(filePath).Should().BeFalse(); } }