Injectable abstractions for the static parts of the .NET base class library (BCL) - file system, time and randomness - with feature-complete in-memory mocks for tests.
📖 Full documentation: docs.testably.org/Abstractions
publicclassReportService(IFileSystemfileSystem){publicvoidSave(stringcontent){fileSystem.Directory.CreateDirectory("reports");fileSystem.File.WriteAllText("reports/latest.xml",content);}}[Fact]publicasyncTaskSave_WritesReportToReportsFolder(){varfileSystem=newMockFileSystem();varsut=newReportService(fileSystem);sut.Save("<report />");awaitExpect.That(fileSystem.File.ReadAllText("reports/latest.xml")).IsEqualTo("<report />");}dotnetaddpackageTestably.AbstractionsdotnetaddpackageTestably.Abstractions.TestingThen register the implementations in your DI container - see Getting Started.
| 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 |
Testably.Abstractions.MemoryMappedFiles | MemoryMappedFile support on IFileSystem |
Testably.Abstractions shares the IFileSystem interface with TestableIO.System.IO.Abstractions, so production code stays untouched. See the migration guide.
Issues and pull requests are welcome - see CONTRIBUTING.md and the issue tracker.