-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHostServiceTests.cs
160 lines (123 loc) · 3.31 KB
/
HostServiceTests.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
namespace CSharpInteractive.Tests;
using CSharpInteractive;
public class HostServiceTests
{
private readonly Mock<ILog<HostService>> _log = new();
private readonly Mock<ISettings> _settings = new();
private readonly Mock<IStdOut> _stdOut = new();
private readonly Mock<IProperties> _properties = new();
[Fact]
public void ShouldProvideArgs()
{
// Given
var host = CreateInstance();
var args = Mock.Of<IReadOnlyList<string>>();
_settings.SetupGet(i => i.ScriptArguments).Returns(args);
// When
// Then
host.Args.ShouldBe(args);
}
[Fact]
public void ShouldProvideProps()
{
// Given
var host = CreateInstance();
// When
// Then
host.Props.ShouldBe(_properties.Object);
}
[Fact]
public void ShouldWritEmptyLine()
{
// Given
var host = CreateInstance();
// When
host.WriteLine();
// Then
_stdOut.Verify(i => i.WriteLine());
}
[Fact]
public void ShouldWritLine()
{
// Given
var host = CreateInstance();
// When
host.WriteLine("Out");
// Then
_stdOut.Verify(i => i.WriteLine(It.Is<Text[]>(text => text.Length == 1 && text[0].Value == "Out" && text[0].Color == Color.Default)));
}
[Fact]
public void ShouldSendError()
{
// Given
var host = CreateInstance();
// When
host.Error("Err", "Id");
// Then
_log.Verify(i => i.Error(new ErrorId("Id"), "Err"));
}
[Fact]
public void ShouldSendWarning()
{
// Given
var host = CreateInstance();
// When
host.Warning("Warn");
// Then
_log.Verify(i => i.Warning("Warn"));
}
[Fact]
public void ShouldSendSummary()
{
// Given
var host = CreateInstance();
// When
host.Summary("Summary message");
// Then
_log.Verify(i => i.Summary("Summary message"));
}
[Fact]
public void ShouldSendInfo()
{
// Given
var host = CreateInstance();
// When
host.Info("Info");
// Then
_log.Verify(i => i.Info("Info"));
}
[Fact]
public void ShouldSendTrace()
{
// Given
var host = CreateInstance();
// When
host.Trace("Trace");
// Then
_log.Verify(i => i.Trace(It.Is<Func<Text[]>>(textProvider => CheckTrace(textProvider())), string.Empty));
}
[Fact]
public void ShouldGetServiceProvider()
{
// Given
var host = CreateInstance();
// When
var serviceProvider = host.GetService<IServiceProvider>();
// Then
serviceProvider.ShouldNotBeNull();
}
[Fact]
public void ShouldProvideHostViaServiceProvider()
{
// Given
var host = Composition.Shared.Root.Host;
// When
var actualHost = host.GetService<IServiceProvider>().GetService(typeof(IHost));
// Then
actualHost.ShouldBe(host);
}
private static bool CheckTrace(IReadOnlyList<Text> text) =>
text is [{Value: "Trace", Color: Color.Default}];
private HostService CreateInstance() =>
new(_log.Object, _settings.Object, _stdOut.Object, _properties.Object);
}