Skip to content

Commit fe8f1db

Browse files
authored
fix: Make MockDirectory.Exists behavior with forward slash on Windows consistent with actual file system (#1245)
# Changes - Removed Unix OS check in `MockDirectory.Exists` - Added additional tests for `MockDirectory`, `MockDirectoryInfo`, `FileSystem.Directory`
1 parent 645a559 commit fe8f1db

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public override void Delete(string path, bool recursive)
174174
/// <inheritdoc />
175175
public override bool Exists(string path)
176176
{
177-
if (path == "/" && XFS.IsUnixPlatform())
177+
if (path == "/")
178178
{
179179
return true;
180180
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ public async Task Move_Directory_DoesNotThrow_When_Target_Directory_Parent_Exist
21812181
string sourceDirName,
21822182
string targetDirName)
21832183
{
2184-
// Arange
2184+
// Arrange
21852185
var fileSystem = new MockFileSystem();
21862186
fileSystem.Directory.CreateDirectory(sourceDirName);
21872187

@@ -2192,4 +2192,16 @@ public async Task Move_Directory_DoesNotThrow_When_Target_Directory_Parent_Exist
21922192
await That(fileSystem.Directory.Exists(targetDirName)).IsTrue();
21932193
await That(fileSystem.Directory.Exists(sourceDirName)).IsFalse();
21942194
}
2195+
2196+
[Test]
2197+
public async Task MockDirectory_Exists_ShouldReturnTrue_IfArgIsFrontSlashAndRootDirExists()
2198+
{
2199+
string testDir = XFS.Path(@"c:\foo\bar\");
2200+
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
2201+
{
2202+
{ testDir, new MockDirectoryData() }
2203+
});
2204+
2205+
await That(fileSystem.Directory.Exists("/")).IsEqualTo(true);
2206+
}
21952207
}

0 commit comments

Comments
 (0)