-
Notifications
You must be signed in to change notification settings - Fork 758
/
TestFrameworkOptionsReadExtensions.cs
212 lines (187 loc) · 9.21 KB
/
TestFrameworkOptionsReadExtensions.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
using System;
using Xunit.Abstractions;
using Xunit.Sdk;
/// <summary>
/// Extension methods for reading <see cref="ITestFrameworkDiscoveryOptions"/> and <see cref="ITestFrameworkExecutionOptions"/>.
/// </summary>
public static class TestFrameworkOptionsReadExtensions
{
// Read methods for ITestFrameworkDiscoveryOptions
/// <summary>
/// Gets a flag that determines whether diagnostic messages will be emitted.
/// </summary>
public static bool? DiagnosticMessages(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetValue<bool?>(TestOptionsNames.Discovery.DiagnosticMessages);
}
/// <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 DiagnosticMessagesOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.DiagnosticMessages() ?? false;
}
/// <summary>
/// Gets a flag that determines the default display name format for test methods.
/// </summary>
public static TestMethodDisplay? MethodDisplay(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 options to format test methods.
/// </summary>
public static TestMethodDisplayOptions? MethodDisplayOptions(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 for test methods. If the flag is not present,
/// returns the default value (<see cref="TestMethodDisplay.ClassAndMethod"/>).
/// </summary>
public static TestMethodDisplay MethodDisplayOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.MethodDisplay() ?? TestMethodDisplay.ClassAndMethod;
}
/// <summary>
/// Gets the options that determine the default display formatting options for test methods. If no options are not present,
/// returns the default value (<see cref="TestMethodDisplayOptions.None"/>).
/// </summary>
public static TestMethodDisplayOptions MethodDisplayOptionsOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.MethodDisplayOptions() ?? 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? PreEnumerateTheories(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.GetValue<bool?>(TestOptionsNames.Discovery.PreEnumerateTheories);
}
/// <summary>
/// Gets a flag that determines whether theories are pre-enumerated. If enabled, then the
/// discovery system will return a test case for each row of test data; if 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 PreEnumerateTheoriesOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.PreEnumerateTheories() ?? true;
}
/// <summary>
/// Gets a flag that determines whether xUnit.net should report test results synchronously.
/// </summary>
public static bool? SynchronousMessageReporting(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.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 SynchronousMessageReportingOrDefault(this ITestFrameworkDiscoveryOptions discoveryOptions)
{
return discoveryOptions.SynchronousMessageReporting() ?? false;
}
// Read methods for ITestFrameworkExecutionOptions
/// <summary>
/// Gets a flag that determines whether diagnostic messages will be emitted.
/// </summary>
public static bool? DiagnosticMessages(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetValue<bool?>(TestOptionsNames.Execution.DiagnosticMessages);
}
/// <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 DiagnosticMessagesOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.DiagnosticMessages() ?? false;
}
/// <summary>
/// Gets the parallel algorithm to be used.
/// </summary>
public static ParallelAlgorithm? ParallelAlgorithm(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 ParallelAlgorithmOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.ParallelAlgorithm() ?? Xunit.Sdk.ParallelAlgorithm.Conservative;
}
/// <summary>
/// Gets a flag to disable parallelization.
/// </summary>
public static bool? DisableParallelization(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 DisableParallelizationOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.DisableParallelization() ?? false;
}
/// <summary>
/// Gets the maximum number of threads to use when running tests in parallel.
/// </summary>
public static int? MaxParallelThreads(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 MaxParallelThreadsOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
var result = executionOptions.MaxParallelThreads();
if (result == null || result == 0)
return Environment.ProcessorCount;
return result.GetValueOrDefault();
}
/// <summary>
/// Gets a flag to stop testing on test failure.
/// </summary>
public static bool? StopOnTestFail(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.GetValue<bool?>(TestOptionsNames.Execution.StopOnFail);
}
/// <summary>
/// Gets a flag to stop testing on test failure. If the flag is not present, returns the
/// default value (<c>false</c>).
/// </summary>
public static bool StopOnTestFailOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.StopOnTestFail() ?? false;
}
/// <summary>
/// Gets a flag that determines whether xUnit.net should report test results synchronously.
/// </summary>
public static bool? SynchronousMessageReporting(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 SynchronousMessageReportingOrDefault(this ITestFrameworkExecutionOptions executionOptions)
{
return executionOptions.SynchronousMessageReporting() ?? false;
}
}