Skip to content

MockFileSystem: Directory and DirectoryInfo "Exists_ForwardSlash_ShouldReturnTrue" tests are failing under certain circumstances #888

@seiben-dev

Description

@seiben-dev

Hello there,

I was playing around with the idea of adding a feature to this library, but I noticed that some tests were always failing even tough I didn't change anything yet.

The tests in question are:

  • Testably.Abstractions.Tests.FileSystem.Directory.ExistsTests+MockFileSystemTests.Exists_ForwardSlash_ShouldReturnTrue
  • Testably.Abstractions.Tests.FileSystem.DirectoryInfo.ExistsTests+MockFileSystemTests.Exists_ForwardSlash_ShouldReturnTrue

I've tried to debug the issue a little bit and for both tests I ended up in Testably.Abstractions.Testing.Helpers.Execute.GetFullPath(string) where in the end System.IO.Path.GetFullPath("/") is called and the result is then returned (which was "E:\\" in my case because that's where I cloned the code to). This returned path seemed to cause the issues, so to verify that I copied the project to my D: drive, ran the tests again, and both of the tests suddenly passed 😄.

So it looks like System.IO.Path.GetFullPath(string) is aware of the current drive of the application and thus the tests pass or fail depending on the current drive. So running the tests from any drive other than D: will currently result in failing tests, because of the FileSystem.InitializeIn("D:") at the start of the two tests.

(I guess it's obvious by now, but I'm using a Windows machine (Windows 11 25H2))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions