Shuttle.Platform
OS and system level abstractions that provide a way to decouple your logic from static system calls, making your code more testable.
Why?
When your code calls DateTimeOffset.UtcNow, Environment.UserInteractive, or Process.GetCurrentProcess(), it is difficult to unit test that code because these are static calls to the operating system. By using these abstractions, you can mock the system-level behavior in your tests.
Installation
dotnet add package Shuttle.PlatformUsage
Register the services with your dependency injection container:
services.AddSingleton<ISystemClock, SystemClock>();
services.AddSingleton<IEnvironmentService, EnvironmentService>();
services.AddSingleton<IProcessService, ProcessService>();All types are in the Shuttle.Platform namespace.
ISystemClock
The default implementation is SystemClock.
DateTimeOffset UtcNow { get; }Returns the DateTimeOffset representing the current UTC date/time.
IEnvironmentService
The default implementation is EnvironmentService.
bool UserInteractive { get; }Returns true if running as a console application; otherwise false.
IProcessService
The default implementation is ProcessService.
IProcess GetCurrentProcess();Returns an IProcess abstraction for the current system process.
IProcess
Represents a system process. The default implementation is SystemProcess.
void Kill();Kills the process.