Search code examples
.netunit-testingtypemock

Mocking filesystem


If my unit tests rely on the file system and I need to mock this, what is the best way to go about this?

Thanks


Solution

  • You basically have two options: eiter abstract all file-system related logic behind a IFileSystemService, or use Stubs from Microsoft, which is

    ...a lightweight framework for .NET that provides test stubs. For interfaces and non-sealed classes, type-safe wrappers are generated that can be easily customized by attaching delegates.