TruePath.TestableIO.System.IO 0.11.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package TruePath.TestableIO.System.IO --version 0.11.2
                    
NuGet\Install-Package TruePath.TestableIO.System.IO -Version 0.11.2
                    
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="TruePath.TestableIO.System.IO" Version="0.11.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TruePath.TestableIO.System.IO" Version="0.11.2" />
                    
Directory.Packages.props
<PackageReference Include="TruePath.TestableIO.System.IO" />
                    
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 TruePath.TestableIO.System.IO --version 0.11.2
                    
#r "nuget: TruePath.TestableIO.System.IO, 0.11.2"
                    
#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 TruePath.TestableIO.System.IO@0.11.2
                    
#: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=TruePath.TestableIO.System.IO&version=0.11.2
                    
Install as a Cake Addin
#tool nuget:?package=TruePath.TestableIO.System.IO&version=0.11.2
                    
Install as a Cake Tool

TruePath.TestableIO.System.IO

Bridges TruePath and TestableIO.System.IO.Abstractions.

This library provides extension methods for TestableIO.System.IO.Abstractions interfaces (like IFile, IDirectory, etc.) that accept AbsolutePath from TruePath instead of raw strings. This combines the strongly-typed path safety of TruePath with the testability of System.IO.Abstractions.

Features

  • Strongly-typed Paths: Use AbsolutePath for all file system operations.
  • Testability: Full support for IFileSystem abstractions, allowing easy mocking in unit tests.
  • Comprehensive API: Covers IFile, IDirectory, IFileInfo, IDirectoryInfo, and IDriveInfo.
  • Modern .NET Support: Targets net8.0 and net10.0.

Installation

Install the package via NuGet:

dotnet add package TruePath.TestableIO.System.IO

Usage

Basic Example

Instead of using strings, you can use AbsolutePath with your IFileSystem:

using System.IO.Abstractions;
using TruePath;

IFileSystem fileSystem = new FileSystem();
var myPath = new AbsolutePath("/var/log/app.log");

// Extension method on IFile that takes AbsolutePath
fileSystem.File.WriteAllText(myPath, "Hello, TruePath!");

// Where possible there will also be direct extensions methods against an AbsolutePath
// So the above could also be achieved with:
myPath.WriteAllText("Hello");

// This method supports adding the fileSystem so this would also be possible
myPath.WriteAllText("Hello", fileSystem);

// Note that the fileSystem will default to null. In case of nulls a new instance of FileSystem will be created by the method

if (fileSystem.File.Exists(myPath))
{
    var content = fileSystem.File.ReadAllText(myPath);
}
Extension example

In the example above. There will be the following extensions methods. Note that this pattern as general rule is followed by other extensions methods.

There are some variations. For instance Exists will be DirectoryExists on the extension of an AbsolutePath

public static void WriteAllText(this IFile file, AbsolutePath path, ReadOnlySpan<char> contents)
{
    file.WriteAllText(path.Value, contents);
}
public static void WriteAllText(this AbsolutePath path, ReadOnlySpan<char> contents, FileSystem? fileSystem = null)
{
    fileSystem ??= new FileSystem();
    fileSystem.File.WriteAllText(path, contents);
}

Working with Directories

var workDir = new AbsolutePath("/tmp/my-work-dir");

fileSystem.Directory.CreateDirectory(workDir);
var files = fileSystem.Directory.GetFiles(workDir); 
// Returns AbsolutePath[] instead of string[]

Bugs or things missing

Feel free to create an issue or submit a pull request.

Note on use of AI

AI has been used for generating documentation of code samples and for simple parts of the development.

However the generation of the actual extensions methods has been done by writing and actual tool to cloning https://github.com/Testably/Testably.Abstractions and analysing the code with Roslyn and generating the code. These parts have not been autogenerated by AI.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TruePath.TestableIO.System.IO:

Package Downloads
FileBasedApp.Toolkit

Opiniated helpers for a FileBaseApp. Based on TruePath, SimpleExec and Spectre.Console.Cli

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.15.1 38 3/15/2026
0.15.0 144 3/13/2026
0.15.0-rc-01 80 3/12/2026
0.15.0-dev-03 88 3/11/2026
0.15.0-dev-01 105 3/11/2026
0.14.0 110 3/10/2026
0.14.0-preview-02 98 3/10/2026
0.13.0 92 3/8/2026
0.12.0 104 3/7/2026
0.11.2 97 3/5/2026

Fix summaries