-
-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathAfterTestContext.cs
More file actions
63 lines (50 loc) · 1.59 KB
/
AfterTestContext.cs
File metadata and controls
63 lines (50 loc) · 1.59 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using TUnit.Core.Enums;
namespace TUnit.Core;
public class AfterTestContext
{
internal readonly DiscoveredTest DiscoveredTest;
internal AfterTestContext(DiscoveredTest discoveredTest)
{
DiscoveredTest = discoveredTest;
}
public TestContext TestContext => DiscoveredTest.TestContext;
public TestDetails TestDetails => TestContext.TestDetails;
public void OverrideResult(Status status, string reason)
{
var testResult = TestContext.Result;
if (testResult is null)
{
throw new InvalidOperationException("There is no test result to override.");
}
OverrideResult(testResult with
{
Status = status,
IsOverridden = true,
OverrideReason = reason
});
if(status == Status.Skipped)
{
TestContext.SkipReason = reason;
}
}
public void OverrideResult(Exception exception, string reason)
{
var testResult = TestContext.Result;
if (testResult is null)
{
throw new InvalidOperationException("There is no test result to override.");
}
OverrideResult(testResult with
{
Status = Status.Failed,
Exception = exception,
IsOverridden = true,
OverrideReason = reason,
});
}
private void OverrideResult(TestResult result)
{
TestContext.Result = result;
}
public static implicit operator TestContext(AfterTestContext afterTestContext) => afterTestContext.TestContext;
}