diff --git a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs index f1789cb4..5d7a7a03 100644 --- a/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs +++ b/Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs @@ -37,6 +37,21 @@ public override string GetFullPath(string path) { path.EnsureValidArgument(FileSystem, nameof(path)); + string? pathRoot = Path.GetPathRoot(path); + string? directoryRoot = Path.GetPathRoot(_fileSystem.Storage.CurrentDirectory); + if (!string.IsNullOrEmpty(pathRoot) && !string.IsNullOrEmpty(directoryRoot)) + { + if (char.ToUpperInvariant(pathRoot[0]) != char.ToUpperInvariant(directoryRoot[0])) + { + return Path.GetFullPath(path); + } + + if (pathRoot.Length < directoryRoot.Length) + { + path = path.Substring(pathRoot.Length); + } + } + return Path.GetFullPath(Path.Combine( _fileSystem.Storage.CurrentDirectory, path)); diff --git a/Tests/Testably.Abstractions.Tests/FileSystem/Path/GetFullPathTests.cs b/Tests/Testably.Abstractions.Tests/FileSystem/Path/GetFullPathTests.cs index 9b6e8dae..2ffecf0d 100644 --- a/Tests/Testably.Abstractions.Tests/FileSystem/Path/GetFullPathTests.cs +++ b/Tests/Testably.Abstractions.Tests/FileSystem/Path/GetFullPathTests.cs @@ -5,6 +5,49 @@ public abstract partial class GetFullPathTests : FileSystemTestBase where TFileSystem : IFileSystem { + [SkippableFact] + public void GetFullPath_Dot_ShouldReturnToCurrentDirectory() + { + string expectedFullPath = FileSystem.Directory.GetCurrentDirectory(); + + string result = FileSystem.Path.GetFullPath("."); + + result.Should().Be(expectedFullPath); + } + + [SkippableFact] + public void GetFullPath_RelativePathWithDrive_ShouldReturnExpectedValue() + { + Skip.IfNot(Test.RunsOnWindows); + + string currentDirectory = FileSystem.Directory.GetCurrentDirectory(); + string drive = currentDirectory.Substring(0, 1); + string input = $"{drive}:test.txt"; + string expectedFullPath = FileSystem.Path.Combine(currentDirectory, "test.txt"); + + string result = FileSystem.Path.GetFullPath(input); + + result.Should().Be(expectedFullPath); + } + + [SkippableFact] + public void + GetFullPath_RelativePathWithDrive_WhenCurrentDirectoryIsDifferent_ShouldReturnExpectedValue() + { + Skip.IfNot(Test.RunsOnWindows); + + string currentDirectory = FileSystem.Directory.GetCurrentDirectory(); + string otherDrive = currentDirectory + .Substring(0,1) + .Equals("x", StringComparison.OrdinalIgnoreCase) ? "Y" : "X"; + string input = $"{otherDrive}:test.txt"; + string expectedFullPath = $@"{otherDrive}:\test.txt"; + + string result = FileSystem.Path.GetFullPath(input); + + result.Should().Be(expectedFullPath); + } + [SkippableTheory] [InlineData(@"top/../most/file", @"most/file")] [InlineData(@"top/../most/../dir/file", @"dir/file")]