Skip to content

MockFileSystem.Directory.GetFiles bug with relative path #475

@sa-he

Description

@sa-he

I hope the following code is self explaining:

[Fact]
public void RelativePathBugTest()
{
    // arrange
    var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
    const string dir = @"C:\test";
    fileSystem.Directory.SetCurrentDirectory(dir);
    fileSystem.AddFile($@"C:\test.txt", new MockFileData("Some ASCII text."));

    fileSystem.File.Exists(@"C:\test.txt").Should().BeTrue();
    fileSystem.File.Exists(@"..\test.txt").Should().BeTrue(); // relative path works fine

    fileSystem.Directory.GetFiles(@"C:\").Length.Should().Be(1);
    fileSystem.Directory.GetFiles(@"..\").Length.Should().Be(1); // this line fails. 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helperstype: 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