TestableIO.System.IO.Abstractions.Wrappers
22.0.11
Prefix Reserved
See the version list below for details.
dotnet add package TestableIO.System.IO.Abstractions.Wrappers --version 22.0.11
NuGet\Install-Package TestableIO.System.IO.Abstractions.Wrappers -Version 22.0.11
paket add TestableIO.System.IO.Abstractions.Wrappers --version 22.0.11
#r "nuget: TestableIO.System.IO.Abstractions.Wrappers, 22.0.11"
#:package TestableIO.System.IO.Abstractions.Wrappers@22.0.11
#addin nuget:?package=TestableIO.System.IO.Abstractions.Wrappers&version=22.0.11
#tool nuget:?package=TestableIO.System.IO.Abstractions.Wrappers&version=22.0.11
At the core of the library is IFileSystem and FileSystem. Instead of calling methods like File.ReadAllText directly, use IFileSystem.File.ReadAllText. We have exactly the same API, except that ours is injectable and testable.
Usage
dotnet add package TestableIO.System.IO.Abstractions.Wrappers
Note: This NuGet package is also published as System.IO.Abstractions but we suggest to use the prefix to make clear that this is not an official .NET package.
public class MyComponent
{
readonly IFileSystem fileSystem;
// Create MyComponent with the given fileSystem implementation
public MyComponent(IFileSystem fileSystem)
{
this.fileSystem = fileSystem;
}
/// Create MyComponent
public MyComponent() : this(
fileSystem: new FileSystem() //use default implementation which calls System.IO
)
{
}
public void Validate()
{
foreach (var textFile in fileSystem.Directory.GetFiles(@"c:\", "*.txt", SearchOption.TopDirectoryOnly))
{
var text = fileSystem.File.ReadAllText(textFile);
if (text != "Testing is awesome.")
throw new NotSupportedException("We can't go on together. It's not me, it's you.");
}
}
}
Test helpers
The library also ships with a series of test helpers to save you from having to mock out every call, for basic scenarios. They are not a complete copy of a real-life file system, but they'll get you most of the way there.
dotnet add package TestableIO.System.IO.Abstractions.TestingHelpers
Note: This NuGet package is also published as System.IO.Abstractions.TestingHelpers but we suggest to use the prefix to make clear that this is not an official .NET package.
[Test]
public void MyComponent_Validate_ShouldThrowNotSupportedExceptionIfTestingIsNotAwesome()
{
// Arrange
var fileSystem = new MockFileSystem(new Dictionary
{
{ @"c:\myfile.txt", new MockFileData("Testing is meh.") },
{ @"c:\demo\jQuery.js", new MockFileData("some js") },
{ @"c:\demo\image.gif", new MockFileData(new byte[] { 0x12, 0x34, 0x56, 0xd2 }) }
});
var component = new MyComponent(fileSystem);
try
{
// Act
component.Validate();
}
catch (NotSupportedException ex)
{
// Assert
Assert.That(ex.Message, Is.EqualTo("We can't go on together. It's not me, it's you."));
return;
}
Assert.Fail("The expected exception was not thrown.");
}
We even support casting from the .NET Framework's untestable types to our testable wrappers:
FileInfo SomeApiMethodThatReturnsFileInfo()
{
return new FileInfo("a");
}
void MyFancyMethod()
{
var testableFileInfo = (FileInfoBase)SomeApiMethodThatReturnsFileInfo();
...
}
Mock support
Since version 4.0 the top-level APIs expose interfaces instead of abstract base classes (these still exist, though), allowing you to completely mock the file system. Here's a small example, using Moq:
[Test]
public void Test1()
{
var watcher = Mock.Of();
var file = Mock.Of();
Mock.Get(file).Setup(f => f.Exists(It.IsAny())).Returns(true);
Mock.Get(file).Setup(f => f.ReadAllText(It.IsAny())).Throws();
var unitUnderTest = new SomeClassUsingFileSystemWatcher(watcher, file);
Assert.Throws(() => {
Mock.Get(watcher).Raise(w => w.Created += null, new System.IO.FileSystemEventArgs(System.IO.WatcherChangeTypes.Created, @"C:\Some\Directory", "Some.File"));
});
Mock.Get(file).Verify(f => f.Exists(It.IsAny()), Times.Once);
Assert.True(unitUnderTest.FileWasCreated);
}
public class SomeClassUsingFileSystemWatcher
{
private readonly IFileSystemWatcher _watcher;
private readonly IFile _file;
public bool FileWasCreated { get; private set; }
public SomeClassUsingFileSystemWatcher(IFileSystemWatcher watcher, IFile file)
{
this._file = file;
this._watcher = watcher;
this._watcher.Created += Watcher_Created;
}
private void Watcher_Created(object sender, System.IO.FileSystemEventArgs e)
{
FileWasCreated = true;
if(_file.Exists(e.FullPath))
{
var text = _file.ReadAllText(e.FullPath);
}
}
}
Related projects
System.IO.Abstractions.Extensionsprovides convenience functionality on top of the core abstractions.System.IO.Abstractions.Analyzersprovides Roslyn analyzers to help use abstractions over static methods.Testably.Abstractionsprovides alternative test helpers and additional abstractions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- Testably.Abstractions.FileSystem.Interface (>= 9.0.0)
-
.NETStandard 2.0
- System.IO.FileSystem.AccessControl (>= 5.0.0)
- Testably.Abstractions.FileSystem.Interface (>= 9.0.0)
-
.NETStandard 2.1
- System.IO.FileSystem.AccessControl (>= 5.0.0)
- Testably.Abstractions.FileSystem.Interface (>= 9.0.0)
-
net6.0
- Testably.Abstractions.FileSystem.Interface (>= 9.0.0)
-
net8.0
- Testably.Abstractions.FileSystem.Interface (>= 9.0.0)
-
net9.0
- Testably.Abstractions.FileSystem.Interface (>= 9.0.0)
NuGet packages (77)
Showing the top 5 NuGet packages that depend on TestableIO.System.IO.Abstractions.Wrappers:
| Package | Downloads |
|---|---|
|
System.IO.Abstractions
A set of abstractions to help make file system interactions testable. |
|
|
TestableIO.System.IO.Abstractions.TestingHelpers
A set of pre-built mocks to help when testing file system interactions. |
|
|
FluentStorage
A polycloud .NET cloud storage abstraction layer. Provides a single unified polycloud API across 15+ clouds for Object manipulation, File uploads/downloads, File streaming/seeking, Object metadata, Versioning, Tags, Storage tier/class, Presigned URLs, Directory manipulation and more. |
|
|
Reo.Core.Database
Package Description |
|
|
Vonage
Official C#/.NET wrapper for the Vonage API. To use it you will need a Vonage account. Sign up for free at vonage.com. For full API documentation refer to developer.vonage.com. |
GitHub repositories (18)
Showing the top 18 popular GitHub repositories that depend on TestableIO.System.IO.Abstractions.Wrappers:
| Repository | Stars |
|---|---|
|
Azure/azure-powershell
Microsoft Azure PowerShell
|
|
|
recyclarr/recyclarr
Automatically sync TRaSH Guides to your Sonarr and Radarr instances
|
|
|
stryker-mutator/stryker-net
Mutation testing for .NET core and .NET framework!
|
|
|
rogerfar/rdt-client
Real-Debrid Client Proxy
|
|
|
prom3theu5/aspirational-manifests
Handle deployments of .NET Aspire AppHost Projects
|
|
|
ChaosRecipeEnhancer/ChaosRecipeEnhancer
🟡📈 Streamline your Chaos Recipe gains! Overlay tool for Path of Exile 1
|
|
|
Azure/azure-functions-dotnet-worker
Azure Functions out-of-process .NET language worker
|
|
|
robinrodricks/FluentStorage
.NET polycloud storage framework which provides a unified polycloud API across 15+ clouds for Object manipulation, File uploads/downloads, File streaming/seeking, Directory upload/download, Object metadata, Versioning, Tags, Storage tier/class, Presigned URLs and more.
|
|
|
octgn/OCTGN
Online Card and Tabletop Gaming Network
|
|
|
sensslen/nuget-license
.NET Core tool to print or save all the licenses of a project
|
|
|
ZarehD/AspNetStatic
Transform ASP.NET Core into a static site generator.
|
|
|
NeilMacMullen/kusto-loco
C# KQL query engine with flexible I/O layers and visualization
|
|
|
SuperJMN/DotnetPackaging
Distribute your .NET applications!
|
|
|
Mutagen-Modding/Spriggit
A tool to facilitate converting Bethesda plugin files to a text based format that can be stored in Git
|
|
|
pre-martin/StreamDeckSimHubPlugin
Keep your Stream Deck buttons in sync with SimHub (and your simulation)
|
|
|
Vonage/vonage-dotnet-sdk
Vonage REST API client for .NET, written in C#. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
|
|
|
rubberduck-vba/Rubberduck3
COM add-in for the VBIDE
|
|
|
hmz777/NetStalkerAvalonia
NetStalker re-written in MVVM, Avalonia and Reactive UI.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 22.3.0 | 80,640 | 9/28/2026 |
| 22.2.0 | 1,276,502 | 7/12/2026 |
| 22.1.1 | 2,904,631 | 4/9/2026 |
| 22.1.0 | 4,632,232 | 11/22/2025 |
| 22.0.16 | 2,882,672 | 9/14/2025 |
| 22.0.16-pre.2 | 267 | 9/14/2025 |
| 22.0.16-pre.1 | 218 | 9/13/2025 |
| 22.0.15 | 2,687,816 | 7/8/2025 |
| 22.0.14 | 3,925,765 | 4/18/2025 |
| 22.0.13 | 711,257 | 4/4/2025 |
| 22.0.12 | 2,409,165 | 3/13/2025 |
| 22.0.11 | 454,926 | 3/1/2025 |
| 22.0.10 | 761,242 | 2/23/2025 |
| 22.0.10-beta.1 | 252 | 2/22/2025 |
| 22.0.9 | 46,408 | 2/22/2025 |
| 21.3.1 | 1,744,040 | 1/29/2025 |
| 21.2.12 | 186,388 | 1/28/2025 |
| 21.2.8 | 65,432 | 1/25/2025 |
| 21.2.1 | 2,260,741 | 12/28/2024 |
| 21.1.7 | 1,864,943 | 12/3/2024 |