From f42d93fcc58131d11aa998fc6e0cbbbf2e6dc0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sat, 22 Jun 2024 08:03:20 +0200 Subject: [PATCH] fix: use correct base path in `Directory.CreateTempSubdirectory` (#1127) * Add failing test * Use correct path for temporary directory --- .../MockDirectory.cs | 4 ++-- .../MockDirectoryTests.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs index d7f0a6d34..b5376487d 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -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); diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index 343a98f26..fbd0fc41f 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -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] @@ -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