From 51c12127b9c365dd3c91f9f96b9d7c7c17bdc0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Tue, 22 Aug 2023 09:08:10 +0200 Subject: [PATCH] The current directory should always be a rooted path, even if the directory is set to a relative directory. --- .../MockDirectory.cs | 2 +- .../MockDirectoryTests.cs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs index 23f6436b1..4697f070b 100644 --- a/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs +++ b/src/TestableIO.System.IO.Abstractions.TestingHelpers/MockDirectory.cs @@ -603,7 +603,7 @@ public override void SetCreationTimeUtc(string path, DateTime creationTimeUtc) /// public override void SetCurrentDirectory(string path) { - currentDirectory = path; + currentDirectory = mockFileDataAccessor.Path.GetFullPath(path); } /// diff --git a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs index c43e68489..c5d0049e3 100644 --- a/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs +++ b/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockDirectoryTests.cs @@ -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() {