Skip to content

Bug: iterate over all drives and iterate over all files throws error if no file is create in C? #844

@klace92

Description

@klace92

On Net framework create a default "MockFileSystem" seems to default create a C drive but no root directory. So if the unit test creates files on other drives then C. Then fs.DriveInfo.GetDrives().SelectMany(drive => drive.RootDirectory.EnumerateFiles("*", SearchOption.AllDirectories)).ToList() throws error ->

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:'

Here some sample code

        [TestMethod]
        public void Test()
        {
            var fs = new MockFileSystem();
            //fs.Directory.CreateDirectory(fs.Directory.GetCurrentDirectory()); // If force creating folder it works
            var files = fs.DriveInfo.GetDrives()
                .SelectMany(drive => drive.RootDirectory.EnumerateFiles("*", SearchOption.AllDirectories)).ToList();
            Console.WriteLine(files.Count);
        }

Is this really correct behavior? fells like root folder should exist for the drive?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions