Bitbound.SystemAbstractions.TestUtilities
1.0.5
See the version list below for details.
dotnet add package Bitbound.SystemAbstractions.TestUtilities --version 1.0.5
NuGet\Install-Package Bitbound.SystemAbstractions.TestUtilities -Version 1.0.5
<PackageReference Include="Bitbound.SystemAbstractions.TestUtilities" Version="1.0.5" />
<PackageVersion Include="Bitbound.SystemAbstractions.TestUtilities" Version="1.0.5" />
<PackageReference Include="Bitbound.SystemAbstractions.TestUtilities" />
paket add Bitbound.SystemAbstractions.TestUtilities --version 1.0.5
#r "nuget: Bitbound.SystemAbstractions.TestUtilities, 1.0.5"
#:package Bitbound.SystemAbstractions.TestUtilities@1.0.5
#addin nuget:?package=Bitbound.SystemAbstractions.TestUtilities&version=1.0.5
#tool nuget:?package=Bitbound.SystemAbstractions.TestUtilities&version=1.0.5
Bitbound.SystemAbstractions.TestUtilities
In-memory fakes and xUnit helpers for testing services that depend on Bitbound.SystemAbstractions. Unlike the main package, the types here are public so tests can build and inspect them directly.
Install
dotnet add package Bitbound.SystemAbstractions.TestUtilities
FakeFileSystem
FakeFileSystem implements IFileSystem and IFileAccessPermissions entirely in memory. It mirrors the real
implementation's behavior, including parent-directory creation, FileMode/FileAccess/FileShare rules on streams,
zip extraction, and the exception types and messages the BCL throws.
var fileSystem = new FakeFileSystem();
fileSystem.AddFile("/data/config.json", """{"port": 5000}""");
fileSystem.AddDrive("/mnt/data", name: "data", totalSize: 1_000_000, totalFreeSpace: 400_000);
fileSystem.SetResolvedFilePath("dotnet", "/usr/share/dotnet/dotnet");
Assert.True(fileSystem.FileExists("/data/config.json"));
Seeding and inspection helpers:
| Member | Purpose |
|---|---|
AddFile(path, content, ...) |
Seed a file from a string or byte[], creating parent directories. |
AddDirectory(path, ...) |
Seed a directory and its parents. |
AddDrive(rootPath, ...) |
Seed an entry returned by GetDrives(). |
SetResolvedFilePath(fileName, path) |
Program the answer to ResolveFilePath(fileName). |
SetVersionInfoSource(path, sourcePath) |
Back GetFileVersionInfo(path) with a real file's version info. |
The constructor takes directorySeparator (/ by default, \ for Windows-style paths) and isCaseSensitive
(false by default, matching Windows).
FakeRegistry
FakeRegistry implements IRegistryManager against a memory-backed tree, and applies the same value-kind inference and
error semantics as the Windows registry, so code that reads and writes keys is testable on any operating system.
var registry = new FakeRegistry();
registry.SetValue(@"HKEY_CURRENT_USER\Software\MyApp", "InstallDir", @"C:\app");
registry.CurrentUser.OpenSubKey(@"Software\MyApp")!.GetValue("InstallDir");
Seeding and inspection helpers: CreateKey(path), SetValue(keyPath, name, value[, kind]), KeyExists(path),
GetValueNames(path), ValueExists(keyPath, name), and Reset(). The constructor takes isCaseSensitive
(false by default, matching Windows). Both HKEY_CURRENT_USER and HKCU style prefixes resolve to the same hive, as
do the other five hives.
Swap the fakes in over the real registrations:
var services = new ServiceCollection();
services.AddSystemAbstractions();
services.AddSingleton<IFileSystem>(fileSystem);
services.AddSingleton<IFileAccessPermissions>(fileSystem);
services.AddSingleton<IRegistryManager>(registry);
Platform-specific facts and theories
Skip attributes for tests that only work on one operating system. They set Skip at construction time when the current
operating system does not match, so the test reports as skipped rather than failed.
WindowsOnlyFactAttribute, WindowsOnlyTheoryAttribute, LinuxOnlyFactAttribute, LinuxOnlyTheoryAttribute,
MacOnlyFactAttribute, MacOnlyTheoryAttribute.
Session-shaped variants gate on the desktop session rather than the operating system alone:
InteractiveWindowsFactAttribute (interactive Windows session, not a CI runner), WaylandOnlyFactAttribute
(WAYLAND_DISPLAY or XDG_SESSION_TYPE=wayland), and MacKeychainIntegrationFactAttribute (interactive macOS session,
not a CI runner).
[WindowsOnlyFact]
public void Set_WhenAclIsApplied_UpdatesTheFile()
{
// ...
}
Logging
XunitLogger, XunitLogger<T>, and XunitLoggerProvider implement Microsoft.Extensions.Logging on top of xUnit's
ITestOutputHelper, so ILogger output from the services under test lands in the test's output.
services.AddSingleton<ILoggerProvider>(new XunitLoggerProvider(testOutputHelper));
XunitLogger<T> uses typeof(T).Name as the category. BeginScope nests, and each entry lists its open scopes from
innermost to outermost.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- Bitbound.SystemAbstractions (>= 1.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- xunit.v3.extensibility.core (>= 4.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.