Skip to content

Commit 757199e

Browse files
committed
fix: directory with forward slash exists on windows
1 parent 2d09c99 commit 757199e

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Source/Testably.Abstractions.Testing/Helpers/Execute.WindowsPath.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public override string GetFullPath(string path)
3232
string candidate;
3333
if (!string.IsNullOrEmpty(pathRoot) && !string.IsNullOrEmpty(directoryRoot))
3434
{
35-
if (char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0]))
35+
if (pathRoot[0] == DirectorySeparatorChar)
36+
{
37+
candidate = directoryRoot;
38+
}
39+
else if (char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0]))
3640
{
3741
candidate = path;
3842
}

Tests/Testably.Abstractions.Tests/FileSystem/Directory/ExistsTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public void Exists_File_ShouldReturnFalse(string path)
2626
result.Should().BeFalse();
2727
}
2828

29+
[Fact]
30+
public void Exists_ForwardSlash_ShouldReturnTrue()
31+
{
32+
bool result = FileSystem.Directory.Exists("/");
33+
34+
result.Should().BeTrue();
35+
}
36+
2937
[Theory]
3038
[InlineData(@"\\s")]
3139
[InlineData("<")]

Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ExistsTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public void Exists_File_ShouldReturnFalse(string path)
3636
sut.Exists.Should().BeFalse();
3737
}
3838

39+
[Fact]
40+
public void Exists_ForwardSlash_ShouldReturnTrue()
41+
{
42+
IDirectoryInfo sut = FileSystem.DirectoryInfo.New("/");
43+
44+
sut.Exists.Should().BeTrue();
45+
}
46+
3947
[Theory]
4048
[AutoData]
4149
public void Exists_NotExistedPreviously_ShouldOnlyUpdateOnInitialization(string path)

0 commit comments

Comments
 (0)