Skip to content

Commit

Permalink
fix: Use searchPattern argument in GetFiles method to complete the lo…
Browse files Browse the repository at this point in the history
…gic (#988)

It should use the searchPattern argument to complete the logic.

I found it while working with MockDirectoryInfo.EnumerateFiles(searchPattern, enumerationOptions)
It didnt respect the searchPattern and my tests failed, so I decided to check the source.
  • Loading branch information
AK1llv authored May 17, 2023
1 parent 97a0ea2 commit 41c7f0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public override string[] GetFiles(string path, string searchPattern, SearchOptio
/// <inheritdoc />
public override string[] GetFiles(string path, string searchPattern, EnumerationOptions enumerationOptions)
{
return GetFiles(path, "*", EnumerationOptionsToSearchOption(enumerationOptions));
return GetFiles(path, searchPattern, EnumerationOptionsToSearchOption(enumerationOptions));
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ public void MockDirectory_GetFiles_ShouldReturnAllFilesBelowPathWhenPatternIsWil
Assert.That(result, Is.EquivalentTo(expected));
}

#if FEATURE_ENUMERATION_OPTIONS
[Test]
public void MockDirectory_GetFiles_ShouldReturnAllPatternMatchingFilesWhenEnumerationOptionHasRecurseSubdirectoriesSetToTrue()
{
// Arrange
var fileSystem = SetupFileSystem();
var expected = new[]
{
XFS.Path(@"c:\b.txt"),
XFS.Path(@"c:\c.txt"),
XFS.Path(@"c:\a\a.txt"),
XFS.Path(@"c:\a\c.txt"),
XFS.Path(@"c:\a\a\a.txt"),
XFS.Path(@"c:\a\a\b.txt")
};

// Act
var result = fileSystem.Directory.GetFiles(XFS.Path(@"c:\"), "*.txt", new EnumerationOptions { RecurseSubdirectories = true });

// Assert
Assert.That(result, Is.EquivalentTo(expected));
}
#endif

private MockFileSystem SetupFileSystem()
{
return new MockFileSystem(new Dictionary<string, MockFileData>
Expand Down

0 comments on commit 41c7f0d

Please sign in to comment.