From bf29359bba2390591d9abab4543806845e657294 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 1 Apr 2026 09:01:42 +0200 Subject: [PATCH 1/4] 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) --- .../MockFileSystem.cs | 3 +-- .../MockPathTests.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index fa5c57430..0cb2e7c0b 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,7 @@ public MockFileSystem(IDictionary files, MockFileSystemOpt throw new ArgumentException("Current directory needs to be rooted.", nameof(currentDirectory)); } - var defaultTempDirectory = XFS.Path(TEMP_DIRECTORY); + var defaultTempDirectory = System.IO.Path.GetTempPath(); StringOperations = new StringOperations(XFS.IsUnixPlatform()); pathVerifier = new PathVerifier(this); 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() { From be27a00856cfb0d72c916dfc7840ac4ce7ea8e94 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 1 Apr 2026 09:27:56 +0200 Subject: [PATCH 2/4] fix: add TemporaryDirectory to MockFileSystemOptions Addresses CoPilot review feedback: the PR description referenced MockFileSystemOptions as a way to set a custom temp directory, but the option did not exist. Added TemporaryDirectory (nullable string) that, when set, is used instead of System.IO.Path.GetTempPath(). Co-Authored-By: Claude Sonnet 4.6 (1M context) --- .../MockFileSystem.cs | 4 +++- .../MockFileSystemOptions.cs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs index 0cb2e7c0b..1b0822646 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystem.cs @@ -57,7 +57,9 @@ public MockFileSystem(IDictionary files, MockFileSystemOpt throw new ArgumentException("Current directory needs to be rooted.", nameof(currentDirectory)); } - var defaultTempDirectory = System.IO.Path.GetTempPath(); + 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..7ac956f05 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 temp directory returned by on the . + /// Defaults to when or empty. + /// + public string? TemporaryDirectory { get; init; } } \ No newline at end of file From 45889b4bdcd042156112665a05ab0fcd1e248ad3 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Wed, 1 Apr 2026 12:09:52 +0200 Subject: [PATCH 3/4] fix: remove nullable annotation from TemporaryDirectory The project does not enable nullable reference types, so string? causes CS8632 across all target frameworks. Plain string with IsNullOrEmpty guard achieves the same result. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- .../MockFileSystemOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs index 7ac956f05..b3a9668a1 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs @@ -19,5 +19,5 @@ public class MockFileSystemOptions /// The temp directory returned by on the . /// Defaults to when or empty. /// - public string? TemporaryDirectory { get; init; } + public string TemporaryDirectory { get; init; } } \ No newline at end of file From 4c004fc73ebcf162e2e75441529c5226bcce51ed Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Thu, 2 Apr 2026 19:49:05 +0200 Subject: [PATCH 4/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks @vbreuss applied your updates ! Co-authored-by: Valentin Breuß --- .../MockFileSystemOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs index b3a9668a1..791e4c2ab 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockFileSystemOptions.cs @@ -16,8 +16,8 @@ public class MockFileSystemOptions public bool CreateDefaultTempDir { get; init; } = true; /// - /// The temp directory returned by on the . + /// The temporary directory used by the . /// Defaults to when or empty. /// - public string TemporaryDirectory { get; init; } + public string? TemporaryDirectory { get; init; } } \ No newline at end of file