Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

An in-memory file system, intended to substitute System.IO calls in .NET unit tests.

License

Notifications You must be signed in to change notification settings

bkoelman/TestableFileSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testable File System

Build status codecov

This project provides a blazingly fast in-memory file system. With an API surface that is practically identical to the System.IO library from the .NET Framework and .NET Core. Using the provided interfaces makes it easy to toggle between the real file system and the fake one. For example, in unit tests.

To help transition existing codebases, an analyzer is included that runs in Visual Studio and highlights potential locations where System.IO calls can be replaced with interface-based calls.

Features of the fake filesystem

  • Concurrent access to the in-memory filesystem is thread-safe
  • Throws appropriate exceptions for files that are in use
  • Fails on changing readonly files and directories
  • Supports absolute and relative paths, based on settable current directory
  • Supports local and UNC (Universal Naming Convention) network paths
  • Paths are case-insensitive
  • Mimics NTFS behavior with NtfsDisableLastAccessUpdate disabled
  • Full support for FileSystemWatcher and async I/O in NetStandard 2.0

Limitations of the fake filesystem

  • A file cannot be opened by multiple writers at the same time (multiple readers are allowed)
  • Exception messages are always in US-English (not localized, but matching type)
  • Limitations around MAXPATH do not apply (paths starting with \\?\ are allowed)
  • Device namespaces (\\.\COM56) and ports (COM1) are not supported
  • Some file attributes, such as Compressed/Offline/NotContentIndexed you will never get (because they are set by nonstandard APIs)
  • NTFS permissions are not implemented
  • Hard links, junctions and symbolic links (reparse points) are not implemented
  • 8.3 aliases for file names are not implemented

Get started

The NuGet packages provide assemblies that target NetStandard 2.0, 1.3 and .NET Framework 4.5.

  • From the NuGet package manager console:

    Install-Package TestableFileSystem.Wrappers -project YourProductName

    Install-Package TestableFileSystem.Fakes -project YourProductUnitTests

See Demo/Program.cs and documentation for example usage.

Trying out the latest build

After each commit, new prerelease NuGet packages are automatically published to AppVeyor at https://ci.appveyor.com/project/bkoelman/testablefilesystem/branch/master/artifacts. To try it out, follow the next steps:

  • In Visual Studio: Tools, NuGet Package Manager, Package Manager Settings, Package Sources
  • Open the NuGet package manager console (Tools, NuGet Package Manager, Package Manager Console)
    • Select AppVeyor TestableFileSystem as package source
    • Run command: Install-Package TestableFileSystem.Wrappers -pre or Install-Package TestableFileSystem.Fakes -pre

Building this project from source requires Visual Studio 2017 or later.

About

An in-memory file system, intended to substitute System.IO calls in .NET unit tests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages