Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 3.11 KB

File metadata and controls

64 lines (47 loc) · 3.11 KB

Testably.Abstractions

Testably.Abstractions Testably.Abstractions.Testing Build Quality Gate Status Coverage

Injectable abstractions for the static parts of the .NET BCL - file system, time and randomness - with feature-complete in-memory mocks for tests.

📖 Full documentation: docs.testably.org

Quick example

public class ReportService(IFileSystem fileSystem)
{
    public void Save(string content)
    {
        fileSystem.Directory.CreateDirectory("reports");
        fileSystem.File.WriteAllText("reports/latest.xml", content);
    }
}
[Fact]
public async Task Save_WritesReportToReportsFolder()
{
    var fileSystem = new MockFileSystem();
    var sut = new ReportService(fileSystem);

    sut.Save("<report />");

    await Expect.That(fileSystem.File.ReadAllText("reports/latest.xml"))
        .IsEqualTo("<report />");
}

Install

dotnet add package Testably.Abstractions
dotnet add package Testably.Abstractions.Testing

Then register the implementations in your DI container - see Getting Started.

Packages

Package Purpose
Testably.Abstractions Production interfaces (IFileSystem, ITimeSystem, IRandomSystem)
Testably.Abstractions.Testing MockFileSystem, MockTimeSystem, MockRandomSystem
Testably.Abstractions.Compression Zip / ZipArchive extension methods on IFileSystem
Testably.Abstractions.AccessControl GetAccessControl / SetAccessControl on files and directories

Already on TestableIO?

Testably.Abstractions shares the IFileSystem interface with TestableIO.System.IO.Abstractions, so production code stays untouched. See the migration guide.

Contributing

Issues and pull requests are welcome - see CONTRIBUTING.md and the issue tracker.