forked from thomhurst/TUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackableObjectGraphProvider.cs
More file actions
56 lines (50 loc) · 1.92 KB
/
TrackableObjectGraphProvider.cs
File metadata and controls
56 lines (50 loc) · 1.92 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
using System.Collections.Concurrent;
using TUnit.Core.Discovery;
using TUnit.Core.Interfaces;
using TUnit.Core.StaticProperties;
namespace TUnit.Core.Tracking;
/// <summary>
/// Provides trackable objects from test contexts for lifecycle management.
/// Delegates to <see cref="ObjectGraphDiscoverer"/> for the actual discovery logic.
/// </summary>
internal class TrackableObjectGraphProvider
{
private readonly IObjectGraphDiscoverer _discoverer;
/// <summary>
/// Creates a new instance with the default discoverer.
/// </summary>
public TrackableObjectGraphProvider() : this(new ObjectGraphDiscoverer())
{
}
/// <summary>
/// Creates a new instance with a custom discoverer (for testing).
/// </summary>
public TrackableObjectGraphProvider(IObjectGraphDiscoverer discoverer)
{
_discoverer = discoverer;
}
/// <summary>
/// Gets trackable objects from a test context, organized by depth level.
/// Delegates to the shared IObjectGraphDiscoverer to eliminate code duplication.
/// </summary>
/// <param name="testContext">The test context to get trackable objects from.</param>
/// <param name="cancellationToken">Optional cancellation token for long-running discovery.</param>
public Dictionary<int, HashSet<object>> GetTrackableObjects(TestContext testContext, CancellationToken cancellationToken = default)
{
// OCP-compliant: Use the interface method directly instead of type-checking
return _discoverer.DiscoverAndTrackObjects(testContext, cancellationToken);
}
/// <summary>
/// Gets trackable objects for static properties (session-level).
/// </summary>
public IEnumerable<object> GetStaticPropertyTrackableObjects()
{
foreach (var value in StaticPropertyRegistry.GetAllInitializedValues())
{
if (value != null)
{
yield return value;
}
}
}
}