Skip to content

Cannot set properties on DriveInfoBase objects returned by MockFileSystem.DriveInfo.GetDrives #274

@jt-msft

Description

@jt-msft

The MockDriveInfo type allows the caller to set various properties on instances of the class (e.g. AvailableFreeSpace or DriveType), but these properties are not included in the objects output by a call to MockFileSystem.DriveInfo.GetDrives() since the array is built from the list of files in the mock without checking if a MockDriveInfo object is defined.

Creating the mock

var fileSystem = new MockFileSystem();
fileSystem.AddFile(@"C:\path\to\file.txt", MockFileData.NullObject);
var driveInfo = new MockDriveInfo(fileSystem, "c:") { DriveType = DriveType.Fixed };

Checking the drive is local

List<string> localDiskDrives = 
(
    from driveInfo in fileSystem.DriveInfo.GetDrives()
    where driveInfo.DriveType == DriveType.Fixed & driveInfo.IsReady
    select driveInfo.RootDirectory.ToString()
).ToList();

Expected
List containing "c:"

Actual
Empty list

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions