Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make MockFileSystem's File.WriteAllText, File.ReadAllText and Directo…
…ry.GetFiles support extended length paths too
  • Loading branch information
mostynb committed Jul 6, 2025
commit 0918171f91fb85fd3ea9c7e2a7e52096ee4d1c0f
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public void IsLegalAbsoluteOrRelative(string path, string paramName)

private static bool IsValidUseOfVolumeSeparatorChar(string path)
{
const string EXTENDED_LENGTH_PATH_PREFIX = @"\\?\";
if (path.StartsWith(EXTENDED_LENGTH_PATH_PREFIX))
{
path = path.Substring(EXTENDED_LENGTH_PATH_PREFIX.Length);
}

var lastVolSepIndex = path.LastIndexOf(Path.VolumeSeparatorChar);
return lastVolSepIndex == -1 || lastVolSepIndex == 1 && char.IsLetter(path[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,14 @@ public async Task MockDirectory_CreateDirectory_ShouldSupportExtendedLengthPaths

// Act
var directoryInfo = fileSystem.Directory.CreateDirectory(XFS.Path(@"\\?\c:\bar"));
fileSystem.File.WriteAllText(@"\\?\c:\bar\grok.txt", "hello world\n");

// Assert
await That(fileSystem.Directory.Exists(XFS.Path(@"\\?\c:\bar"))).IsTrue();
await That(directoryInfo.FullName).IsEqualTo(@"\\?\c:\bar");
await That(fileSystem.File.ReadAllText(@"\\?\c:\bar\grok.txt")).IsEqualTo("hello world\n");
await That(fileSystem.Directory.GetFiles(@"\\?\c:\bar")).HasSingle()
.Which.IsEqualTo(@"\\?\c:\bar\grok.txt");
}

// Issue #210
Expand Down