Simulating other operating systems
MockFileSystem can pretend to be a different operating system than the host it runs on. Pass a SimulationMode in the constructor:
- Linux
- Windows
- macOS
MockFileSystem fileSystem = new(o =>
o.SimulatingOperatingSystem(SimulationMode.Linux));
// case-sensitive, '/' separator, single root
MockFileSystem fileSystem = new(o =>
o.SimulatingOperatingSystem(SimulationMode.Windows));
// case-insensitive, '\' separator, drive letters
MockFileSystem fileSystem = new(o =>
o.SimulatingOperatingSystem(SimulationMode.MacOS));
// case-insensitive, '/' separator, single root
Because the entire test suite runs against the real file system on Linux, macOS and Windows and against each SimulationMode in CI, the simulated behavior stays in lock-step with the genuine platform behavior over time.
.NET 6 or later
SimulatingOperatingSystem is only available on .NET 6 and later. On older targets, the mock always uses the host OS.
Why simulate
- Catch case-sensitivity bugs that only show up on Linux from a Windows dev machine.
- Verify path-handling code on Windows from a Linux CI runner.
- Test drive-letter handling without spinning up a Windows job.
If you only need the host's own behavior, omit SimulatingOperatingSystem: MockFileSystem defaults to whichever OS it is running on.