-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMultiEngineTest.cs
More file actions
47 lines (38 loc) · 1.25 KB
/
MultiEngineTest.cs
File metadata and controls
47 lines (38 loc) · 1.25 KB
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
using System.Reflection;
namespace GenHTTP.Testing.Acceptance;
/// <summary>
/// When attributed on a test method, this attribute
/// injects the engines that are target to be tested
/// into the test method.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class MultiEngineTestAttribute : Attribute, ITestDataSource
{
public IEnumerable<object[]> GetData(MethodInfo methodInfo)
{
var engine = Environment.GetEnvironmentVariable("TEST_ENGINE");
if (engine == null) {
return new List<object[]>
{
new object[] { TestEngine.Internal },
new object[] { TestEngine.Kestrel }
};
}
if (Enum.TryParse(engine, out TestEngine found))
{
return new List<object[]>
{
new object[] { found }
};
}
throw new InvalidOperationException($"Engine '{engine}' is not supported");
}
public string GetDisplayName(MethodInfo methodInfo, object?[]? data)
{
if (data?[0] is TestEngine engine)
{
return $"{methodInfo.Name} ({engine.ToString()})";
}
return methodInfo.Name;
}
}