Skip to content

Commit eeb83c3

Browse files
committed
Make MockFileSystem's File.WriteAllText, File.ReadAllText and Directory.GetFiles support extended length paths too
1 parent 264f1e0 commit eeb83c3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/TestableIO.System.IO.Abstractions.TestingHelpers/PathVerifier.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public void IsLegalAbsoluteOrRelative(string path, string paramName)
6565

6666
private static bool IsValidUseOfVolumeSeparatorChar(string path)
6767
{
68+
const string EXTENDED_LENGTH_PATH_PREFIX = @"\\?\";
69+
if (path.StartsWith(EXTENDED_LENGTH_PATH_PREFIX))
70+
{
71+
path = path.Substring(EXTENDED_LENGTH_PATH_PREFIX.Length);
72+
}
73+
6874
var lastVolSepIndex = path.LastIndexOf(Path.VolumeSeparatorChar);
6975
return lastVolSepIndex == -1 || lastVolSepIndex == 1 && char.IsLetter(path[0]);
7076
}

tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,19 @@ public async Task MockDirectory_CreateDirectory_ShouldSupportExtendedLengthPaths
756756

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

760761
// Assert
761762
await That(fileSystem.Directory.Exists(XFS.Path(@"\\?\c:\bar"))).IsTrue();
762763
await That(directoryInfo.FullName).IsEqualTo(@"\\?\c:\bar");
764+
await That(fileSystem.File.ReadAllText(@"\\?\c:\bar\grok.txt")).IsEqualTo("hello world\n");
765+
var count = 0;
766+
foreach (var f in fileSystem.Directory.GetFiles(@"\\?\c:\bar"))
767+
{
768+
await That(f).IsEqualTo(@"\\?\c:\bar\grok.txt");
769+
count++;
770+
}
771+
await That(count).IsEqualTo(1);
763772
}
764773

765774
// Issue #210

0 commit comments

Comments
 (0)