-
-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathTestRegisteredContext.cs
More file actions
69 lines (58 loc) · 2.17 KB
/
TestRegisteredContext.cs
File metadata and controls
69 lines (58 loc) · 2.17 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
64
65
66
67
68
69
using System.Collections.Concurrent;
using TUnit.Core.Interfaces;
namespace TUnit.Core;
/// <summary>
/// Context for test registration phase
/// </summary>
public class TestRegisteredContext
{
public string TestName { get; }
public string? CustomDisplayName { get; }
public TestContext TestContext { get; }
public DiscoveredTest DiscoveredTest { get; set; } = null!;
public TestRegisteredContext(TestContext testContext)
{
TestContext = testContext;
TestName = testContext.Metadata.TestDetails.TestName;
CustomDisplayName = testContext.CustomDisplayName;
}
[Obsolete("Use StateBag property instead.")]
public ConcurrentDictionary<string, object?> ObjectBag => StateBag;
/// <summary>
/// Gets the object bag from the underlying TestContext
/// </summary>
public ConcurrentDictionary<string, object?> StateBag => TestContext.StateBag.Items;
/// <summary>
/// Gets the test details from the underlying TestContext
/// </summary>
public TestDetails TestDetails => TestContext.Metadata.TestDetails;
public void SetTestExecutor(ITestExecutor executor)
{
DiscoveredTest.TestExecutor = executor;
}
/// <summary>
/// Sets a custom hook executor that will be used for all test-level hooks (Before/After Test).
/// This allows you to wrap hook execution in custom logic (e.g., running on a specific thread).
/// </summary>
public void SetHookExecutor(IHookExecutor executor)
{
TestContext.CustomHookExecutor = executor;
}
/// <summary>
/// Sets the parallel limiter for the test
/// </summary>
public void SetParallelLimiter(IParallelLimit parallelLimit)
{
TestContext.ParallelLimiter = parallelLimit;
}
/// <summary>
/// Marks the test as skipped with the specified reason.
/// This can only be called during the test registration phase.
/// </summary>
/// <param name="reason">The reason why the test is being skipped</param>
public void SetSkipped(string reason)
{
TestContext.SkipReason = reason;
TestContext.Metadata.TestDetails.ClassInstance = SkippedTestInstance.Instance;
}
}