VOOZH about

URL: https://www.nuget.org/packages/Testably.Abstractions/

⇱ NuGet Gallery | Testably.Abstractions 10.2.0




👁 Image
Testably.Abstractions 10.2.0

Prefix Reserved
dotnet add package Testably.Abstractions --version 10.2.0
 
 
NuGet\Install-Package Testably.Abstractions -Version 10.2.0
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Testably.Abstractions" Version="10.2.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Testably.Abstractions" Version="10.2.0" />
 
Directory.Packages.props
<PackageReference Include="Testably.Abstractions" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Testably.Abstractions --version 10.2.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Testably.Abstractions, 10.2.0"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Testably.Abstractions@10.2.0
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Testably.Abstractions&version=10.2.0
 
Install as a Cake Addin
#tool nuget:?package=Testably.Abstractions&version=10.2.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

👁 Testably.Abstractions
👁 Changelog
👁 Nuget
👁 Nuget
👁 Coverage

This library is a feature complete testing helper for the IFileSystem abstractions for I/O-related functionality from the System.IO namespace. It uses an in-memory file system that behaves exactly like the real file system and can be used in unit tests for dependency injection.
The testing helper also supports advanced scenarios like

  • and
  • a way to work with

The companion projects Testably.Abstractions.Compression and Testably.Abstractions.AccessControl allow working with and respectively.

As the test suite runs both against the mocked and the real file system, the behaviour between the two is identical and it also allows simulating the file system on other operating systems (Linux, MacOS and Windows).

In addition, the following interfaces are defined:

  • The ITimeSystem interface abstracts away time-related functionality:
  • The IRandomSystem interface abstracts away functionality related to randomness:
    Random methods implement a thread-safe Shared instance also under .NET Framework and Guid methods allow creating new GUIDs.

Example

Use the interfaces and their default implementations using your prefered dependency injection method, e.g.:

private readonly IFileSystem _fileSystem;

public class MyService(IFileSystem fileSystem)
{
 _fileSystem = fileSystem;
}

public void StoreData()
{
 var fileContent = GetFileContent();
 _fileSystem.File.WriteAllText("result.xml", fileContent);
}

private string GetFileContent()
{
 // Generate the file content
}

Then you test your class with the mocked types in Testably.Abstractions.Testing:

[Test]
public void StoreData_ShouldWriteValidFile()
{
 IFileSystem fileSystem = new MockFileSystem();
 MyService sut = new MyService(fileSystem);

 sut.StoreData();

 var fileContent = fileSystem.File.ReadAllText("result.xml");
 // Validate fileContent
}

More examples can be found in the !

Getting Started

  • Install Testably.Abstractions as nuget package in your production projects and Testably.Abstractions.Testing as nuget package in your test projects.

    dotnet add package Testably.Abstractions
    dotnet add package Testably.Abstractions.Testing
    
  • Configure your dependeny injection framework, e.g. with Microsoft.Extensions.DependencyInjections in ASP.NET core:

    builder.Services
     .AddSingleton<IFileSystem, RealFileSystem>()
     .AddSingleton<IRandomSystem, RealRandomSystem>()
     .AddSingleton<ITimeSystem, RealTimeSystem>();
    

You can now use the interfaces in your services!

Testing

In order to simplify testing, the Testably.Abstractions.Testing project provides mocked instances for the abstraction interfaces, which are configured using fluent syntax:

Initialization

The following two code snippets initialize the mocked fileSystem with a structure like the following:

  • Directory "foo"
    • Directory "bar"
    • Empty file "bar.txt"
  • File "foo.txt" with "some file content" as content
var fileSystem = new MockFileSystem();
fileSystem.Initialize().With(
 new DirectoryDescription("foo",
 new DirectoryDescription("bar"),
 new FileDescription("bar.txt")),
 new FileDescription("foo.txt", "some file content"));
var fileSystem = new MockFileSystem();
fileSystem.Initialize()
	.WithSubdirectory("foo").Initialized(d => d
		.WithSubdirectory("bar")
		.WithFile("bar.txt"))
	.WithFile("foo.txt").Which(f => f.HasStringContent("some file content"));

Simulating other operating systems

The MockFileSystem can also simulate other operating systems than the one it is currently running on. This can be achieved, by providing the corresponding SimulationMode in the constructor:

var linuxFileSystem = new MockFileSystem(o => o.SimulatingOperatingSystem(SimulationMode.Linux));
// The `linuxFileSystem` now behaves like a Linux file system even under Windows:
// - case-sensitive
// - slash as directory separator

var windowsFileSystem = new MockFileSystem(o => o.SimulatingOperatingSystem(SimulationMode.Windows));
// The `windowsFileSystem` now behaves like a Windows file system even under Linux or MacOS:
// - multiple drives
// - case-insensitive
// - backslash as directory separator

