-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessResultHandlerTests.cs
100 lines (79 loc) · 2.96 KB
/
ProcessResultHandlerTests.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
namespace CSharpInteractive.Tests;
public class ProcessResultHandlerTests
{
private readonly Mock<ILog<ProcessResultHandler>> _log = new();
private readonly Mock<IStartInfo> _startInfo = new();
private readonly Mock<IExitTracker> _exitTracker = new();
private readonly Text[] _description = [new("Abc")];
private readonly Action<object> _handler = Mock.Of<Action<object>>();
private readonly ProcessInfo _processInfo;
public ProcessResultHandlerTests()
{
_processInfo = new ProcessInfo(_startInfo.Object, Mock.Of<IProcessMonitor>(), 1);
}
[Theory]
[InlineData(ProcessState.Finished)]
internal void ShouldLogInfoWhenFinishedAndHasHandler(ProcessState state)
{
// Given
var handler = CreateInstance();
// When
handler.Handle(new ProcessResult(_processInfo, state, 12, _description), _handler);
// Then
_log.Verify(i => i.Info(_description));
}
[Fact]
public void ShouldLogSummaryWhenFinishedAndHasNoHandler()
{
// Given
var handler = CreateInstance();
// When
handler.Handle(new ProcessResult(_processInfo, ProcessState.Finished, 12, _description), default(Action<object>));
// Then
_log.Verify(i => i.Summary(_description));
}
[Fact]
public void ShouldLogWarningWhenCanceledAndHasNoHandler()
{
// Given
var handler = CreateInstance();
// When
handler.Handle(new ProcessResult(_processInfo, ProcessState.Canceled, 12, _description), default(Action<object>));
// Then
_log.Verify(i => i.Warning(_description));
}
[Fact]
public void ShouldNotLogWarningWhenCanceledAndTerminating()
{
// Given
var handler = CreateInstance();
// When
_exitTracker.SetupGet(i => i.IsTerminating).Returns(true);
handler.Handle(new ProcessResult(_processInfo, ProcessState.Canceled, 12, _description), default(Action<object>));
// Then
_log.Verify(i => i.Warning(_description), Times.Never);
}
[Fact]
public void ShouldLogErrorWhenFailedAndHasNoHandler()
{
// Given
var handler = CreateInstance();
// When
handler.Handle(new ProcessResult(_processInfo, ProcessState.FailedToStart, 12, _description), default(Action<object>));
// Then
_log.Verify(i => i.Error(ErrorId.Process, _description));
}
[Fact]
public void ShouldLogErrorWhenFailedAndHasNoHandlerAndHasError()
{
// Given
var handler = CreateInstance();
var error = new Exception("Some error.");
// When
handler.Handle(new ProcessResult(_processInfo, ProcessState.FailedToStart, 12, _description, null, error), default(Action<object>));
// Then
_log.Verify(i => i.Error(ErrorId.Process, It.Is<Text[]>(text => text.Length == 3)));
}
private ProcessResultHandler CreateInstance() =>
new(_log.Object, _exitTracker.Object);
}