diff --git a/TUnit.Core/Discovery/ObjectGraphDiscoverer.cs b/TUnit.Core/Discovery/ObjectGraphDiscoverer.cs
index de94eebb9b..96fb88747d 100644
--- a/TUnit.Core/Discovery/ObjectGraphDiscoverer.cs
+++ b/TUnit.Core/Discovery/ObjectGraphDiscoverer.cs
@@ -110,7 +110,7 @@ bool TryAddStandard(object obj, int depth)
return false;
}
- AddToDepth(objectsByDepth, depth, obj);
+ TryAddToHashSet(objectsByDepth, depth, obj);
return true;
}
@@ -133,7 +133,7 @@ public ObjectGraph DiscoverNestedObjectGraph(object rootObject, CancellationToke
if (visitedObjects.Add(rootObject))
{
- AddToDepth(objectsByDepth, 0, rootObject);
+ TryAddToHashSet(objectsByDepth, 0, rootObject);
DiscoverNestedObjects(rootObject, objectsByDepth, visitedObjects, currentDepth: 1, cancellationToken);
}
@@ -148,7 +148,7 @@ public ObjectGraph DiscoverNestedObjectGraph(object rootObject, CancellationToke
/// The test context to discover objects from.
/// Cancellation token for the operation.
/// The tracked objects dictionary (same as testContext.TrackedObjects).
- public ConcurrentDictionary> DiscoverAndTrackObjects(TestContext testContext, CancellationToken cancellationToken = default)
+ public Dictionary> DiscoverAndTrackObjects(TestContext testContext, CancellationToken cancellationToken = default)
{
var visitedObjects = testContext.TrackedObjects;
@@ -188,7 +188,7 @@ bool TryAddStandard(object value, int depth)
return false;
}
- AddToDepth(objectsByDepth, depth, value);
+ TryAddToHashSet(objectsByDepth, depth, value);
return true;
}
@@ -212,7 +212,7 @@ void Recurse(object value, int depth)
///
private void DiscoverNestedObjectsForTracking(
object obj,
- ConcurrentDictionary> visitedObjects,
+ Dictionary> visitedObjects,
int currentDepth,
CancellationToken cancellationToken)
{
@@ -262,24 +262,12 @@ private static bool ShouldSkipType(Type type)
}
///
- /// Adds an object to the specified depth level.
- ///
- private static void AddToDepth(Dictionary> objectsByDepth, int depth, object obj)
- {
- var hashSet = objectsByDepth.GetOrAdd(depth, _ => new HashSet