MockDirectory.EnumerateFiles search pattern behaves differently from Directory.EnumerateFiles in .NET 5+
In .NET 5 the behaviour of the file extension search pattern changed from .NET Framework. See EnumerateFiles, specifically the table entry
book.xls, book.xlsx | *.xls | book.xls | book.xls, book.xlsx
To Reproduce Steps to reproduce the behaviour:
- Create files
a.txtandb.txt2in a directory. - Run
Directory.EnumerateFiles(dir, "*.txt", SearchOption.AllDirectories) - Compare .NET 5 or 6 behaviour to
MockDirectory
Expected behaviour
Only a.txt should be returned.
Actual behaviour
Both a.txt and b.txt2 are returned.
Can also just use *.t as search pattern which should return no files in a folder of .txt files etc.
Good find, thanks for the detailed explanation!
When fixing this we need to ensure that we keep the current behavior for .NET Framework (what about .NET Core?).
Thanks, By the way, ignore the *.t test as this behaviour only applies to 3 letter extensions, I believe.