Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

943 Commits

Repository files navigation

Testably.Abstractions

Testably.AbstractionsTestably.Abstractions.TestingBuildQuality Gate StatusCoverage

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

Quick example

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 />");}

Install

dotnetaddpackageTestably.AbstractionsdotnetaddpackageTestably.Abstractions.Testing

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

Packages

PackagePurpose
Testably.AbstractionsProduction interfaces (IFileSystem, ITimeSystem, IRandomSystem)
Testably.Abstractions.TestingMockFileSystem, MockTimeSystem, MockRandomSystem
Testably.Abstractions.CompressionZip / ZipArchive extension methods on IFileSystem
Testably.Abstractions.AccessControlGetAccessControl / SetAccessControl on files and directories
Testably.Abstractions.MemoryMappedFilesMemoryMappedFile support on IFileSystem

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.

About

Depend on IFileSystem, ITimeSystem and IRandomSystem in production. Swap in the in-memory mocks for tests - deterministic, cross-platform, no temp folders or Thread.Sleep.

Resources

Code of conduct

Contributing

Stars

87 stars

Watchers

1 watching

Forks

Sponsor this project

Used by

Contributors

Languages