Skip to content

MockFileSystem directory behavior with front slash inconsistent with actual file system behavior on Windows #1244

@tbui17

Description

@tbui17

Describe the bug
Both native Directory.Exists and the wrapper FileSystem.Directory.Exists methods successfully pick up the root directory using a /. However, MockFileSystem.Directory.Exists does not on Windows.

It's also worth noting that MockFileSystem.DirectoryInfo.Exists does work.

To Reproduce

[Test]
public async Task MockDirectory_Exists_ShouldReturnTrue_IfArgIsFrontSlashAndRootDirExists()
{
    string testDir = XFS.Path(@"c:\foo\bar\");
    var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
    {
        { testDir,  new MockDirectoryData() }
    });

    await That(fileSystem.Directory.Exists("/")).IsEqualTo(true);
}

Expected behavior
Test shouldn't fail on Windows.

Additional context
OS: Windows 11
.NET Version: net9.0/net8.0/net6.0/net472
Package Version: 22.0.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: releasedIssues that are releasedtype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions