Skip to content

DirectoryMock.EnumerateDirectories does not throw exceptions until enumerated #856

@stogle

Description

@stogle

The real Directory.EnumerateDirectories will immediately throw IO exceptions for missing directory/etc. (see FileSystemEnumerator.Windows.cs#L48-L50). The equivalent DirectoryMock.EnumerateDirectories will not throw these exceptions until you start to enumerate the result. The same may be true for other methods that return enumerations.

To resolve this, I think InMemoryStorage.EnumerateLocations needs to be split into two methods, something like:

public IEnumerable<IStorageLocation> EnumerateLocations(...)
{
    // check for missing directory/etc. and throw exceptions

    return EnumerateLocationsImpl(...)
}

private IEnumerable<IStorageLocation> EnumerateLocationsImpl(...)
{
    // existing implementation with yield return
}

The checking and throwing in the first method should happen during the initial call, while the code in the second method won't happen until the caller enumerates the result.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions