Skip to content

Providing mocks as and when necessary #1081

@sameera

Description

@sameera

Problem:

I have a parser that iterates through the file system and parses each file one by one. The functionality is built around IEnumerables and needs to ensure that the next file is read for parsing only after all downstream functions are done processing the previous one.
To test for this, I want to setup a mock for File.ReadAllText and ensure that it's not being called until again the previous file is done.
I could do this by setting up a mock for IFile and checking calls to ReadAllText as that's the only op I do on IFile type. I do have few other calls to other file system objects that I don't want to mock/change. If MockFileSystem.File was settable, I can assign the mock for this test only without changing anything about the other tests.

Proposed solution:
Provide setters for MockFileSystem.File and MockFileSystem.Directory (for consistency and possible similar use cases).

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Alternatives:
For such tests, setup a mocked IFileSystem from scratch with all objects and methods mocked. This could be tedious in many cases.

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