diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index fa5c57430..1b0822646 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs @@ -14,7 +14,6 @@ namespace System.IO.Abstractions.TestingHelpers; public class MockFileSystem : FileSystemBase, IMockFileDataAccessor { private const string DEFAULT_CURRENT_DIRECTORY = @"C:\"; - private const string TEMP_DIRECTORY = @"C:\temp\"; private readonly IDictionary files; private readonly IDictionary drives; @@ -58,7 +57,9 @@ public MockFileSystem(IDictionary files, MockFileSystemOpt throw new ArgumentException("Current directory needs to be rooted.", nameof(currentDirectory)); } - var defaultTempDirectory = XFS.Path(TEMP_DIRECTORY); + var defaultTempDirectory = !string.IsNullOrEmpty(options.TemporaryDirectory) + ? options.TemporaryDirectory + : System.IO.Path.GetTempPath(); StringOperations = new StringOperations(XFS.IsUnixPlatform()); pathVerifier = new PathVerifier(this); diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs index f6f19dbf3..791e4c2ab 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs @@ -14,4 +14,10 @@ public class MockFileSystemOptions /// Flag indicating, if a temporary directory should be created. /// public bool CreateDefaultTempDir { get; init; } = true; + + /// + /// The temporary directory used by the . + /// Defaults to when or empty. + /// + public string? TemporaryDirectory { get; init; } } \ No newline at end of file diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs index e614de495..4e7e6f347 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs @@ -412,6 +412,19 @@ public async Task GetTempPath_Called_ReturnsStringLengthGreaterThanZero(string t await That(result.Length > 0).IsTrue(); } + [Test] + public async Task GetTempPath_Default_MatchesRealOsTempPath() + { + //Arrange + var mockPath = new MockFileSystem().Path; + + //Act + var result = mockPath.GetTempPath(); + + //Assert + await That(result).IsEqualTo(System.IO.Path.GetTempPath()); + } + [Test] public async Task GetTempPath_Called_WithNonNullVirtualTempDirectory_ReturnsVirtualTempDirectory() {