Skip to content

Commit

Permalink
fix: use correct base path in Directory.CreateTempSubdirectory (#1127)
Browse files Browse the repository at this point in the history
* Add failing test
* Use correct path for temporary directory
  • Loading branch information
vbreuss committed Jun 22, 2024
1 parent f870d15 commit f42d93f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public override IDirectoryInfo CreateTempSubdirectory(string prefix = null)
// Perform directory name generation in a loop, just in case the randomly generated name already exists.
do
{
var randomDir = $"{prefix}{Path.GetRandomFileName()}";
potentialTempDirectory = Path.Combine(Path.GetTempPath(), randomDir);
var randomDir = $"{prefix}{FileSystem.Path.GetRandomFileName()}";
potentialTempDirectory = Path.Combine(FileSystem.Path.GetTempPath(), randomDir);
} while (Exists(potentialTempDirectory));

return CreateDirectoryInternal(potentialTempDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ public void MockDirectory_CreateTempSubdirectory_ShouldCreateSubdirectoryInTempD

// Assert
Assert.That(fileSystem.Directory.Exists(result.FullName), Is.True);
Assert.That(result.FullName.Contains(Path.GetTempPath()), Is.True);
Assert.That(result.FullName, Does.StartWith(fileSystem.Path.GetTempPath()));
}

[Test]
Expand All @@ -877,7 +877,7 @@ public void MockDirectory_CreateTempSubdirectoryWithPrefix_ShouldCreateDirectory
// Assert
Assert.That(fileSystem.Directory.Exists(result.FullName), Is.True);
Assert.That(Path.GetFileName(result.FullName).StartsWith("foo-"), Is.True);
Assert.That(result.FullName.Contains(Path.GetTempPath()), Is.True);
Assert.That(result.FullName.Contains(fileSystem.Path.GetTempPath()), Is.True);
}
#endif

Expand Down

0 comments on commit f42d93f

Please sign in to comment.