From ddca44b353e0d9ba60f26a3dd93aad778e11a3c8 Mon Sep 17 00:00:00 2001 From: Valentin Date: Sun, 9 Mar 2025 12:20:24 +0100 Subject: [PATCH 1/4] fix: directory with forward slash exists on windows --- .gitignore | 2 +- .../Helpers/Execute.WindowsPath.cs | 6 +++++- Testably.Abstractions.sln.DotSettings | 1 + .../FileSystem/Directory/ExistsTests.cs | 18 ++++++++++++++++++ .../FileSystem/DirectoryInfo/ExistsTests.cs | 8 ++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f39d5e3ec..c9f82dd83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Ignore the test.settings.json as it should reflect the individual developer experience. # > https://github.com/Testably/Testably.Abstractions/blob/main/CONTRIBUTING.md#tests -/test.settings.json +/Tests/test.settings.json # Set up Visual Studio to use WSL to execute unit tests in Ubuntu: # https://learn.microsoft.com/en-us/visualstudio/test/remote-testing diff --git a/Source/Testably.Abstractions.Testing/Helpers/Execute.WindowsPath.cs b/Source/Testably.Abstractions.Testing/Helpers/Execute.WindowsPath.cs index 93b01b4c3..8d5e50429 100644 --- a/Source/Testably.Abstractions.Testing/Helpers/Execute.WindowsPath.cs +++ b/Source/Testably.Abstractions.Testing/Helpers/Execute.WindowsPath.cs @@ -32,7 +32,11 @@ public override string GetFullPath(string path) string candidate; if (!string.IsNullOrEmpty(pathRoot) && !string.IsNullOrEmpty(directoryRoot)) { - if (char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0])) + if (pathRoot[0] == DirectorySeparatorChar && pathRoot.Length == 1) + { + candidate = directoryRoot + path.Substring(1); + } + else if (char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0])) { candidate = path; } diff --git a/Testably.Abstractions.sln.DotSettings b/Testably.Abstractions.sln.DotSettings index 60cbae69e..4e0175e87 100644 --- a/Testably.Abstractions.sln.DotSettings +++ b/Testably.Abstractions.sln.DotSettings @@ -446,6 +446,7 @@ False True OS + UNC True True True diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs index a719d7f29..59fb9f74b 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs @@ -26,6 +26,24 @@ public void Exists_File_ShouldReturnFalse(string path) result.Should().BeFalse(); } + [Fact] + public void Exists_ForwardSlash_ShouldReturnTrue() + { + bool result = FileSystem.Directory.Exists("/"); + + result.Should().BeTrue(); + } + + [Fact] + public void Exists_ForwardSlashWithDirectory_ShouldReturnTrue() + { + FileSystem.Directory.CreateDirectory("/temp"); + + bool result = FileSystem.Directory.Exists("/temp"); + + result.Should().BeTrue(); + } + [Theory] [InlineData(@"\\s")] [InlineData("<")] diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs index 240d9ac9e..f06a79594 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs @@ -36,6 +36,14 @@ public void Exists_File_ShouldReturnFalse(string path) sut.Exists.Should().BeFalse(); } + [Fact] + public void Exists_ForwardSlash_ShouldReturnTrue() + { + IDirectoryInfo sut = FileSystem.DirectoryInfo.New("/"); + + sut.Exists.Should().BeTrue(); + } + [Theory] [AutoData] public void Exists_NotExistedPreviously_ShouldOnlyUpdateOnInitialization(string path) From 07bed9210acbb7040ba419f0fdfdffe4f881f1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Thu, 13 Mar 2025 09:01:52 +0100 Subject: [PATCH 2/4] Update ExistsTests.cs --- .../FileSystem/Directory/ExistsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs index 59fb9f74b..dd2beb247 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs @@ -37,9 +37,9 @@ public void Exists_ForwardSlash_ShouldReturnTrue() [Fact] public void Exists_ForwardSlashWithDirectory_ShouldReturnTrue() { - FileSystem.Directory.CreateDirectory("/temp"); + FileSystem.Directory.CreateDirectory("/tmp"); - bool result = FileSystem.Directory.Exists("/temp"); + bool result = FileSystem.Directory.Exists("/tmp"); result.Should().BeTrue(); } From c8f95d2b6ac8af0609adfead430a4e11f87535ad Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 13 Mar 2025 10:32:14 +0100 Subject: [PATCH 3/4] Initialize FileSystem --- .../FileSystem/Directory/ExistsTests.cs | 2 ++ .../FileSystem/DirectoryInfo/ExistsTests.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs index dd2beb247..1dbafb344 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs @@ -29,6 +29,8 @@ public void Exists_File_ShouldReturnFalse(string path) [Fact] public void Exists_ForwardSlash_ShouldReturnTrue() { + FileSystem.Initialize(); + bool result = FileSystem.Directory.Exists("/"); result.Should().BeTrue(); diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs index f06a79594..875358edf 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs @@ -39,6 +39,8 @@ public void Exists_File_ShouldReturnFalse(string path) [Fact] public void Exists_ForwardSlash_ShouldReturnTrue() { + FileSystem.Initialize(); + IDirectoryInfo sut = FileSystem.DirectoryInfo.New("/"); sut.Exists.Should().BeTrue(); From 10cd8e7a6c10a40e4de85e444597e819ea6dd0d1 Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 13 Mar 2025 11:27:16 +0100 Subject: [PATCH 4/4] Initialize in drive D --- .../FileSystem/Directory/ExistsTests.cs | 2 +- .../FileSystem/DirectoryInfo/ExistsTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs index 1dbafb344..28e8e1d53 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs @@ -29,7 +29,7 @@ public void Exists_File_ShouldReturnFalse(string path) [Fact] public void Exists_ForwardSlash_ShouldReturnTrue() { - FileSystem.Initialize(); + FileSystem.InitializeIn("D:"); bool result = FileSystem.Directory.Exists("/"); diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs index 875358edf..1a1210454 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs @@ -39,7 +39,7 @@ public void Exists_File_ShouldReturnFalse(string path) [Fact] public void Exists_ForwardSlash_ShouldReturnTrue() { - FileSystem.Initialize(); + FileSystem.InitializeIn("D:"); IDirectoryInfo sut = FileSystem.DirectoryInfo.New("/");