forked from thomhurst/TUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIObjectGraphDiscoverer.cs
More file actions
89 lines (84 loc) · 4.01 KB
/
IObjectGraphDiscoverer.cs
File metadata and controls
89 lines (84 loc) · 4.01 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System.Collections.Concurrent;
using TUnit.Core.Discovery;
namespace TUnit.Core.Interfaces;
/// <summary>
/// Defines a contract for discovering object graphs from test contexts.
/// Pure query interface - only reads and returns data, does not modify state.
/// </summary>
/// <remarks>
/// <para>
/// Object graph discovery is used to find all objects that need initialization or disposal,
/// organized by their nesting depth in the object hierarchy.
/// </para>
/// <para>
/// The discoverer traverses:
/// <list type="bullet">
/// <item><description>Test class constructor arguments</description></item>
/// <item><description>Test method arguments</description></item>
/// <item><description>Injected property values</description></item>
/// <item><description>Nested objects that implement <see cref="IAsyncInitializer"/></description></item>
/// </list>
/// </para>
/// <para>
/// For tracking operations that modify TestContext.TrackedObjects, see <see cref="IObjectGraphTracker"/>.
/// </para>
/// </remarks>
internal interface IObjectGraphDiscoverer
{
/// <summary>
/// Discovers all objects from a test context, organized by depth level.
/// </summary>
/// <param name="testContext">The test context to discover objects from.</param>
/// <param name="cancellationToken">Optional cancellation token for long-running discovery.</param>
/// <returns>
/// An <see cref="IObjectGraph"/> containing all discovered objects organized by depth.
/// Depth 0 contains root objects (arguments and property values).
/// Higher depths contain nested objects.
/// </returns>
ObjectGraph DiscoverObjectGraph(TestContext testContext, CancellationToken cancellationToken = default);
/// <summary>
/// Discovers nested objects from a single root object, organized by depth.
/// </summary>
/// <param name="rootObject">The root object to discover nested objects from.</param>
/// <param name="cancellationToken">Optional cancellation token for long-running discovery.</param>
/// <returns>
/// An <see cref="IObjectGraph"/> containing all discovered objects organized by depth.
/// Depth 0 contains the root object itself.
/// Higher depths contain nested objects.
/// </returns>
ObjectGraph DiscoverNestedObjectGraph(object rootObject, CancellationToken cancellationToken = default);
/// <summary>
/// Discovers objects and populates the test context's tracked objects dictionary directly.
/// Used for efficient object tracking without intermediate allocations.
/// </summary>
/// <param name="testContext">The test context to discover objects from and populate.</param>
/// <param name="cancellationToken">Optional cancellation token for long-running discovery.</param>
/// <returns>
/// The tracked objects dictionary (same as testContext.TrackedObjects) populated with discovered objects.
/// </returns>
/// <remarks>
/// This method modifies testContext.TrackedObjects directly. For pure query operations,
/// use <see cref="DiscoverObjectGraph"/> instead.
/// </remarks>
Dictionary<int, HashSet<object>> DiscoverAndTrackObjects(TestContext testContext, CancellationToken cancellationToken = default);
}
/// <summary>
/// Marker interface for object graph tracking operations.
/// Extends <see cref="IObjectGraphDiscoverer"/> with operations that modify state.
/// </summary>
/// <remarks>
/// <para>
/// This interface exists to support Interface Segregation Principle:
/// clients that only need query operations can depend on <see cref="IObjectGraphDiscoverer"/>,
/// while clients that need tracking can depend on <see cref="IObjectGraphTracker"/>.
/// </para>
/// <para>
/// Currently inherits all methods from <see cref="IObjectGraphDiscoverer"/>.
/// The distinction exists for semantic clarity and future extensibility.
/// </para>
/// </remarks>
internal interface IObjectGraphTracker : IObjectGraphDiscoverer
{
// All methods inherited from IObjectGraphDiscoverer
// This interface provides semantic clarity for tracking operations
}