Skip to content

Shuttle/Shuttle.Platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shuttle.Core.System

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.Core.System

Usage

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.Core.System 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.

About

OS and system level abstractions.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages