Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, FileSystemEntry> files;
private readonly IDictionary<string, MockDriveData> drives;
Expand Down Expand Up @@ -58,7 +57,9 @@ public MockFileSystem(IDictionary<string, MockFileData> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ public class MockFileSystemOptions
/// Flag indicating, if a temporary directory should be created.
/// </summary>
public bool CreateDefaultTempDir { get; init; } = true;

/// <summary>
/// The temporary directory used by the <see cref="MockFileSystem" />.
/// Defaults to <see cref="System.IO.Path.GetTempPath()" /> when <see langword="null" /> or empty.
/// </summary>
public string? TemporaryDirectory { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading