-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildContextTests.cs
319 lines (284 loc) · 11.2 KB
/
BuildContextTests.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
namespace CSharpInteractive.Tests;
using JetBrains.TeamCity.ServiceMessages.Write;
public class BuildContextTests
{
private readonly Mock<ICommandLineResult> _commandLineResult = new();
private readonly Mock<IStartInfo> _startInfo = new();
[Fact]
public void ShouldProcessStdOutput()
{
// Given
var result = CreateInstance();
var output = new Output(Mock.Of<IStartInfo>(), false, "Abc", 33);
var msg = new BuildMessage(output, BuildMessageState.StdOut, null, "Abc");
// When
var messages = result.ProcessOutput(output);
var buildResult = result.Create(_commandLineResult.Object);
// Then
messages.ShouldBe([msg]);
buildResult.Errors.ShouldNotContain(msg);
}
[Fact]
public void ShouldProcessErrOutput()
{
// Given
var result = CreateInstance();
var output = new Output(Mock.Of<IStartInfo>(), true, "Abc", 33);
var msg = new BuildMessage(output, BuildMessageState.StdError, null, "Abc");
// When
var messages = result.ProcessOutput(output);
var buildResult = result.Create(_commandLineResult.Object);
// Then
messages.ShouldBe([msg]);
buildResult.Errors.ShouldContain(msg);
}
[Fact]
public void ShouldProcessTestFinished()
{
// Given
var result = CreateInstance();
var testStdout = new ServiceMessage("testStdout")
{
{"suiteName", "Assembly1"},
{"name", "Test1"},
{"flowId", "11"},
{"out", "Some output"}
};
var testStderr = new ServiceMessage("testStderr")
{
{"suiteName", "Assembly1"},
{"name", "Test1"},
{"flowId", "11"},
{"out", "Some error"}
};
var testFinished = new ServiceMessage("testFinished")
{
{"suiteName", "Assembly1"},
{"name", "Test1"},
{"flowId", "11"},
{"duration", "123"},
{"displayName", "Test1"},
{"fullyQualifiedName", "Full Test1"},
{"executorUri", "executor://mstestadapter/v2"},
{"lineNumber", "23"}
};
var stdOutput = new Output(_startInfo.Object, false, "Some output", 11);
var errOutput = new Output(_startInfo.Object, true, "Some error", 11);
var finishedOutput = new Output(Mock.Of<IStartInfo>(), false, "Abc", 33);
// When
result.ProcessMessage(stdOutput, testStdout).ToArray().ShouldBe([new BuildMessage(stdOutput, BuildMessageState.StdOut).WithText("Some output")]);
result.ProcessMessage(errOutput, testStderr).ToArray().ShouldBe([new BuildMessage(errOutput, BuildMessageState.StdError).WithText("Some error")]);
result.ProcessMessage(finishedOutput, testFinished).ShouldBeEmpty();
var buildResult = result.Create(_commandLineResult.Object);
// Then
buildResult.Tests.Count.ShouldBe(1);
var test = buildResult.Tests[0];
test.SuiteName.ShouldBe("Assembly1");
test.DisplayName.ShouldBe("Test1");
test.FullyQualifiedName.ShouldBe("Full Test1");
test.Duration.ShouldBe(TimeSpan.FromMilliseconds(123));
test.State.ShouldBe(TestState.Finished);
test.Message.ShouldBeEmpty();
test.Details.ShouldBeEmpty();
test.Output.ShouldBe([stdOutput, errOutput]);
test.ExecutorUri.ShouldBe(new Uri("executor://mstestadapter/v2", UriKind.RelativeOrAbsolute));
test.LineNumber.ShouldBe(23);
}
[Fact]
public void ShouldProcessTestFailed()
{
// Given
var result = CreateInstance();
var testStdout = new ServiceMessage("testStdout")
{
{"suiteName", "Assembly1"},
{"name", "Test1"},
{"flowId", "11"},
{"out", "Some output"}
};
var testFailed = new ServiceMessage("testFailed")
{
{"suiteName", "Assembly1"},
{"name", "Test1"},
{"flowId", "11"},
{"message", "Some message"},
{"details", "Error details"},
{"displayName", "Test1"},
{"resultDisplayName", "Test1 Abc"},
{"fullyQualifiedName", "Full Test1"}
};
var output = new Output(_startInfo.Object, false, string.Empty, 11);
// When
result.ProcessMessage(output, testStdout).ToArray().ShouldBe([new BuildMessage(output, BuildMessageState.StdOut).WithText("Some output")]);
result.ProcessMessage(output, testFailed).ShouldBeEmpty();
var buildResult = result.Create(_commandLineResult.Object);
// Then
buildResult.Tests.Count.ShouldBe(1);
var test = buildResult.Tests[0];
test.SuiteName.ShouldBe("Assembly1");
test.DisplayName.ShouldBe("Test1");
test.ResultDisplayName.ShouldBe("Test1 Abc");
test.FullyQualifiedName.ShouldBe("Full Test1");
test.Duration.ShouldBe(TimeSpan.Zero);
test.State.ShouldBe(TestState.Failed);
test.Message.ShouldBe("Some message");
test.Details.ShouldBe("Error details");
test.Output.ShouldBe([new Output(_startInfo.Object, false, "Some output", 11)]);
}
[Fact]
public void ShouldProcessTestIgnored()
{
// Given
var result = CreateInstance();
var testStdout = new ServiceMessage("testStdout")
{
{"suiteName", "Assembly1"},
{"name", "Test1"},
{"flowId", "11"},
{"out", "Some output"}
};
var testIgnored = new ServiceMessage("testIgnored")
{
{"suiteName", "Assembly1"},
{"name", "Test1"},
{"flowId", "11"},
{"message", "Some message"},
{"displayName", "Test1"},
{"fullyQualifiedName", "Full Test1"}
};
var output = new Output(_startInfo.Object, false, string.Empty, 11);
// When
result.ProcessMessage(output, testStdout).ToArray().ShouldBe([new BuildMessage(output, BuildMessageState.StdOut).WithText("Some output")]);
result.ProcessMessage(output, testIgnored).ShouldBeEmpty();
var buildResult = result.Create(_commandLineResult.Object);
// Then
buildResult.Tests.Count.ShouldBe(1);
var test = buildResult.Tests[0];
test.SuiteName.ShouldBe("Assembly1");
test.DisplayName.ShouldBe("Test1");
test.FullyQualifiedName.ShouldBe("Full Test1");
test.Duration.ShouldBe(TimeSpan.Zero);
test.State.ShouldBe(TestState.Ignored);
test.Message.ShouldBe("Some message");
test.Details.ShouldBeEmpty();
test.Output.ShouldBe([new Output(_startInfo.Object, false, "Some output", 11)]);
}
[Theory]
[InlineData("Normal", BuildMessageState.StdOut)]
[InlineData("normal", BuildMessageState.StdOut)]
[InlineData("NORMAL", BuildMessageState.StdOut)]
[InlineData("Warning", BuildMessageState.Warning)]
[InlineData("warning", BuildMessageState.Warning)]
[InlineData("WARNING", BuildMessageState.Warning)]
[InlineData("Failure", BuildMessageState.Failure)]
[InlineData("failure", BuildMessageState.Failure)]
[InlineData("FAILURE", BuildMessageState.Failure)]
[InlineData("Error", BuildMessageState.StdError)]
[InlineData("error", BuildMessageState.StdError)]
[InlineData("ERROR", BuildMessageState.StdError)]
public void ShouldProcessMessage(string status, BuildMessageState state)
{
// Given
var result = CreateInstance();
var message = new ServiceMessage("message")
{
{"text", "some text"},
{"status", status},
{"errorDetails", "error details"},
{"code", "xUnit1026"},
{"file", @"C:\Projects\_temp\xu\TestProject1\TestProject1.cs"},
{"subcategory", "Abc"},
{"projectFile", @"C:\Projects\_temp\xu\TestProject1\TestProject1.csproj"},
{"senderName", "Csc"},
{"columnNumber", "1"},
{"endColumnNumber", "2"},
{"lineNumber", "3"},
{"endLineNumber", "4"},
{"importance", "High"}
};
var output = new Output(_startInfo.Object, false, string.Empty, 11);
var buildMessage = new BuildMessage(
output,
state,
null,
"some text",
"error details",
"xUnit1026",
@"C:\Projects\_temp\xu\TestProject1\TestProject1.cs",
"Abc",
@"C:\Projects\_temp\xu\TestProject1\TestProject1.csproj",
"Csc",
1,
2,
3,
4,
DotNetMessageImportance.High);
// When
result.ProcessMessage(output, message).ShouldBe([buildMessage]);
var buildResult = result.Create(_commandLineResult.Object);
// Then
buildResult.Tests.Count.ShouldBe(0);
// ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
switch (state)
{
case BuildMessageState.ServiceMessage:
case BuildMessageState.StdOut:
buildResult.Errors.ShouldBe(Array.Empty<BuildMessage>());
break;
case BuildMessageState.Warning:
buildResult.Warnings.ShouldBe([buildMessage]);
break;
case BuildMessageState.Failure:
case BuildMessageState.StdError:
case BuildMessageState.BuildProblem:
buildResult.Errors.ShouldBe([buildMessage]);
break;
}
}
[Fact]
public void ShouldBuildProblem()
{
// Given
var result = CreateInstance();
var buildProblem = new ServiceMessage("buildProblem")
{
{"description", "Problem description"},
{"errorDetails", "error details"},
{"code", "xUnit1026"},
{"file", @"C:\Projects\_temp\xu\TestProject1\TestProject1.cs"},
{"subcategory", "Abc"},
{"projectFile", @"C:\Projects\_temp\xu\TestProject1\TestProject1.csproj"},
{"senderName", "Csc"},
{"columnNumber", "1"},
{"endColumnNumber", "2"},
{"lineNumber", "3"},
{"endLineNumber", "4"},
{"importance", "High"}
};
var output = new Output(_startInfo.Object, false, string.Empty, 11);
var buildMessage = new BuildMessage(
output,
BuildMessageState.BuildProblem,
null,
"Problem description",
"error details",
"xUnit1026",
@"C:\Projects\_temp\xu\TestProject1\TestProject1.cs",
"Abc",
@"C:\Projects\_temp\xu\TestProject1\TestProject1.csproj",
"Csc",
1,
2,
3,
4,
DotNetMessageImportance.High);
// When
result.ProcessMessage(output, buildProblem).ShouldBe([buildMessage]);
var buildResult = result.Create(_commandLineResult.Object);
// Then
buildResult.Tests.Count.ShouldBe(0);
buildResult.Errors.ShouldBe([buildMessage]);
}
private static BuildContext CreateInstance() => new();
}