Skip to content

MockDirectory.GetDirectories does not handle empty searchOption properly #739

@TureeZhang

Description

@TureeZhang

Describe the bug
Directory.GetDirectories(path,pattern,searchOption) returns nothing when the 3rd parameter use SearchOption.TopDirectoryOnly, just like this Directory.GetDirectories(@"F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "", SearchOption.TopDirectoryOnly)

To Reproduce
Steps to reproduce the behavior:

  1. copy these code bellow which I just writed in my unit test to create the mock files and directories
string projResoRoot = Path.Combine("F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "my-project");
            string projectFile1 = Path.Combine("F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "__node__info__file__");
            string projectFile2 = Path.Combine("F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "my-project", "Biz/Rule", "__node__info__file__");
            string projectFile3 = Path.Combine("F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "my-project", "Biz/Rule", "Models.vl.json");
            string projectFile4 = Path.Combine("F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "my-project", "Biz/Rule", "Consts.cl.json");
            string projectFile5 = Path.Combine("F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "my-project", "Biz/Rule", "MyRule.rs.json");
            MockFileSystem mockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData> {
                { projResoRoot, new MockDirectoryData()},
                { projectFile1, new MockFileData("") },
                { projectFile2, new MockFileData("{\"Name\":\"my-project\",\"_dataDic\":{}}") },
                { projectFile3, new MockFileData("{\"Name\":\"/my-project/Models.vl.json\",\"_dataDic\":{}}") },
                { projectFile4, new MockFileData("{\"Name\":\"/my-project/Consts.cl.json\",\"_dataDic\":{}}") },
                { projectFile5, new MockFileData("{\"Name\":\"/my-project/MyRule.rs.json\",\"_dataDic\":{}}") }
            });
  1. it's create these files and directories :

image

  1. call the method mockFileSystem.Directory.GetDirectories(@"F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "", SearchOption.TopDirectoryOnly)

  2. it returns nothing, but should be "my-project" directories under "F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource".

image

Expected behavior

it should be "my-project" directory under "F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", just like System.IO.Directory.GetDirectories(@"F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource", "", SearchOption.TopDirectoryOnly) did .

The path "F:\BeflamRule\src\Beflam.Rule.WebApi\bin\Debug\netcoreapp3.1\ProjectResource" also really exist on my computer disk which now contians "t1" "t2" directories ,System.IO.Directories works right :

image

Additional context

Nothing else . GOOD JOB man, nice unit test utils, thanks so much !

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: ready to pickIssues that are ready for being worked onstate: releasedIssues that are releasedtype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions