-
Notifications
You must be signed in to change notification settings - Fork 255
/
TestNodeProperties.cs
333 lines (292 loc) · 11.6 KB
/
TestNodeProperties.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.Testing.Platform.Extensions.Messages;
#pragma warning disable SA1201 // Elements should appear in the correct order
/// <summary>
/// The interface that every test node property must implement.
/// </summary>
public interface IProperty
{
}
/// <summary>
/// Node property that represents a key-value pair.
/// </summary>
/// <param name="Key">Key name.</param>
/// <param name="Value">Key value.</param>
public record KeyValuePairStringProperty(string Key, string Value) : IProperty;
/// <summary>
/// Base class for test node state properties.
/// </summary>
/// <param name="Explanation">Textual explanation of the node state.</param>
public abstract record TestNodeStateProperty(string? Explanation) : IProperty;
/// <summary>
/// Property that represents test node that has been discovered.
/// </summary>
/// <param name="Explanation">Textual explanation of the node.</param>
public sealed record DiscoveredTestNodeStateProperty(string? Explanation = null) : TestNodeStateProperty(Explanation)
{
/// <summary>
/// Gets cached instance of the <see cref="DiscoveredTestNodeStateProperty"/>.
/// </summary>
public static DiscoveredTestNodeStateProperty CachedInstance { get; } = new DiscoveredTestNodeStateProperty();
}
/// <summary>
/// Property that represents a test node that is being executed.
/// </summary>
/// <param name="Explanation">Textual explanation of the node.</param>
public sealed record InProgressTestNodeStateProperty(string? Explanation = null) : TestNodeStateProperty(Explanation)
{
/// <summary>
/// Gets cached instance of the <see cref="InProgressTestNodeStateProperty"/>.
/// </summary>
public static InProgressTestNodeStateProperty CachedInstance { get; } = new InProgressTestNodeStateProperty();
}
/// <summary>
/// Property that represents a test node that has been executed and passed.
/// </summary>
/// <param name="Explanation">Textual explanation of the node.</param>
public sealed record PassedTestNodeStateProperty(string? Explanation = null) : TestNodeStateProperty(Explanation)
{
public static PassedTestNodeStateProperty CachedInstance { get; } = new PassedTestNodeStateProperty();
}
/// <summary>
/// Property that represents a test node that has been skipped.
/// </summary>
/// <param name="Explanation">Textual explanation of the node.</param>
public sealed record SkippedTestNodeStateProperty(string? Explanation = null) : TestNodeStateProperty(Explanation)
{
public static SkippedTestNodeStateProperty CachedInstance { get; } = new SkippedTestNodeStateProperty();
}
/// <summary>
/// Property that represents a test node that has been failed.
/// </summary>
public sealed record FailedTestNodeStateProperty : TestNodeStateProperty
{
/// <summary>
/// Initializes a new instance of the <see cref="FailedTestNodeStateProperty"/> class.
/// </summary>
public FailedTestNodeStateProperty()
: base(default(string))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FailedTestNodeStateProperty"/> class.
/// </summary>
/// <param name="explanation">Failure explanation.</param>
public FailedTestNodeStateProperty(string explanation)
: base(explanation)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FailedTestNodeStateProperty"/> class.
/// </summary>
/// <param name="exception">Failure exception.</param>
/// <param name="explanation">Failure explanation.</param>
public FailedTestNodeStateProperty(Exception exception, string? explanation = null)
: base(explanation ?? exception.Message)
{
Exception = exception;
}
/// <summary>
/// Gets the failure exception.
/// </summary>
public Exception? Exception { get; }
}
/// <summary>
/// Property that represents an eventual error in the test node.
/// </summary>
public sealed record ErrorTestNodeStateProperty : TestNodeStateProperty
{
/// <summary>
/// Initializes a new instance of the <see cref="ErrorTestNodeStateProperty"/> class.
/// </summary>
public ErrorTestNodeStateProperty()
: base(default(string))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ErrorTestNodeStateProperty"/> class.
/// </summary>
/// <param name="explanation">Error explanation.</param>
public ErrorTestNodeStateProperty(string explanation)
: base(explanation)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ErrorTestNodeStateProperty"/> class.
/// </summary>
/// <param name="exception">Error exception.</param>
/// <param name="explanation">Error explanation.</param>
public ErrorTestNodeStateProperty(Exception exception, string? explanation = null)
: base(explanation ?? exception.Message)
{
Exception = exception;
}
/// <summary>
/// Gets the error exception.
/// </summary>
public Exception? Exception { get; }
}
/// <summary>
/// Property that represents an eventual timeout in the test node.
/// </summary>
public sealed record TimeoutTestNodeStateProperty : TestNodeStateProperty
{
/// <summary>
/// Initializes a new instance of the <see cref="TimeoutTestNodeStateProperty"/> class.
/// </summary>
public TimeoutTestNodeStateProperty()
: base(default(string))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="TimeoutTestNodeStateProperty"/> class.
/// </summary>
/// <param name="explanation">Timeout explanation.</param>
public TimeoutTestNodeStateProperty(string explanation)
: base(explanation)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="TimeoutTestNodeStateProperty"/> class.
/// </summary>
/// <param name="exception">Timeout exception.</param>
/// <param name="explanation">Timeout explanation.</param>
public TimeoutTestNodeStateProperty(Exception exception, string? explanation = null)
: base(explanation ?? exception.Message)
{
Exception = exception;
}
/// <summary>
/// Gets get the timeout exception.
/// </summary>
public Exception? Exception { get; }
/// <summary>
/// Gets get the timeout Timespan.
/// </summary>
public TimeSpan? Timeout { get; init; }
}
/// <summary>
/// Property that represents an eventual cancellation of a test node.
/// </summary>
public sealed record CancelledTestNodeStateProperty : TestNodeStateProperty
{
/// <summary>
/// Initializes a new instance of the <see cref="CancelledTestNodeStateProperty"/> class.
/// </summary>
public CancelledTestNodeStateProperty()
: base(default(string))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CancelledTestNodeStateProperty"/> class.
/// </summary>
/// <param name="explanation">Cancellation explanation.</param>
public CancelledTestNodeStateProperty(string explanation)
: base(explanation)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="CancelledTestNodeStateProperty"/> class.
/// </summary>
/// <param name="exception">Cancellation exception.</param>
/// <param name="explanation">Cancellation explanation.</param>
public CancelledTestNodeStateProperty(Exception exception, string? explanation = null)
: base(explanation ?? exception.Message)
{
Exception = exception;
}
/// <summary>
/// Gets the cancellation exception.
/// </summary>
public Exception? Exception { get; }
}
/// <summary>
/// Information about the timing of a test node.
/// </summary>
/// <param name="StartTime">Test start time.</param>
/// <param name="EndTime">Test end time.</param>
/// <param name="Duration">Total test duration.</param>
public readonly record struct TimingInfo(DateTimeOffset StartTime, DateTimeOffset EndTime, TimeSpan Duration);
/// <summary>
/// Information about the timing of a test node step.
/// </summary>
/// <param name="Id">Step identifier.</param>
/// <param name="Description">Step description.</param>
/// <param name="Timing">Step timing info.</param>
public sealed record StepTimingInfo(string Id, string Description, TimingInfo Timing);
/// <summary>
/// Property that represents the timing of a test node.
/// </summary>
public sealed record TimingProperty : IProperty
{
/// <summary>
/// Initializes a new instance of the <see cref="TimingProperty"/> class.
/// </summary>
/// <param name="globalTiming">Timing info.</param>
public TimingProperty(TimingInfo globalTiming)
: this(globalTiming, [])
{
}
/// <summary>
/// Initializes a new instance of the <see cref="TimingProperty"/> class.
/// </summary>
/// <param name="globalTiming">Timing info.</param>
/// <param name="stepTimings">Steps timing.</param>
public TimingProperty(TimingInfo globalTiming, StepTimingInfo[] stepTimings)
{
GlobalTiming = globalTiming;
StepTimings = stepTimings;
}
/// <summary>
/// Gets the global timing info.
/// </summary>
public TimingInfo GlobalTiming { get; }
/// <summary>
/// Gets the steps timing info.
/// </summary>
public StepTimingInfo[] StepTimings { get; }
}
/// <summary>
/// Line position in a file.
/// </summary>
/// <param name="Line">Line number.</param>
/// <param name="Column">Column number.</param>
public record struct LinePosition(int Line, int Column);
/// <summary>
/// Line position span in a file.
/// </summary>
/// <param name="Start">Start line position.</param>
/// <param name="End">End line position.</param>
public record struct LinePositionSpan(LinePosition Start, LinePosition End);
/// <summary>
/// Base property that represents a file location.
/// </summary>
/// <param name="FilePath">File path.</param>
/// <param name="LineSpan">Line position.</param>
public abstract record FileLocationProperty(string FilePath, LinePositionSpan LineSpan) : IProperty;
/// <summary>
/// Property that represents a file location for a test node.
/// </summary>
/// <param name="FilePath">File path.</param>
/// <param name="LineSpan">Line position.</param>
public sealed record TestFileLocationProperty(string FilePath, LinePositionSpan LineSpan) : FileLocationProperty(FilePath, LineSpan);
/// <summary>
/// Property that uniquely identifies a test method. Values are ECMA-335 compliant.
/// </summary>
/// <param name="AssemblyFullName">Assembly full name.</param>
/// <param name="Namespace">Namespace.</param>
/// <param name="TypeName">Type name.</param>
/// <param name="MethodName">Method name.</param>
/// <param name="ParameterTypeFullNames">Parameter type full name.</param>
/// <param name="ReturnTypeFullName">Return type full name.</param>
public sealed record TestMethodIdentifierProperty(string AssemblyFullName, string Namespace, string TypeName, string MethodName, string[] ParameterTypeFullNames, string ReturnTypeFullName) : IProperty;
/// <summary>
/// Property that represents a generic test metadata property.
/// </summary>
/// <param name="Key">Key name.</param>
/// <param name="Value">Value name.</param>
public sealed record TestMetadataProperty(string Key, string Value) : IProperty;
internal sealed record SerializableKeyValuePairStringProperty(string Key, string Value) : KeyValuePairStringProperty(Key, Value);
internal sealed record SerializableNamedKeyValuePairsStringProperty(string Name, KeyValuePair<string, string>[] Pairs) : IProperty;
internal sealed record SerializableNamedArrayStringProperty(string Name, string[] Values) : IProperty;