TestableIO/System.IO.Abstractions

Multiple temp directories in MockFileSystem

Closed this issue · 4 comments

Describe the bug
The default temp directory, which is created automatically, is not the same as used by the MockDirectory.CreateTempSubdirectory() method.

To Reproduce
Steps to reproduce the behavior:

var fileSystem = new MockFileSystem();
var result = fileSystem.Directory.CreateTempSubdirectory();
var temp = fileSystem.Path.GetTempPath();
result.FullName.StartsWith(temp); // expected true but false

Expected behavior
It's expected that there's a single temp directory in the mocked file system but MockDirectory.CreateTempSubdirectory() uses the current user's temp path instead.

Additional context
Also there's no way to specify the temp directory manually.

Thanks for reporting, @montoner0, but I couldn't reproduce this issue. I executed the following test and it was successful:

        [Test]
        public void MockDirectory_CreateTempSubdirectory_ShouldStartWithTempPath()
        {
            var fileSystem = new MockFileSystem();
            var result = fileSystem.Directory.CreateTempSubdirectory();
            var temp = fileSystem.Path.GetTempPath();
            result.FullName.StartsWith(temp);
        }

@vbreuss
I believe you have to assert the result of the last line to fail the test.
Assert.That(result.FullName.StartsWith(temp));

Sorry, @montoner0, my bad 🙈

I created a pull request, that should fix your issue and will be published shortly.

Thanks for reporting!

This is addressed in release v21.0.22.