-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyServiceTests.cs
45 lines (36 loc) · 1.06 KB
/
MyServiceTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Moq;
using Pure.DI;
namespace Lib.Tests.Integration;
public partial class MyServiceTests
{
private readonly Mock<IOutput> _output = new();
private readonly Mock<IInput> _input = new();
[Fact]
public void ShouldAskToPressEnter()
{
// Given
// When
Service.Run();
// Then
_output.Verify(i => i.WriteLine("Hello!"));
_output.Verify(i => i.WriteLine("Press the Enter key to exit."));
}
[Fact]
public void ShouldWaitForEnter()
{
// Given
// When
Service.Run();
// Then
_input.Verify(i => i.ReadLine());
}
private void Setup() =>
DI.Setup(nameof(MyServiceTests))
// Based on the Composition setup from the Lib namespace
.DependsOn("Lib.Composition")
// Overrides some instances using mocks
.Bind<IOutput>().To(_ => _output.Object)
.Bind<IInput>().To(_ => _input.Object)
// Exposing a test instance as the composition root
.Root<IService>("Service");
}