Skip to content

Commit 4c5b0c1

Browse files
authored
fix: use full path in Directory.SetCurrentDirectory (#1028)
The current directory should always be a rooted path, even if the directory is set to a relative directory.
1 parent 0755df0 commit 4c5b0c1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ public override void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
602602
/// <inheritdoc />
603603
public override void SetCurrentDirectory(string path)
604604
{
605-
currentDirectory = path;
605+
currentDirectory = mockFileDataAccessor.Path.GetFullPath(path);
606606
}
607607

608608
/// <inheritdoc />

tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,17 @@ public void MockDirectory_SetCurrentDirectory_ShouldChangeCurrentDirectory()
16611661
Assert.AreEqual(directory, fileSystem.Directory.GetCurrentDirectory());
16621662
}
16631663

1664+
[Test]
1665+
public void MockDirectory_SetCurrentDirectory_WithRelativePath_ShouldUseFullPath()
1666+
{
1667+
var fileSystem = new MockFileSystem();
1668+
fileSystem.Directory.SetCurrentDirectory(".");
1669+
1670+
var result = fileSystem.Directory.GetCurrentDirectory();
1671+
1672+
Assert.IsTrue(fileSystem.Path.IsPathRooted(result));
1673+
}
1674+
16641675
[Test]
16651676
public void MockDirectory_GetParent_ShouldThrowArgumentNullExceptionIfPathIsNull()
16661677
{

0 commit comments

Comments
 (0)