By running all tests against the real file system and the simulated under Linux, MacOS and Windows, the behaviour is consistent between the native and simulated mock file systems.

Drive management

var fileSystem = new MockFileSystem();
fileSystem
 .WithDrive("D:", d => d
 .SetTotalSize(1024 * 1024))
 .InitializeIn("D:")
 .WithFile("foo.txt")
 .WithSubdirectory("sub-dir").Initialized(s => s
 .WithAFile(".json").Which(
 f => f.HasStringContent("{\"count\":1}")));

Initializes the mocked file system with a second drive D: with 1MB total available space and creates on it an empty text file foo.txt and a directory sub-dir which contains randomly named json file with {"count":1} as file content.

On non-Windows systems, the main drive can still be configured, e.g.

var fileSystem = new MockFileSystem();
fileSystem.WithDrive(d => d.SetTotalSize(20));

// this will throw an IOException that there is not enough space on the disk.
fileSystem.File.WriteAllText("foo", "some text longer than 20 bytes");

Relationship with TestableIO.System.IO.Abstractions

This library uses the same interfaces as TestableIO.System.IO.Abstractions, which means you can switch between the two testing libraries without changing your production code. Both libraries provide IFileSystem implementations, but with different testing capabilities and API surfaces.

When to use Testably.Abstractions vs TestableIO

  • Use Testably.Abstractions if you need:

    • Advanced testing scenarios (FileSystemWatcher, SafeFileHandles, multiple drives)
    • Additional abstractions (ITimeSystem, IRandomSystem)
    • Cross-platform file system simulation (Linux, MacOS, Windows)
    • More extensive and consistent behavior validation
    • Active development and new features
  • Use TestableIO.System.IO.Abstractions if you need:

    • Basic file system mocking capabilities
    • Direct manipulation of stored file entities (MockFileData, MockDirectoryData)
    • Established codebase with existing TestableIO integration

Migrating from TestableIO

Switching from TestableIO to Testably only requires changes in your test projects:

  1. Replace the NuGet package reference in your test projects:

    
    <PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" />
    
    <PackageReference Include="Testably.Abstractions.Testing" />
    
  2. Update your test code to use the new MockFileSystem:

    // Before (TestableIO)
    var fileSystem = new MockFileSystem();
    fileSystem.AddDirectory("some-directory");
    fileSystem.AddFile("some-file.txt", new MockFileData("content"));
    
    // After (Testably)
    var fileSystem = new MockFileSystem();
    fileSystem.Directory.CreateDirectory("some-directory");
    fileSystem.File.WriteAllText("some-file.txt", "content");
    // or using fluent initialization:
    fileSystem.Initialize()
     .WithSubdirectory("some-directory")
     .WithFile("some-file.txt").Which(f => f
     .HasStringContent("content"));
    

Your production code using IFileSystem remains unchanged.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 is compatible. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on Testably.Abstractions:

Package Downloads
MyLittleContentEngine

A powerful content engine for building static sites with Blazor and ASP.NET Core

AnakinRaW.CommonUtilities

Provides common classes and utilities for personal use.

AnakinRaW.CommonUtilities.FileSystem

Helper classes and methods targeting the file system.

ktsu.Abstractions

A library providing a comprehensive set of interfaces for compression, encryption, hashing, obfuscation, serialization, and filesystem access with zero-allocation Try* methods and convenient default implementations.

Fleece.Core

Core library for Fleece issue tracking

GitHub repositories (4)

Showing the top 4 popular GitHub repositories that depend on Testably.Abstractions:

Repository Stars
ErsatzTV/legacy
Open-source platform that transforms your personal media library into live, custom TV channels.
NethermindEth/nethermind
A robust, high-performance execution client for Ethereum node operators.
Monitor221hz/Pandora-Behaviour-Engine-Plus
Patcher for behavior, character, and skeleton project files for Skyrim Special Edition.
TeamWheelWizard/WheelWizard
WheelWizard, Retro Rewind Launcher
Version Downloads Last Updated
10.2.0 2,112,552 3/24/2026
10.2.0-pre.1 370 3/13/2026
10.1.0 974,619 2/21/2026
10.1.0-rc1 173 2/20/2026
10.0.0 71,931 11/12/2025
10.0.0-pre.1 171 8/15/2025
9.0.0 110,527 1/31/2025
9.0.0-pre.2 128 1/31/2025
9.0.0-pre.1 139 1/30/2025
3.2.4 23,913 11/12/2024
3.2.3 19,742 8/16/2024
3.2.2 1,141 7/17/2024
3.2.1 3,018 5/16/2024
3.2.0 566 5/5/2024
3.1.2 743 4/9/2024
3.1.1 264 4/7/2024
3.1.0 349 4/1/2024
3.0.1 284 3/30/2024
3.0.0 316 3/29/2024
2.6.1 24,417 1/7/2024
Loading failed