|
1 | 1 | # Shuttle.Core.System |
2 | 2 |
|
| 3 | +OS and system level abstractions that provide a way to decouple your logic from static system calls, making your code more testable. |
| 4 | + |
| 5 | +## Why? |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +dotnet add package Shuttle.Core.System |
3 | 13 | ``` |
4 | | -PM> Install-Package Shuttle.Core.System |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Register the services with your dependency injection container: |
| 18 | + |
| 19 | +```csharp |
| 20 | +services.AddSingleton<ISystemClock, SystemClock>(); |
| 21 | +services.AddSingleton<IEnvironmentService, EnvironmentService>(); |
| 22 | +services.AddSingleton<IProcessService, ProcessService>(); |
5 | 23 | ``` |
6 | 24 |
|
7 | | -OS and system level abstractions. |
| 25 | +All types are in the `Shuttle.Core.System` namespace. |
8 | 26 |
|
9 | | -## ISystemClock |
| 27 | +## `ISystemClock` |
10 | 28 |
|
11 | 29 | The default implementation is `SystemClock`. |
12 | 30 |
|
13 | | -``` c# |
| 31 | +```csharp |
14 | 32 | DateTimeOffset UtcNow { get; } |
15 | 33 | ``` |
16 | 34 |
|
17 | | -Return the `DataTimeOffset` as the current UTC data/time. |
| 35 | +Returns the `DateTimeOffset` representing the current UTC date/time. |
18 | 36 |
|
19 | | -## IEnvironmentService |
| 37 | +## `IEnvironmentService` |
20 | 38 |
|
21 | 39 | The default implementation is `EnvironmentService`. |
22 | 40 |
|
23 | | -``` c# |
| 41 | +```csharp |
24 | 42 | bool UserInteractive { get; } |
25 | 43 | ``` |
26 | 44 |
|
27 | | -Return `true` if running as a console application; else `false`. |
| 45 | +Returns `true` if running as a console application; otherwise `false`. |
28 | 46 |
|
29 | | -## IProcessService |
| 47 | +## `IProcessService` |
30 | 48 |
|
31 | 49 | The default implementation is `ProcessService`. |
32 | 50 |
|
33 | | -``` c# |
| 51 | +```csharp |
34 | 52 | IProcess GetCurrentProcess(); |
35 | 53 | ``` |
36 | 54 |
|
37 | | - Returns the `IProcess` abstraction for the current process. |
| 55 | +Returns an `IProcess` abstraction for the current system process. |
38 | 56 |
|
39 | | -## IProcess |
| 57 | +## `IProcess` |
40 | 58 |
|
41 | | -Represents a system process and the default implementation is `SystemProcess`. |
| 59 | +Represents a system process. The default implementation is `SystemProcess`. |
42 | 60 |
|
43 | | -``` c# |
| 61 | +```csharp |
44 | 62 | void Kill(); |
45 | 63 | ``` |
46 | 64 |
|
|
0 commit comments