Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Source/Testably.Abstractions.Testing/FileSystem/PathMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,49 @@ public abstract partial class GetFullPathTests<TFileSystem>
: FileSystemTestBase<TFileSystem>
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")]
Expand Down