Skip to content

Commit bf29359

Browse files
Mpdreamzclaude
andcommitted
fix: MockFileSystem.GetTempPath() now returns real OS temp path by default
Replace the hardcoded C:\temp\ constant (converted via XFS.Path) with System.IO.Path.GetTempPath() so the default mirrors the actual environment. Callers can still override by passing an explicit temp directory. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 7e5f54a commit bf29359

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace System.IO.Abstractions.TestingHelpers;
1414
public class MockFileSystem : FileSystemBase, IMockFileDataAccessor
1515
{
1616
private const string DEFAULT_CURRENT_DIRECTORY = @"C:\";
17-
private const string TEMP_DIRECTORY = @"C:\temp\";
1817

1918
private readonly IDictionary<string, FileSystemEntry> files;
2019
private readonly IDictionary<string, MockDriveData> drives;
@@ -58,7 +57,7 @@ public MockFileSystem(IDictionary<string, MockFileData> files, MockFileSystemOpt
5857
throw new ArgumentException("Current directory needs to be rooted.", nameof(currentDirectory));
5958
}
6059

61-
var defaultTempDirectory = XFS.Path(TEMP_DIRECTORY);
60+
var defaultTempDirectory = System.IO.Path.GetTempPath();
6261

6362
StringOperations = new StringOperations(XFS.IsUnixPlatform());
6463
pathVerifier = new PathVerifier(this);

tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockPathTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,19 @@ public async Task GetTempPath_Called_ReturnsStringLengthGreaterThanZero(string t
412412
await That(result.Length > 0).IsTrue();
413413
}
414414

415+
[Test]
416+
public async Task GetTempPath_Default_MatchesRealOsTempPath()
417+
{
418+
//Arrange
419+
var mockPath = new MockFileSystem().Path;
420+
421+
//Act
422+
var result = mockPath.GetTempPath();
423+
424+
//Assert
425+
await That(result).IsEqualTo(System.IO.Path.GetTempPath());
426+
}
427+
415428
[Test]
416429
public async Task GetTempPath_Called_WithNonNullVirtualTempDirectory_ReturnsVirtualTempDirectory()
417430
{

0 commit comments

Comments
 (0)