Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support relative paths with multiple subfolders in Directory.GetFiles #332

Merged
merged 3 commits into from
Jul 17, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static string GetSubdirectoryPath(this IFileSystem fileSystem,
return fullFilePath;
}

string currentDirectory = fileSystem.Directory.GetCurrentDirectory();
string currentDirectory = fileSystem.Path.GetFullPath(givenPath);
if (currentDirectory == string.Empty.PrefixRoot())
{
fullFilePath = fullFilePath.Substring(currentDirectory.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ public void
result.Should().NotContain(initialized[3].ToString());
}

[SkippableTheory]
[AutoData]
public void GetFiles_WithRelativePathAndSubfolders_ShouldReturnRelativeFilePath(
string subfolder1, string subfolder2, string[] files)
{
string workingDirectory = System.IO.Path.Combine(BasePath, subfolder1, subfolder2);
FileSystem.Directory.CreateDirectory(workingDirectory);
foreach (string file in files)
{
FileSystem.File.Create(System.IO.Path.Combine(workingDirectory, file));
}
FileSystem.Directory.SetCurrentDirectory(subfolder1);
IEnumerable<string> expectation =
files.Select(f => System.IO.Path.Combine("..", subfolder1, subfolder2, f));
var path = System.IO.Path.Combine("..", subfolder1, subfolder2);

List<string> result = FileSystem.Directory.GetFiles(path).ToList();

result.Should().BeEquivalentTo(expectation);
}

[SkippableTheory]
[AutoData]
public void GetFiles_WithSearchPattern_ShouldReturnMatchingFiles(
Expand Down
Loading