Skip to content

Commit

Permalink
fix: use full path in Directory.SetCurrentDirectory (#1028)
Browse files Browse the repository at this point in the history
The current directory should always be a rooted path, even if the directory is set to a relative directory.
  • Loading branch information
vbreuss authored Aug 22, 2023
1 parent 0755df0 commit 4c5b0c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public override void SetCreationTimeUtc(string path, DateTime creationTimeUtc)
/// <inheritdoc />
public override void SetCurrentDirectory(string path)
{
currentDirectory = path;
currentDirectory = mockFileDataAccessor.Path.GetFullPath(path);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,17 @@ public void MockDirectory_SetCurrentDirectory_ShouldChangeCurrentDirectory()
Assert.AreEqual(directory, fileSystem.Directory.GetCurrentDirectory());
}

[Test]
public void MockDirectory_SetCurrentDirectory_WithRelativePath_ShouldUseFullPath()
{
var fileSystem = new MockFileSystem();
fileSystem.Directory.SetCurrentDirectory(".");

var result = fileSystem.Directory.GetCurrentDirectory();

Assert.IsTrue(fileSystem.Path.IsPathRooted(result));
}

[Test]
public void MockDirectory_GetParent_ShouldThrowArgumentNullExceptionIfPathIsNull()
{
Expand Down

0 comments on commit 4c5b0c1

Please sign in to comment.