-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTestLoggerContextExtensions.cs
77 lines (71 loc) · 2.71 KB
/
TestLoggerContextExtensions.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
namespace GitHubActionsTestLogger.Tests.Utils.Extensions;
internal static class TestLoggerContextExtensions
{
public static void SimulateTestRun(
this TestReporterContext context,
string testSuiteFilePath,
string targetFrameworkName,
params IReadOnlyList<TestResult> testResults
)
{
context.HandleTestRunStart(
new TestRunStartEventArgs(
new TestRunCriteria(
[testSuiteFilePath],
1,
true,
// lang=xml
$"""
<RunSettings>
<RunConfiguration>
<TargetFrameworkVersion>{targetFrameworkName}</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
"""
)
)
);
foreach (var testResult in testResults)
context.HandleTestResult(new TestResultEventArgs(testResult));
context.HandleTestRunComplete(
new TestRunCompleteEventArgs(
new TestRunStatistics(
new Dictionary<TestOutcome, long>
{
[TestOutcome.Passed] = testResults.Count(r =>
r.Outcome == TestOutcome.Passed
),
[TestOutcome.Failed] = testResults.Count(r =>
r.Outcome == TestOutcome.Failed
),
[TestOutcome.Skipped] = testResults.Count(r =>
r.Outcome == TestOutcome.Skipped
),
[TestOutcome.None] = testResults.Count(r => r.Outcome == TestOutcome.None),
}
),
false,
false,
null,
new Collection<AttachmentSet>(),
TimeSpan.FromSeconds(1.234)
)
);
}
public static void SimulateTestRun(
this TestReporterContext context,
string testSuiteName,
params IReadOnlyList<TestResult> testResults
) => context.SimulateTestRun(testSuiteName, "FakeTargetFramework", testResults);
public static void SimulateTestRun(
this TestReporterContext context,
params IReadOnlyList<TestResult> testResults
) => context.SimulateTestRun("FakeTests.dll", testResults);
}