-
Notifications
You must be signed in to change notification settings - Fork 758
/
TestFrameworkOptionsReadWriteExtensions.cs
353 lines (311 loc) · 15.6 KB
/
TestFrameworkOptionsReadWriteExtensions.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
using System;
using Xunit;
using Xunit.Abstractions;
/// <summary>
/// Extension methods for reading and writing <see cref="ITestFrameworkDiscoveryOptions"/> and <see cref="ITestFrameworkExecutionOptions"/>.
/// </summary>
public static class TestFrameworkOptionsReadWriteExtensions
{
// Read/write methods for ITestFrameworkDiscoveryOptions
/// <summary>
/// Gets a flag that determines whether diagnostic messages will be emitted.
/// </summary>
public static bool? GetDiagnosticMessages(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetValue<bool?>(TestOptionsNames.Discovery.DiagnosticMessages);
}
/// <summary>
/// Gets a flag that determines whether internal diagnostic messages will be emitted.
/// </summary>
public static bool? GetInternalDiagnosticMessages(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetValue<bool?>(TestOptionsNames.Discovery.InternalDiagnosticMessages);
}
/// <summary>
/// Gets a flag that determines whether diagnostic messages will be emitted. If the flag is not
/// set, returns the default value (<c>false</c>).
/// </summary>
public static bool GetDiagnosticMessagesOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetDiagnosticMessages() ?? false;
}
/// <summary>
/// Gets a flag that determines whether internal diagnostic messages will be emitted. If the flag is not
/// set, returns the default value (<c>false</c>).
/// </summary>
public static bool GetInternalDiagnosticMessagesOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetInternalDiagnosticMessages() ?? false;
}
/// <summary>
/// Gets a flag that determines the default display name format for test methods.
/// </summary>
public static TestMethodDisplay? GetMethodDisplay(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
var methodDisplayString = discoveryOptions.GetValue<string>(TestOptionsNames.Discovery.MethodDisplay);
return methodDisplayString != null ? (TestMethodDisplay?)Enum.Parse(typeof(TestMethodDisplay), methodDisplayString) : null;
}
/// <summary>
/// Gets a flag that determines the default display name format for test methods. If the flag is not present,
/// returns the default value (<see cref="TestMethodDisplay.ClassAndMethod"/>).
/// </summary>
public static TestMethodDisplay GetMethodDisplayOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetMethodDisplay() ?? TestMethodDisplay.ClassAndMethod;
}
/// <summary>
/// Gets a flag that determines the default display name format options for test methods.
/// </summary>
public static TestMethodDisplayOptions? GetMethodDisplayOptions(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
var methodDisplayOptionsString = discoveryOptions.GetValue<string>(TestOptionsNames.Discovery.MethodDisplayOptions);
return methodDisplayOptionsString != null ? (TestMethodDisplayOptions?)Enum.Parse(typeof(TestMethodDisplayOptions), methodDisplayOptionsString) : null;
}
/// <summary>
/// Gets a flag that determines the default display name format options for test methods. If the flag is not present,
/// returns the default value (<see cref="TestMethodDisplayOptions.None"/>).
/// </summary>
public static TestMethodDisplayOptions GetMethodDisplayOptionsOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetMethodDisplayOptions() ?? TestMethodDisplayOptions.None;
}
/// <summary>
/// Gets a flag that determines whether theories are pre-enumerated. If they enabled, then the
/// discovery system will return a test case for each row of test data; they are disabled, then the
/// discovery system will return a single test case for the theory.
/// </summary>
public static bool? GetPreEnumerateTheories(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetValue<bool?>(TestOptionsNames.Discovery.PreEnumerateTheories);
}
/// <summary>
/// Gets a flag that determines whether theories are pre-enumerated. If they enabled, then the
/// discovery system will return a test case for each row of test data; they are disabled, then the
/// discovery system will return a single test case for the theory. If the flag is not present,
/// returns the default value (<c>true</c>).
/// </summary>
public static bool GetPreEnumerateTheoriesOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetPreEnumerateTheories() ?? true;
}
/// <summary>
/// Gets a flag that determines whether xUnit.net should report test results synchronously.
/// </summary>
public static bool? GetSynchronousMessageReporting(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetValue<bool?>(TestOptionsNames.Discovery.SynchronousMessageReporting);
}
/// <summary>
/// Gets a flag that determines whether xUnit.net should report test results synchronously.
/// If the flag is not set, returns the default value (<c>false</c>).
/// </summary>
public static bool GetSynchronousMessageReportingOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetSynchronousMessageReporting() ?? false;
}
/// <summary>
/// Sets a flag that determines whether diagnostic messages will be emitted.
/// </summary>
public static void SetDiagnosticMessages(this ITestFrameworkDiscoveryOptions discoveryOptions, bool? value)
{
discoveryOptions.SetValue(TestOptionsNames.Discovery.DiagnosticMessages, value);
}
/// <summary>
/// Sets a flag that determines whether internal diagnostic messages will be emitted.
/// </summary>
public static void SetInternalDiagnosticMessages(this ITestFrameworkDiscoveryOptions discoveryOptions, bool? value)
{
discoveryOptions.SetValue(TestOptionsNames.Discovery.InternalDiagnosticMessages, value);
}
/// <summary>
/// Sets a flag that determines the default display name format for test methods.
/// </summary>
public static void SetMethodDisplay(this ITestFrameworkDiscoveryOptions discoveryOptions, TestMethodDisplay? value)
{
discoveryOptions.SetValue(TestOptionsNames.Discovery.MethodDisplay, value.HasValue ? value.GetValueOrDefault().ToString() : null);
}
/// <summary>
/// Sets the flags that determine the default display options for test methods.
/// </summary>
public static void SetMethodDisplayOptions(this ITestFrameworkDiscoveryOptions discoveryOptions, TestMethodDisplayOptions? value)
{
discoveryOptions.SetValue(TestOptionsNames.Discovery.MethodDisplayOptions, value.HasValue ? value.GetValueOrDefault().ToString() : null);
}
/// <summary>
/// Sets a flag that determines whether theories are pre-enumerated. If they enabled, then the
/// discovery system will return a test case for each row of test data; they are disabled, then the
/// discovery system will return a single test case for the theory.
/// </summary>
public static void SetPreEnumerateTheories(this ITestFrameworkDiscoveryOptions discoveryOptions, bool? value)
{
discoveryOptions.SetValue(TestOptionsNames.Discovery.PreEnumerateTheories, value);
}
/// <summary>
/// Sets a flag that determines whether xUnit.net should report test results synchronously.
/// </summary>
public static void SetSynchronousMessageReporting(this ITestFrameworkDiscoveryOptions discoveryOptions, bool? value)
{
discoveryOptions.SetValue(TestOptionsNames.Discovery.SynchronousMessageReporting, value);
}
// Read/write methods for ITestFrameworkExecutionOptions
/// <summary>
/// Gets a flag that determines whether diagnostic messages will be emitted.
/// </summary>
public static bool? GetDiagnosticMessages(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetValue<bool?>(TestOptionsNames.Execution.DiagnosticMessages);
}
/// <summary>
/// Gets a flag that determines whether internal diagnostic messages will be emitted.
/// </summary>
public static bool? GetInternalDiagnosticMessages(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetValue<bool?>(TestOptionsNames.Execution.InternalDiagnosticMessages);
}
/// <summary>
/// Gets a flag that determines whether diagnostic messages will be emitted. If the flag is not
/// present, returns the default value (<c>false</c>).
/// </summary>
public static bool GetDiagnosticMessagesOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetDiagnosticMessages() ?? false;
}
/// <summary>
/// Gets a flag that determines whether internal diagnostic messages will be emitted. If the flag is not
/// present, returns the default value (<c>false</c>).
/// </summary>
public static bool GetInternalDiagnosticMessagesOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetInternalDiagnosticMessages() ?? false;
}
/// <summary>
/// Gets a flag to disable parallelization.
/// </summary>
public static bool? GetDisableParallelization(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetValue<bool?>(TestOptionsNames.Execution.DisableParallelization);
}
/// <summary>
/// Gets a flag to disable parallelization. If the flag is not present, returns the
/// default value (<c>false</c>).
/// </summary>
public static bool GetDisableParallelizationOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetDisableParallelization() ?? false;
}
/// <summary>
/// Gets the maximum number of threads to use when running tests in parallel.
/// </summary>
public static int? GetMaxParallelThreads(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetValue<int?>(TestOptionsNames.Execution.MaxParallelThreads);
}
/// <summary>
/// Gets the maximum number of threads to use when running tests in parallel. If set to 0 (or not set),
/// the value of <see cref="Environment.ProcessorCount"/> is used; if set to a value less
/// than 0, does not limit the number of threads.
/// </summary>
public static int GetMaxParallelThreadsOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
var result = executionOptions.GetMaxParallelThreads();
if (result == null || result == 0)
return Environment.ProcessorCount;
return result.GetValueOrDefault();
}
/// <summary>
/// Gets the parallel algorithm to be used.
/// </summary>
public static ParallelAlgorithm? GetParallelAlgorithm(this ITestFrameworkExecutionOptions executionOptions)
{
var parallelAlgorithmString = executionOptions.GetValue<string>(TestOptionsNames.Execution.ParallelAlgorithm);
return parallelAlgorithmString != null ? (ParallelAlgorithm?)Enum.Parse(typeof(ParallelAlgorithm), parallelAlgorithmString) : null;
}
/// <summary>
/// Gets the parallel algorithm to be used. If the flag is not present, return the default
/// value (<see cref="ParallelAlgorithm.Conservative"/>).
/// </summary>
public static ParallelAlgorithm GetParallelAlgorithmOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetParallelAlgorithm() ?? ParallelAlgorithm.Conservative;
}
/// <summary>
/// Gets a flag that determines whether xUnit.net stop testing when a test fails.
/// </summary>
public static bool? GetStopOnTestFail(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetValue<bool?>(TestOptionsNames.Execution.StopOnFail);
}
/// <summary>
/// Gets a flag that determines whether xUnit.net stop testing when a test fails. If the flag
/// is not set, returns the default value (<c>false</c>).
/// </summary>
public static bool GetStopOnTestFailOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetStopOnTestFail() ?? false;
}
/// <summary>
/// Gets a flag that determines whether xUnit.net should report test results synchronously.
/// </summary>
public static bool? GetSynchronousMessageReporting(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetValue<bool?>(TestOptionsNames.Execution.SynchronousMessageReporting);
}
/// <summary>
/// Gets a flag that determines whether xUnit.net should report test results synchronously.
/// If the flag is not set, returns the default value (<c>false</c>).
/// </summary>
public static bool GetSynchronousMessageReportingOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetSynchronousMessageReporting() ?? false;
}
/// <summary>
/// Sets a flag that determines whether diagnostic messages will be emitted.
/// </summary>
public static void SetDiagnosticMessages(this ITestFrameworkExecutionOptions executionOptions, bool? value)
{
executionOptions.SetValue(TestOptionsNames.Execution.DiagnosticMessages, value);
}
/// <summary>
/// Sets a flag that determines whether internal diagnostic messages will be emitted.
/// </summary>
public static void SetInternalDiagnosticMessages(this ITestFrameworkExecutionOptions executionOptions, bool? value)
{
executionOptions.SetValue(TestOptionsNames.Execution.InternalDiagnosticMessages, value);
}
/// <summary>
/// Sets the parallel algorith to be used.
/// </summary>
public static void SetParallelAlgorithm(this ITestFrameworkExecutionOptions executionOptions, ParallelAlgorithm? value)
{
executionOptions.SetValue(TestOptionsNames.Execution.ParallelAlgorithm, value.HasValue ? value.GetValueOrDefault().ToString() : null);
}
/// <summary>
/// Sets a flag that determines whether xUnit.net stop testing when a test fails.
/// </summary>
public static void SetStopOnTestFail(this ITestFrameworkExecutionOptions executionOptions, bool? value)
{
executionOptions.SetValue(TestOptionsNames.Execution.StopOnFail, value);
}
/// <summary>
/// Sets a flag to disable parallelization.
/// </summary>
public static void SetDisableParallelization(this ITestFrameworkExecutionOptions executionOptions, bool? value)
{
executionOptions.SetValue(TestOptionsNames.Execution.DisableParallelization, value);
}
/// <summary>
/// Sets the maximum number of threads to use when running tests in parallel.
/// If set to 0 (the default value), does not limit the number of threads.
/// </summary>
public static void SetMaxParallelThreads(this ITestFrameworkExecutionOptions executionOptions, int? value)
{
executionOptions.SetValue(TestOptionsNames.Execution.MaxParallelThreads, value);
}
/// <summary>
/// Sets a flag that determines whether xUnit.net should report test results synchronously.
/// </summary>
public static void SetSynchronousMessageReporting(this ITestFrameworkExecutionOptions executionOptions, bool? value)
{
executionOptions.SetValue(TestOptionsNames.Execution.SynchronousMessageReporting, value);
}
}