Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions TUnit.Core/TestDetails.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using TUnit.Core.Interfaces;

Expand Down Expand Up @@ -32,10 +33,8 @@ public partial class TestDetails : ITestIdentity, ITestClass, ITestMethod, ITest
public string TestFilePath { get; set; } = "";
public int TestLineNumber { get; set; }
public required Type ReturnType { get; set; }
public IDictionary<string, object?> TestClassInjectedPropertyArguments { get; init; } = new Dictionary<string, object?>();
public List<string> Categories { get; } =
[
];
public IDictionary<string, object?> TestClassInjectedPropertyArguments { get; init; } = new ConcurrentDictionary<string, object?>();
public List<string> Categories { get; } = [];
public Dictionary<string, List<string>> CustomProperties { get; } = new();
public Type[]? TestClassParameterTypes { get; set; }

Expand Down
7 changes: 4 additions & 3 deletions TUnit.Engine/Services/PropertyInitializationOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ private async Task InitializeSourceGeneratedPropertyAsync(
// Set the property value
metadata.SetProperty(instance, resolvedValue);

// Store for potential reuse
if (testContext != null && !testContext.Metadata.TestDetails.TestClassInjectedPropertyArguments.ContainsKey(metadata.PropertyName))
// Store for potential reuse (using TryAdd for thread-safe concurrent access)
if (testContext != null)
{
testContext.Metadata.TestDetails.TestClassInjectedPropertyArguments[metadata.PropertyName] = resolvedValue;
((ConcurrentDictionary<string, object?>)testContext.Metadata.TestDetails.TestClassInjectedPropertyArguments)
.TryAdd(metadata.PropertyName, resolvedValue);
}
}

Expand Down
Loading