TruePath.TestableIO.System.IO
1.1.0
dotnet add package TruePath.TestableIO.System.IO --version 1.1.0
NuGet\Install-Package TruePath.TestableIO.System.IO -Version 1.1.0
<PackageReference Include="TruePath.TestableIO.System.IO" Version="1.1.0" />
<PackageVersion Include="TruePath.TestableIO.System.IO" Version="1.1.0" />
<PackageReference Include="TruePath.TestableIO.System.IO" />
paket add TruePath.TestableIO.System.IO --version 1.1.0
#r "nuget: TruePath.TestableIO.System.IO, 1.1.0"
#:package TruePath.TestableIO.System.IO@1.1.0
#addin nuget:?package=TruePath.TestableIO.System.IO&version=1.1.0
#tool nuget:?package=TruePath.TestableIO.System.IO&version=1.1.0
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.
TruePath 2.0 compatibility
Requires TruePath 2.0.0 or later. Wrapper signatures are unchanged, but TruePath 2.0 normalization and validation apply:
CombineToPath/PathIO.CombineandPathJoin/PathIO.Joinpreserve the injectedIPath's System.IO behavior. They require a fully qualified result and throwArgumentExceptionfor relative results. Windows paths such as\x,C:x, andC:no longer qualify as absolute.- These helpers do not use TruePath's new
/semantics. For example, combiningC:\baseand\xproduces a non-absolute\xand is rejected; TruePath's/instead producesC:\x. - Resolve relative input explicitly with
PathIO.GetFullPath(input, fileSystem)orPathIO.GetFullPath(input, baseDirectory.Value, fileSystem). This keeps resolution inside the supplied abstraction instead of using the real process current directory. - The current-directory
LocalPath.Valueis now".", including aGetRelativePathresult for identical paths. Update string assertions and mock expectations accordingly. ChangeExtensionstill delegates toIPath.ChangeExtension. Unlike TruePath's stricterWithExtension, it can remove a dotfile's filename or change a root path.- Keep using
DirectoryIO.GetFiles(path, pattern, fileSystem)or abstraction overloads for injectable enumeration. TruePath.SystemIo'sGetFiles(LocalPathPattern)accesses the real filesystem.
Features
Instead of using strings, you can use AbsolutePath with your IFileSystem:
For relevant interfaces of the IFileSystem abstraction it will provide extension methods and if possible also provide a convinience method directly on AbsolutePath that allows for a direct way to call it with an optional IFileSystem (if null the default IFileSystem will be used new FileSystem() ).
For instance IFile.WriteAllText will be available as FileIO.WriteAllText(...)
For these there will also be a direct method available on AbsolutePath that allows for a direct way to call it. Note that this will live in the TruePath.TestableIO.System.IO namespace and not System.IO.Abstractions
Note that in some cases. For instance the Create method that is available for both IFile and IDirectory the direct method call will be FileCreate and DirectoryCreate
Example
For instance SetLastWriteTime on IFile is available as
FileSetLastWriteTime(this AbsolutePath path, DateTime lastWriteTime, IFileSystem? fileSystem = null)
and
SetLastWriteTime(this IFile file, AbsolutePath path, DateTime lastWriteTime)
It will also be available with ad call to
FileIO.SetLastWriteTime(AbsolutePath.Create(...), .., ...)
Installation
Install the package via NuGet:
dotnet add package TruePath.TestableIO.System.IO
Usage
Basic Example
using System.IO.Abstractions;
using TruePath;
var fileSystem = new FileSystem();
var myPath = new AbsolutePath("/var/log/app.log");
fileSystem.File.WriteAllText(myPath, "Hello, world!");
myPath.WriteAllText("Hello world", fileSystem);
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, IFileSystem? fileSystem = null)
{
fileSystem ??= new FileSystem();
fileSystem.File.WriteAllText(path, contents);
}
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 | Versions 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. |
-
net10.0
- TestableIO.System.IO.Abstractions.Wrappers (>= 22.2.0)
- Testably.Abstractions.FileSystem.Interface (>= 10.3.0)
- TruePath (>= 2.0.0)
-
net8.0
- TestableIO.System.IO.Abstractions.Wrappers (>= 22.2.0)
- Testably.Abstractions.FileSystem.Interface (>= 10.3.0)
- TruePath (>= 2.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on TruePath.TestableIO.System.IO:
| Package | Downloads |
|---|---|
|
FileBasedApp.Toolkit
General-purpose helpers for file-based apps, including typed paths, URIs, JSON and HTTP utilities. |
|
|
JRK.JevRunner
.NET client for Jev and the TypeSafe System One API that supports an approach using source generators. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0 | 248 | 11/5/2026 |
| 1.0.1 | 640 | 8/25/2026 |
| 1.0.0 | 265 | 8/23/2026 |
| 0.16.1 | 288 | 4/22/2026 |
| 0.16.0 | 789 | 3/29/2026 |
| 0.15.1 | 187 | 3/15/2026 |
| 0.15.0 | 274 | 3/13/2026 |
| 0.15.0-rc-01 | 175 | 3/12/2026 |
| 0.15.0-dev-03 | 168 | 3/11/2026 |
| 0.15.0-dev-01 | 176 | 3/11/2026 |
| 0.14.0 | 176 | 3/10/2026 |
| 0.14.0-preview-02 | 157 | 3/10/2026 |
| 0.13.0 | 150 | 3/8/2026 |
| 0.12.0 | 156 | 3/7/2026 |
| 0.11.2 | 148 | 3/5/2026 |
- Update to use TruePath 2.0