diff --git a/.idea/.idea.TUnit/.idea/copilot.data.migration.agent.xml b/.idea/.idea.TUnit/.idea/copilot.data.migration.agent.xml
new file mode 100644
index 0000000000..4ea72a911a
--- /dev/null
+++ b/.idea/.idea.TUnit/.idea/copilot.data.migration.agent.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.TUnit/.idea/copilot.data.migration.edit.xml b/.idea/.idea.TUnit/.idea/copilot.data.migration.edit.xml
new file mode 100644
index 0000000000..8648f9401a
--- /dev/null
+++ b/.idea/.idea.TUnit/.idea/copilot.data.migration.edit.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.serena/cache/csharp/document_symbols_cache_v23-06-25.pkl b/.serena/cache/csharp/document_symbols_cache_v23-06-25.pkl
index 007b9406d8..e0cad6d197 100644
Binary files a/.serena/cache/csharp/document_symbols_cache_v23-06-25.pkl and b/.serena/cache/csharp/document_symbols_cache_v23-06-25.pkl differ
diff --git a/KNOWN_ISSUES.md b/KNOWN_ISSUES.md
deleted file mode 100644
index 1594260393..0000000000
--- a/KNOWN_ISSUES.md
+++ /dev/null
@@ -1,37 +0,0 @@
-# Known Issues in TUnit
-
-## NotInParallel with Multiple Constraint Keys
-
-**Issue**: Tests with multiple `NotInParallel` constraint keys may run in parallel when they shouldn't.
-
-**Example**:
-```csharp
-[Test, NotInParallel(["GroupD", "GroupE"])]
-public async Task Test1() { }
-
-[Test, NotInParallel(["GroupD", "GroupF"])]
-public async Task Test2() { }
-```
-
-Test1 and Test2 share "GroupD" and should not run in parallel, but they might.
-
-**Root Cause**:
-The current implementation adds tests with multiple keys to separate queues for each key. Each queue is processed independently in parallel. This means:
-- GroupD queue will run Test1 and Test2 sequentially
-- But GroupE queue (processing Test1) and GroupF queue (processing Test2) may run concurrently
-- There's no cross-queue coordination to prevent tests sharing any constraint from overlapping
-
-**Workaround**:
-- Use single constraint keys per test
-- Or group related tests in the same test class with a class-level `NotInParallel` attribute
-
-**Fix Required**:
-The scheduler needs to track running tests across all queues and check for shared constraints before starting any test. This requires significant changes to the scheduling algorithm in `TestScheduler.cs` and `TestGroupingService.cs`.
-
-## Assembly-Level Hooks Affecting Unrelated Tests
-
-**Issue**: Assembly-level hooks (e.g., `[AfterEvery(Assembly)]`) run for ALL tests in the assembly, which can cause unexpected failures when hooks from test-specific scenarios affect other tests.
-
-**Workaround**:
-- Avoid using assembly-level hooks in test files that intentionally throw exceptions
-- Or add proper filtering in the hooks to only run for specific test namespaces/classes
\ No newline at end of file
diff --git a/TUnit.Analyzers.Tests/DynamicTestAwaitExpressionSuppressorTests.cs b/TUnit.Analyzers.Tests/DynamicTestAwaitExpressionSuppressorTests.cs
index 0559faedc0..6769a6e4a9 100644
--- a/TUnit.Analyzers.Tests/DynamicTestAwaitExpressionSuppressorTests.cs
+++ b/TUnit.Analyzers.Tests/DynamicTestAwaitExpressionSuppressorTests.cs
@@ -17,95 +17,95 @@ await AnalyzerTestHelpers
using System.Threading.Tasks;
using TUnit;
using TUnit.Core;
-
+
namespace TUnit.TestProject.DynamicTests;
-
+
public class Basic
{
public void SomeMethod()
{
Console.Out.WriteLine(@"Hello, World!");
}
-
+
public async ValueTask SomeMethod_ValueTask()
{
await default(ValueTask);
Console.WriteLine(@"Hello, World!");
}
-
+
public async Task SomeMethod_Task()
{
await Task.CompletedTask;
Console.WriteLine(@"Hello, World!");
}
-
+
public void SomeMethod_Args(int a, string b, bool c)
{
Console.WriteLine(@"Hello, World!");
}
-
+
public async ValueTask SomeMethod_ValueTask_Args(int a, string b, bool c)
{
await default(ValueTask);
Console.WriteLine(@"Hello, World!");
}
-
+
public async Task SomeMethod_Task_Args(int a, string b, bool c)
{
await Task.CompletedTask;
Console.WriteLine(@"Hello, World!");
}
-
+
#pragma warning disable TUnitWIP0001
[DynamicTestBuilder]
#pragma warning restore TUnitWIP0001
public async Task BuildTests(DynamicTestBuilderContext context)
{
await Task.Delay(TimeSpan.FromSeconds(0.5));
-
- context.AddTest(new DynamicTestInstance
+
+ context.AddTest(new DynamicTest
{
TestMethod = @class => @class.SomeMethod(),
TestMethodArguments = [],
Attributes = [new RepeatAttribute(5)]
});
-
- context.AddTest(new DynamicTestInstance
+
+ context.AddTest(new DynamicTest
{
TestMethod = @class => {|#0:@class.SomeMethod_Task()|},
TestMethodArguments = [],
Attributes = [new RepeatAttribute(5)]
});
-
- context.AddTest(new DynamicTestInstance
+
+ context.AddTest(new DynamicTest
{
TestMethod = @class => {|#1:@class.SomeMethod_ValueTask()|},
TestMethodArguments = [],
Attributes = [new RepeatAttribute(5)]
});
-
- context.AddTest(new DynamicTestInstance
+
+ context.AddTest(new DynamicTest
{
TestMethod = @class => @class.SomeMethod_Args(1, "test", true),
TestMethodArguments = [2, "test", false],
Attributes = [new RepeatAttribute(5)]
});
-
- context.AddTest(new DynamicTestInstance
+
+ context.AddTest(new DynamicTest
{
TestMethod = @class => {|#2:@class.SomeMethod_Task_Args(1, "test", true)|},
TestMethodArguments = [2, "test", false],
Attributes = [new RepeatAttribute(5)]
});
-
- context.AddTest(new DynamicTestInstance
+
+ context.AddTest(new DynamicTest
{
TestMethod = @class => {|#3:@class.SomeMethod_ValueTask_Args(1, "test", true)|},
TestMethodArguments = [2, "test", false],
Attributes = [new RepeatAttribute(5)]
});
-
- context.AddTest(new DynamicTestInstance
+
+ context.AddTest(new DynamicTest
{
TestMethod = @class => {|#4:@class.SomeMethod_ValueTask_Args(1, "test", true)|},
TestMethodArguments = [2, "test", false],
diff --git a/TUnit.Analyzers/DynamicTestAwaitExpressionSuppressor.cs b/TUnit.Analyzers/DynamicTestAwaitExpressionSuppressor.cs
index ddcbbddc3f..19145cbd2c 100644
--- a/TUnit.Analyzers/DynamicTestAwaitExpressionSuppressor.cs
+++ b/TUnit.Analyzers/DynamicTestAwaitExpressionSuppressor.cs
@@ -29,7 +29,7 @@ public override void ReportSuppressions(SuppressionAnalysisContext context)
continue;
}
- if (namedTypeSymbol.Name == "DynamicTest" || namedTypeSymbol.Name == "DynamicTestInstance")
+ if (namedTypeSymbol.Name == "DynamicTest" || namedTypeSymbol.Name == "DynamicTest")
{
Suppress(context, diagnostic);
}
diff --git a/TUnit.Assertions.SourceGenerator.Tests/TUnit.Assertions.SourceGenerator.Tests.csproj b/TUnit.Assertions.SourceGenerator.Tests/TUnit.Assertions.SourceGenerator.Tests.csproj
index d208bc7d3b..2366a286a1 100644
--- a/TUnit.Assertions.SourceGenerator.Tests/TUnit.Assertions.SourceGenerator.Tests.csproj
+++ b/TUnit.Assertions.SourceGenerator.Tests/TUnit.Assertions.SourceGenerator.Tests.csproj
@@ -28,11 +28,5 @@
-
-
- PreserveNewest
-
-
-
-
\ No newline at end of file
+
diff --git a/TUnit.Core.SourceGenerator.Tests/!newname! b/TUnit.Core.SourceGenerator.Tests/!newname!
new file mode 100644
index 0000000000..06aed7c825
--- /dev/null
+++ b/TUnit.Core.SourceGenerator.Tests/!newname!
@@ -0,0 +1,575 @@
+//
+#pragma warning disable
+
+//
+#pragma warning disable
+#nullable enable
+namespace TUnit.Generated;
+internal sealed class Tests_GenericArgumentsTest_TestSource_GUID : global::TUnit.Core.Interfaces.SourceGenerator.ITestSource
+{
+ public async global::System.Collections.Generic.IAsyncEnumerable GetTestsAsync(string testSessionId, [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken = default)
+ {
+ // Create generic metadata with concrete type registrations
+ var genericMetadata = new global::TUnit.Core.GenericTestMetadata
+ {
+ TestName = "GenericArgumentsTest",
+ TestClassType = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TestMethodName = "GenericArgumentsTest",
+ Dependencies = global::System.Array.Empty(),
+ AttributeFactory = () =>
+ [
+ new global::TUnit.Core.TestAttribute(),
+ new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
+ ],
+ DataSources = global::System.Array.Empty(),
+ ClassDataSources = global::System.Array.Empty(),
+ PropertyDataSources = global::System.Array.Empty(),
+ PropertyInjections = new global::TUnit.Core.PropertyInjectionData[]
+ {
+ },
+ InheritanceDepth = 0,
+ FilePath = @"",
+ LineNumber = 8,
+ MethodMetadata = new global::TUnit.Core.MethodMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "GenericArgumentsTest",
+ GenericTypeCount = 1,
+ ReturnType = typeof(global::System.Threading.Tasks.Task),
+ ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(object))
+ {
+ Name = "value",
+ TypeReference = global::TUnit.Core.TypeReference.CreateGenericParameter(0, true, "T"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[0]!
+ },
+ new global::TUnit.Core.ParameterMetadata(typeof(string))
+ {
+ Name = "expected",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("string, System.Private.CoreLib"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]!
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () =>
+ {
+ var classMetadata = new global::TUnit.Core.ClassMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "Tests",
+ Namespace = "TUnit.TestProject.Bugs._2136",
+ Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
+ Parameters = global::System.Array.Empty(),
+ Properties = global::System.Array.Empty(),
+ Parent = null
+ };
+ // Set ClassMetadata and ContainingTypeMetadata references on properties to avoid circular dependency
+ foreach (var prop in classMetadata.Properties)
+ {
+ prop.ClassMetadata = classMetadata;
+ prop.ContainingTypeMetadata = classMetadata;
+ }
+ return classMetadata;
+ })
+ },
+ InstanceFactory = (typeArgs, args) =>
+ {
+ return new global::TUnit.TestProject.Bugs._2136.Tests();
+ },
+ TestInvoker = async (instance, args) =>
+ {
+ var instanceType = instance.GetType();
+ var method = instanceType.GetMethod("GenericArgumentsTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance);
+ if (method == null)
+ {
+ throw new global::System.InvalidOperationException($"Method 'GenericArgumentsTest' not found on type {instanceType.FullName}");
+ }
+ // Make the method generic if it has type parameters
+ if (method.IsGenericMethodDefinition)
+ {
+ // Use the resolved generic types from the test context
+ var testContext = global::TUnit.Core.TestContext.Current;
+ var resolvedTypes = testContext?.TestDetails?.MethodGenericArguments;
+ if (resolvedTypes != null && resolvedTypes.Length > 0)
+ {
+ // Use the pre-resolved generic types
+ method = method.MakeGenericMethod(resolvedTypes);
+ }
+ else
+ {
+ // Fallback: infer type arguments from the actual argument types
+ var typeArgs = new global::System.Type[1];
+ for (int i = 0; i < typeArgs.Length && i < args.Length; i++)
+ {
+ typeArgs[i] = args[i]?.GetType() ?? typeof(object);
+ }
+ method = method.MakeGenericMethod(typeArgs);
+ }
+ }
+ // Prepare method arguments
+ var methodArgs = new object?[args.Length];
+ args.CopyTo(methodArgs, 0);
+ // Invoke the method
+ var result = method.Invoke(instance, methodArgs);
+ if (result is global::System.Threading.Tasks.Task task)
+ {
+ await task;
+ }
+ },
+ ConcreteInstantiations = new global::System.Collections.Generic.Dictionary
+ {
+ [(typeof(bool).FullName ?? typeof(bool).Name)] =
+ new global::TUnit.Core.TestMetadata
+ {
+ TestName = "GenericArgumentsTest",
+ TestClassType = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TestMethodName = "GenericArgumentsTest",
+ GenericMethodTypeArguments = new global::System.Type[] { typeof(bool)},
+ Dependencies = global::System.Array.Empty(),
+ AttributeFactory = () =>
+ [
+ new global::TUnit.Core.TestAttribute(),
+ new global::TUnit.Core.ArgumentsAttribute(true, "True"),
+ new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
+ ],
+ DataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ new global::TUnit.Core.ArgumentsAttribute(true, "True"),
+ },
+ ClassDataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ },
+ PropertyDataSources = global::System.Array.Empty(),
+ PropertyInjections = new global::TUnit.Core.PropertyInjectionData[]
+ {
+ },
+ FilePath = @"",
+ LineNumber = 8,
+ InheritanceDepth = 0,
+ TestSessionId = testSessionId,
+ MethodMetadata = new global::TUnit.Core.MethodMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "GenericArgumentsTest",
+ GenericTypeCount = 1,
+ ReturnType = typeof(global::System.Threading.Tasks.Task),
+ ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(object))
+ {
+ Name = "value",
+ TypeReference = global::TUnit.Core.TypeReference.CreateGenericParameter(0, true, "T"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[0]!
+ },
+ new global::TUnit.Core.ParameterMetadata(typeof(string))
+ {
+ Name = "expected",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("string, System.Private.CoreLib"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]!
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () =>
+ {
+ var classMetadata = new global::TUnit.Core.ClassMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "Tests",
+ Namespace = "TUnit.TestProject.Bugs._2136",
+ Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
+ Parameters = global::System.Array.Empty(),
+ Properties = global::System.Array.Empty(),
+ Parent = null
+ };
+ // Set ClassMetadata and ContainingTypeMetadata references on properties to avoid circular dependency
+ foreach (var prop in classMetadata.Properties)
+ {
+ prop.ClassMetadata = classMetadata;
+ prop.ContainingTypeMetadata = classMetadata;
+ }
+ return classMetadata;
+ })
+ },
+ InstanceFactory = (typeArgs, args) =>
+ {
+ return new global::TUnit.TestProject.Bugs._2136.Tests();
+ },
+ InvokeTypedTest = async (instance, args, cancellationToken) =>
+ {
+ var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance;
+ await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((bool)args[0]!, (string)args[1]!));
+ }
+ }
+ ,
+ [(typeof(int).FullName ?? typeof(int).Name)] =
+ new global::TUnit.Core.TestMetadata
+ {
+ TestName = "GenericArgumentsTest",
+ TestClassType = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TestMethodName = "GenericArgumentsTest",
+ GenericMethodTypeArguments = new global::System.Type[] { typeof(int)},
+ Dependencies = global::System.Array.Empty(),
+ AttributeFactory = () =>
+ [
+ new global::TUnit.Core.TestAttribute(),
+ new global::TUnit.Core.ArgumentsAttribute(1, "1"),
+ new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
+ ],
+ DataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ new global::TUnit.Core.ArgumentsAttribute(1, "1"),
+ },
+ ClassDataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ },
+ PropertyDataSources = global::System.Array.Empty(),
+ PropertyInjections = new global::TUnit.Core.PropertyInjectionData[]
+ {
+ },
+ FilePath = @"",
+ LineNumber = 8,
+ InheritanceDepth = 0,
+ TestSessionId = testSessionId,
+ MethodMetadata = new global::TUnit.Core.MethodMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "GenericArgumentsTest",
+ GenericTypeCount = 1,
+ ReturnType = typeof(global::System.Threading.Tasks.Task),
+ ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(object))
+ {
+ Name = "value",
+ TypeReference = global::TUnit.Core.TypeReference.CreateGenericParameter(0, true, "T"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[0]!
+ },
+ new global::TUnit.Core.ParameterMetadata(typeof(string))
+ {
+ Name = "expected",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("string, System.Private.CoreLib"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]!
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () =>
+ {
+ var classMetadata = new global::TUnit.Core.ClassMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "Tests",
+ Namespace = "TUnit.TestProject.Bugs._2136",
+ Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
+ Parameters = global::System.Array.Empty(),
+ Properties = global::System.Array.Empty(),
+ Parent = null
+ };
+ // Set ClassMetadata and ContainingTypeMetadata references on properties to avoid circular dependency
+ foreach (var prop in classMetadata.Properties)
+ {
+ prop.ClassMetadata = classMetadata;
+ prop.ContainingTypeMetadata = classMetadata;
+ }
+ return classMetadata;
+ })
+ },
+ InstanceFactory = (typeArgs, args) =>
+ {
+ return new global::TUnit.TestProject.Bugs._2136.Tests();
+ },
+ InvokeTypedTest = async (instance, args, cancellationToken) =>
+ {
+ var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance;
+ await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((int)args[0]!, (string)args[1]!));
+ }
+ }
+ ,
+ [(typeof(double).FullName ?? typeof(double).Name)] =
+ new global::TUnit.Core.TestMetadata
+ {
+ TestName = "GenericArgumentsTest",
+ TestClassType = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TestMethodName = "GenericArgumentsTest",
+ GenericMethodTypeArguments = new global::System.Type[] { typeof(double)},
+ Dependencies = global::System.Array.Empty(),
+ AttributeFactory = () =>
+ [
+ new global::TUnit.Core.TestAttribute(),
+ new global::TUnit.Core.ArgumentsAttribute(1.1, "1.1"),
+ new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
+ ],
+ DataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ new global::TUnit.Core.ArgumentsAttribute(1.1, "1.1"),
+ },
+ ClassDataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ },
+ PropertyDataSources = global::System.Array.Empty(),
+ PropertyInjections = new global::TUnit.Core.PropertyInjectionData[]
+ {
+ },
+ FilePath = @"",
+ LineNumber = 8,
+ InheritanceDepth = 0,
+ TestSessionId = testSessionId,
+ MethodMetadata = new global::TUnit.Core.MethodMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "GenericArgumentsTest",
+ GenericTypeCount = 1,
+ ReturnType = typeof(global::System.Threading.Tasks.Task),
+ ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(object))
+ {
+ Name = "value",
+ TypeReference = global::TUnit.Core.TypeReference.CreateGenericParameter(0, true, "T"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[0]!
+ },
+ new global::TUnit.Core.ParameterMetadata(typeof(string))
+ {
+ Name = "expected",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("string, System.Private.CoreLib"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]!
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () =>
+ {
+ var classMetadata = new global::TUnit.Core.ClassMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "Tests",
+ Namespace = "TUnit.TestProject.Bugs._2136",
+ Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
+ Parameters = global::System.Array.Empty(),
+ Properties = global::System.Array.Empty(),
+ Parent = null
+ };
+ // Set ClassMetadata and ContainingTypeMetadata references on properties to avoid circular dependency
+ foreach (var prop in classMetadata.Properties)
+ {
+ prop.ClassMetadata = classMetadata;
+ prop.ContainingTypeMetadata = classMetadata;
+ }
+ return classMetadata;
+ })
+ },
+ InstanceFactory = (typeArgs, args) =>
+ {
+ return new global::TUnit.TestProject.Bugs._2136.Tests();
+ },
+ InvokeTypedTest = async (instance, args, cancellationToken) =>
+ {
+ var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance;
+ await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((double)args[0]!, (string)args[1]!));
+ }
+ }
+ ,
+ [(typeof(string).FullName ?? typeof(string).Name)] =
+ new global::TUnit.Core.TestMetadata
+ {
+ TestName = "GenericArgumentsTest",
+ TestClassType = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TestMethodName = "GenericArgumentsTest",
+ GenericMethodTypeArguments = new global::System.Type[] { typeof(string)},
+ Dependencies = global::System.Array.Empty(),
+ AttributeFactory = () =>
+ [
+ new global::TUnit.Core.TestAttribute(),
+ new global::TUnit.Core.ArgumentsAttribute("hello", "hello"),
+ new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
+ ],
+ DataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ new global::TUnit.Core.ArgumentsAttribute("hello", "hello"),
+ },
+ ClassDataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ },
+ PropertyDataSources = global::System.Array.Empty(),
+ PropertyInjections = new global::TUnit.Core.PropertyInjectionData[]
+ {
+ },
+ FilePath = @"",
+ LineNumber = 8,
+ InheritanceDepth = 0,
+ TestSessionId = testSessionId,
+ MethodMetadata = new global::TUnit.Core.MethodMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "GenericArgumentsTest",
+ GenericTypeCount = 1,
+ ReturnType = typeof(global::System.Threading.Tasks.Task),
+ ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(object))
+ {
+ Name = "value",
+ TypeReference = global::TUnit.Core.TypeReference.CreateGenericParameter(0, true, "T"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[0]!
+ },
+ new global::TUnit.Core.ParameterMetadata(typeof(string))
+ {
+ Name = "expected",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("string, System.Private.CoreLib"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]!
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () =>
+ {
+ var classMetadata = new global::TUnit.Core.ClassMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "Tests",
+ Namespace = "TUnit.TestProject.Bugs._2136",
+ Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
+ Parameters = global::System.Array.Empty(),
+ Properties = global::System.Array.Empty(),
+ Parent = null
+ };
+ // Set ClassMetadata and ContainingTypeMetadata references on properties to avoid circular dependency
+ foreach (var prop in classMetadata.Properties)
+ {
+ prop.ClassMetadata = classMetadata;
+ prop.ContainingTypeMetadata = classMetadata;
+ }
+ return classMetadata;
+ })
+ },
+ InstanceFactory = (typeArgs, args) =>
+ {
+ return new global::TUnit.TestProject.Bugs._2136.Tests();
+ },
+ InvokeTypedTest = async (instance, args, cancellationToken) =>
+ {
+ var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance;
+ await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((string)args[0]!, (string)args[1]!));
+ }
+ }
+ ,
+ [(typeof(global::TUnit.TestProject.Bugs._2136.MyEnum).FullName ?? typeof(global::TUnit.TestProject.Bugs._2136.MyEnum).Name)] =
+ new global::TUnit.Core.TestMetadata
+ {
+ TestName = "GenericArgumentsTest",
+ TestClassType = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TestMethodName = "GenericArgumentsTest",
+ GenericMethodTypeArguments = new global::System.Type[] { typeof(global::TUnit.TestProject.Bugs._2136.MyEnum)},
+ Dependencies = global::System.Array.Empty(),
+ AttributeFactory = () =>
+ [
+ new global::TUnit.Core.TestAttribute(),
+ new global::TUnit.Core.ArgumentsAttribute(global::TUnit.TestProject.Bugs._2136.MyEnum.Item, "Item"),
+ new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
+ ],
+ DataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ new global::TUnit.Core.ArgumentsAttribute(global::TUnit.TestProject.Bugs._2136.MyEnum.Item, "Item"),
+ },
+ ClassDataSources = new global::TUnit.Core.IDataSourceAttribute[]
+ {
+ },
+ PropertyDataSources = global::System.Array.Empty(),
+ PropertyInjections = new global::TUnit.Core.PropertyInjectionData[]
+ {
+ },
+ FilePath = @"",
+ LineNumber = 8,
+ InheritanceDepth = 0,
+ TestSessionId = testSessionId,
+ MethodMetadata = new global::TUnit.Core.MethodMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "GenericArgumentsTest",
+ GenericTypeCount = 1,
+ ReturnType = typeof(global::System.Threading.Tasks.Task),
+ ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(object))
+ {
+ Name = "value",
+ TypeReference = global::TUnit.Core.TypeReference.CreateGenericParameter(0, true, "T"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[0]!
+ },
+ new global::TUnit.Core.ParameterMetadata(typeof(string))
+ {
+ Name = "expected",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("string, System.Private.CoreLib"),
+ IsNullable = false,
+ ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]!
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () =>
+ {
+ var classMetadata = new global::TUnit.Core.ClassMetadata
+ {
+ Type = typeof(global::TUnit.TestProject.Bugs._2136.Tests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.Bugs._2136.Tests, TestsBase`1"),
+ Name = "Tests",
+ Namespace = "TUnit.TestProject.Bugs._2136",
+ Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
+ Parameters = global::System.Array.Empty(),
+ Properties = global::System.Array.Empty(),
+ Parent = null
+ };
+ // Set ClassMetadata and ContainingTypeMetadata references on properties to avoid circular dependency
+ foreach (var prop in classMetadata.Properties)
+ {
+ prop.ClassMetadata = classMetadata;
+ prop.ContainingTypeMetadata = classMetadata;
+ }
+ return classMetadata;
+ })
+ },
+ InstanceFactory = (typeArgs, args) =>
+ {
+ return new global::TUnit.TestProject.Bugs._2136.Tests();
+ },
+ InvokeTypedTest = async (instance, args, cancellationToken) =>
+ {
+ var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance;
+ await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((global::TUnit.TestProject.Bugs._2136.MyEnum)args[0]!, (string)args[1]!));
+ }
+ }
+ ,
+ }
+ };
+ genericMetadata.TestSessionId = testSessionId;
+ yield return genericMetadata;
+ yield break;
+ }
+}
+internal static class Tests_GenericArgumentsTest_ModuleInitializer_GUID
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.SourceRegistrar.Register(typeof(global::TUnit.TestProject.Bugs._2136.Tests), new Tests_GenericArgumentsTest_TestSource_GUID());
+ }
+}
diff --git a/TUnit.Core.SourceGenerator.Tests/AbstractTests.AbstractClass.verified.txt b/TUnit.Core.SourceGenerator.Tests/AbstractTests.AbstractClass.verified.txt
index e69de29bb2..5f282702bb 100644
--- a/TUnit.Core.SourceGenerator.Tests/AbstractTests.AbstractClass.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/AbstractTests.AbstractClass.verified.txt
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt
index 702915cc67..7075b7be5b 100644
--- a/TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt
@@ -15,32 +15,22 @@ using global::TUnit.Core.Hooks;
using global::TUnit.Core.Interfaces.SourceGenerator;
using global::TUnit.Core.Models;
using HookType = global::TUnit.Core.HookType;
-namespace TUnit.Generated.Hooks;
-public sealed class GeneratedHookRegistry
+namespace TUnit.Generated.Hooks.AssemblyBase1_AfterAll1_After_Assembly_GUID;
+internal static class AssemblyBase1_AfterAll1_After_Assembly_GUIDInitializer
{
- static GeneratedHookRegistry()
- {
- try
- {
- PopulateSourcesDictionaries();
- }
- catch (Exception ex)
- {
- throw new global::System.InvalidOperationException($"Failed to initialize hook registry: {ex.Message}", ex);
- }
- }
- private static void PopulateSourcesDictionaries()
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
{
- global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1), _ => new global::System.Collections.Concurrent.ConcurrentBag());
- global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1)].Add(
- new InstanceHookMethod
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1).Assembly;
+ global::TUnit.Core.Sources.AfterAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
+ new AfterAssemblyHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase1, TestsBase`1"),
- Name = "AfterEach1",
+ Name = "AfterAll1",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
@@ -69,31 +59,66 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyBase1_AfterEach1_0Params_Body
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
+ Body = global_TUnit_TestProject_AfterTests_AssemblyBase1_AfterAll1_0Params_Body,
+ FilePath = @"",
+ LineNumber = 5
}
);
- global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2), _ => new global::System.Collections.Concurrent.ConcurrentBag());
- global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2)].Add(
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase1_AfterAll1_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyBase1.AfterAll1());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase1_AfterEach1_After_Test_GUID;
+internal static class AssemblyBase1_AfterEach1_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1)].Add(
new InstanceHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
+ InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase2, TestsBase`1"),
- Name = "AfterEach2",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase1, TestsBase`1"),
+ Name = "AfterEach1",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase2", () =>
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase1", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase2, TestsBase`1"),
- Name = "AssemblyBase2",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase1, TestsBase`1"),
+ Name = "AssemblyBase1",
Namespace = "TUnit.TestProject.AfterTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -112,30 +137,64 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyBase2_AfterEach2_0Params_Body
+ Body = global_TUnit_TestProject_AfterTests_AssemblyBase1_AfterEach1_0Params_Body
}
);
- global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3), _ => new global::System.Collections.Concurrent.ConcurrentBag());
- global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3)].Add(
- new InstanceHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase1_AfterEach1_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyBase1)instance;
+ await AsyncConvert.Convert(() => typedInstance.AfterEach1());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase2_AfterAll2_After_Assembly_GUID;
+internal static class AssemblyBase2_AfterAll2_After_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2).Assembly;
+ global::TUnit.Core.Sources.AfterAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
+ new AfterAssemblyHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase3, TestsBase`1"),
- Name = "AfterEach3",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase2, TestsBase`1"),
+ Name = "AfterAll2",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase3", () =>
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase2", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase3, TestsBase`1"),
- Name = "AssemblyBase3",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase2, TestsBase`1"),
+ Name = "AssemblyBase2",
Namespace = "TUnit.TestProject.AfterTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -153,31 +212,66 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyBase3_AfterEach3_0Params_Body
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
+ Body = global_TUnit_TestProject_AfterTests_AssemblyBase2_AfterAll2_0Params_Body,
+ FilePath = @"",
+ LineNumber = 20
}
);
- global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
- global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase2_AfterAll2_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyBase2.AfterAll2());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase2_AfterEach2_After_Test_GUID;
+internal static class AssemblyBase2_AfterEach2_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2)].Add(
new InstanceHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
+ InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "Cleanup",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase2, TestsBase`1"),
+ Name = "AfterEach2",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase2", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "AssemblyCleanupTests",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase2, TestsBase`1"),
+ Name = "AssemblyBase2",
Namespace = "TUnit.TestProject.AfterTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -196,38 +290,64 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_0Params_Body
+ Body = global_TUnit_TestProject_AfterTests_AssemblyBase2_AfterEach2_0Params_Body
}
);
- global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
- new InstanceHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase2_AfterEach2_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyBase2)instance;
+ await AsyncConvert.Convert(() => typedInstance.AfterEach2());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase3_AfterAll3_After_Assembly_GUID;
+internal static class AssemblyBase3_AfterAll3_After_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3).Assembly;
+ global::TUnit.Core.Sources.AfterAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
+ new AfterAssemblyHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "Cleanup",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase3, TestsBase`1"),
+ Name = "AfterAll3",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = new global::TUnit.Core.ParameterMetadata[]
- {
- new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
- {
- Name = "cancellationToken",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
- IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("Cleanup", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
- }
- },
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
+ Parameters = global::System.Array.Empty(),
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase3", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "AssemblyCleanupTests",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase3, TestsBase`1"),
+ Name = "AssemblyBase3",
Namespace = "TUnit.TestProject.AfterTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -245,39 +365,66 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_1Params_Body
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
+ Body = global_TUnit_TestProject_AfterTests_AssemblyBase3_AfterAll3_0Params_Body,
+ FilePath = @"",
+ LineNumber = 35
}
);
- global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase3_AfterAll3_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyBase3.AfterAll3());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase3_AfterEach3_After_Test_GUID;
+internal static class AssemblyBase3_AfterEach3_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3)].Add(
new InstanceHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
+ InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "CleanupWithContext",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase3, TestsBase`1"),
+ Name = "AfterEach3",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = new global::TUnit.Core.ParameterMetadata[]
- {
- new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.TestContext))
- {
- Name = "testContext",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.TestContext, TUnit.Core"),
- IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("CleanupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0]
- }
- },
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
+ Parameters = global::System.Array.Empty(),
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase3", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "AssemblyCleanupTests",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase3, TestsBase`1"),
+ Name = "AssemblyBase3",
Namespace = "TUnit.TestProject.AfterTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -296,38 +443,57 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupWithContext_1Params_Body
+ Body = global_TUnit_TestProject_AfterTests_AssemblyBase3_AfterEach3_0Params_Body
}
);
- global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
- new InstanceHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase3_AfterEach3_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyBase3)instance;
+ await AsyncConvert.Convert(() => typedInstance.AfterEach3());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyCleanupTests_AfterAllCleanUp_After_Assembly_GUID;
+internal static class AssemblyCleanupTests_AfterAllCleanUp_After_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).Assembly;
+ global::TUnit.Core.Sources.AfterAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
+ new AfterAssemblyHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "CleanupWithContext",
+ Name = "AfterAllCleanUp",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = new global::TUnit.Core.ParameterMetadata[]
- {
- new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.TestContext))
- {
- Name = "testContext",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.TestContext, TUnit.Core"),
- IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("CleanupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
- },
- new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
- {
- Name = "cancellationToken",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
- IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("CleanupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1]
- }
- },
+ Parameters = global::System.Array.Empty(),
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
@@ -352,31 +518,75 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupWithContext_2Params_Body
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
+ Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUp_0Params_Body,
+ FilePath = @"",
+ LineNumber = 50
}
);
- var TestsBase`1_assembly = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1).Assembly;
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUp_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyCleanupTests.AfterAllCleanUp());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyCleanupTests_AfterAllCleanUpWithContext_After_Assembly_GUID;
+internal static class AssemblyCleanupTests_AfterAllCleanUpWithContext_After_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).Assembly;
global::TUnit.Core.Sources.AfterAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
new AfterAssemblyHookMethod
{
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase1, TestsBase`1"),
- Name = "AfterAll1",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
+ Name = "AfterAllCleanUpWithContext",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase1", () =>
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.AssemblyHookContext))
+ {
+ Name = "context",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.AssemblyHookContext, TUnit.Core"),
+ IsNullable = false,
+ ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("AfterAllCleanUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext) }, null)!.GetParameters()[0]
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase1, TestsBase`1"),
- Name = "AssemblyBase1",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
+ Name = "AssemblyCleanupTests",
Namespace = "TUnit.TestProject.AfterTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -395,30 +605,65 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyBase1_AfterAll1_0Params_Body,
+ Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUpWithContext_1Params_Body,
FilePath = @"",
- LineNumber = 5
+ LineNumber = 56
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUpWithContext_1Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyCleanupTests.AfterAllCleanUpWithContext(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyCleanupTests_AfterAllCleanUp2_After_Assembly_GUID;
+internal static class AssemblyCleanupTests_AfterAllCleanUp2_After_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).Assembly;
+ global::TUnit.Core.Sources.AfterAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
new AfterAssemblyHookMethod
{
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase2, TestsBase`1"),
- Name = "AfterAll2",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
+ Name = "AfterAllCleanUp2",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase2", () =>
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase2, TestsBase`1"),
- Name = "AssemblyBase2",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
+ Name = "AssemblyCleanupTests",
Namespace = "TUnit.TestProject.AfterTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -437,30 +682,81 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyBase2_AfterAll2_0Params_Body,
+ Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUp2_0Params_Body,
FilePath = @"",
- LineNumber = 20
+ LineNumber = 62
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUp2_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyCleanupTests.AfterAllCleanUp2());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyCleanupTests_AfterAllCleanUpWithContextAndToken_After_Assembly_GUID;
+internal static class AssemblyCleanupTests_AfterAllCleanUpWithContextAndToken_After_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).Assembly;
+ global::TUnit.Core.Sources.AfterAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
new AfterAssemblyHookMethod
{
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase3, TestsBase`1"),
- Name = "AfterAll3",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
+ Name = "AfterAllCleanUpWithContextAndToken",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase3", () =>
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.AssemblyHookContext))
+ {
+ Name = "context",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.AssemblyHookContext, TUnit.Core"),
+ IsNullable = false,
+ ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("AfterAllCleanUpWithContextAndToken", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
+ },
+ new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
+ {
+ Name = "cancellationToken",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
+ IsNullable = false,
+ ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("AfterAllCleanUpWithContextAndToken", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1]
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyBase3, TestsBase`1"),
- Name = "AssemblyBase3",
+ Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
+ Name = "AssemblyCleanupTests",
Namespace = "TUnit.TestProject.AfterTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -479,19 +775,54 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyBase3_AfterAll3_0Params_Body,
+ Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUpWithContextAndToken_2Params_Body,
FilePath = @"",
- LineNumber = 35
+ LineNumber = 68
}
);
- global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
- new AfterAssemblyHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUpWithContextAndToken_2Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyCleanupTests.AfterAllCleanUpWithContextAndToken(context, cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyCleanupTests_Cleanup_After_Test_GUID;
+internal static class AssemblyCleanupTests_Cleanup_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
+ new InstanceHookMethod
{
+ InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "AfterAllCleanUp",
+ Name = "Cleanup",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
@@ -520,31 +851,65 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUp_0Params_Body,
- FilePath = @"",
- LineNumber = 50
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
+ Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_0Params_Body
}
);
- global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
- new AfterAssemblyHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.Cleanup());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyCleanupTests_Cleanup_After_Test_GUID;
+internal static class AssemblyCleanupTests_Cleanup_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
+ new InstanceHookMethod
{
+ InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "AfterAllCleanUpWithContext",
+ Name = "Cleanup",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = new global::TUnit.Core.ParameterMetadata[]
{
- new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.AssemblyHookContext))
+ new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
{
- Name = "context",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.AssemblyHookContext, TUnit.Core"),
+ Name = "cancellationToken",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("AfterAllCleanUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext) }, null)!.GetParameters()[0]
+ ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("Cleanup", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
}
},
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
@@ -571,24 +936,67 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUpWithContext_1Params_Body,
- FilePath = @"",
- LineNumber = 56
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
+ Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_1Params_Body
}
);
- global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
- new AfterAssemblyHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.Cleanup(cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyCleanupTests_CleanupWithContext_After_Test_GUID;
+internal static class AssemblyCleanupTests_CleanupWithContext_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
+ new InstanceHookMethod
{
+ InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "AfterAllCleanUp2",
+ Name = "CleanupWithContext",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = global::System.Array.Empty(),
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.TestContext))
+ {
+ Name = "testContext",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.TestContext, TUnit.Core"),
+ IsNullable = false,
+ ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("CleanupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0]
+ }
+ },
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
@@ -613,38 +1021,72 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUp2_0Params_Body,
- FilePath = @"",
- LineNumber = 62
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
+ Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupWithContext_1Params_Body
}
);
- global::TUnit.Core.Sources.AfterAssemblyHooks[TestsBase`1_assembly].Add(
- new AfterAssemblyHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupWithContext_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.CleanupWithContext(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyCleanupTests_CleanupWithContext_After_Test_GUID;
+internal static class AssemblyCleanupTests_CleanupWithContext_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
+ new InstanceHookMethod
{
+ InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.AfterTests.AssemblyCleanupTests, TestsBase`1"),
- Name = "AfterAllCleanUpWithContextAndToken",
+ Name = "CleanupWithContext",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = new global::TUnit.Core.ParameterMetadata[]
{
- new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.AssemblyHookContext))
+ new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.TestContext))
{
- Name = "context",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.AssemblyHookContext, TUnit.Core"),
+ Name = "testContext",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.TestContext, TUnit.Core"),
IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("AfterAllCleanUpWithContextAndToken", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
+ ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("CleanupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
},
new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
{
Name = "cancellationToken",
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("AfterAllCleanUpWithContextAndToken", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1]
+ ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("CleanupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1]
}
},
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () =>
@@ -671,82 +1113,14 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterAssemblyHookIndex(),
- Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUpWithContextAndToken_2Params_Body,
- FilePath = @"",
- LineNumber = 68
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextAfterTestHookIndex(),
+ Body = global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupWithContext_2Params_Body
}
);
}
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase1_AfterAll1_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyBase1.AfterAll1());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase1_AfterEach1_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyBase1)instance;
- await AsyncConvert.Convert(() => typedInstance.AfterEach1());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase2_AfterAll2_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyBase2.AfterAll2());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase2_AfterEach2_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyBase2)instance;
- await AsyncConvert.Convert(() => typedInstance.AfterEach2());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase3_AfterAll3_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyBase3.AfterAll3());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyBase3_AfterEach3_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyBase3)instance;
- await AsyncConvert.Convert(() => typedInstance.AfterEach3());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUp_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyCleanupTests.AfterAllCleanUp());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUpWithContext_1Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyCleanupTests.AfterAllCleanUpWithContext(context));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUp2_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyCleanupTests.AfterAllCleanUp2());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAllCleanUpWithContextAndToken_2Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.AssemblyCleanupTests.AfterAllCleanUpWithContextAndToken(context, cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)instance;
- await AsyncConvert.Convert(() => typedInstance.Cleanup());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)instance;
- await AsyncConvert.Convert(() => typedInstance.Cleanup(cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupWithContext_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)instance;
- await AsyncConvert.Convert(() => typedInstance.CleanupWithContext(context));
- }
private static async ValueTask global_TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupWithContext_2Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
{
var typedInstance = (global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)instance;
await AsyncConvert.Convert(() => typedInstance.CleanupWithContext(context, cancellationToken));
}
}
-internal static class HookModuleInitializer
-{
- [global::System.Runtime.CompilerServices.ModuleInitializer]
- public static void Initialize()
- {
- _ = new GeneratedHookRegistry();
- }
-}
diff --git a/TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt
index ae811b9000..75dbf482c1 100644
--- a/TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt
@@ -15,32 +15,22 @@ using global::TUnit.Core.Hooks;
using global::TUnit.Core.Interfaces.SourceGenerator;
using global::TUnit.Core.Models;
using HookType = global::TUnit.Core.HookType;
-namespace TUnit.Generated.Hooks;
-public sealed class GeneratedHookRegistry
+namespace TUnit.Generated.Hooks.AssemblyBase1_BeforeAll1_Before_Assembly_GUID;
+internal static class AssemblyBase1_BeforeAll1_Before_Assembly_GUIDInitializer
{
- static GeneratedHookRegistry()
- {
- try
- {
- PopulateSourcesDictionaries();
- }
- catch (Exception ex)
- {
- throw new global::System.InvalidOperationException($"Failed to initialize hook registry: {ex.Message}", ex);
- }
- }
- private static void PopulateSourcesDictionaries()
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
{
- global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1), _ => new global::System.Collections.Concurrent.ConcurrentBag());
- global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1)].Add(
- new InstanceHookMethod
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1).Assembly;
+ global::TUnit.Core.Sources.BeforeAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
+ new BeforeAssemblyHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase1, TestsBase`1"),
- Name = "BeforeEach1",
+ Name = "BeforeAll1",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
@@ -69,31 +59,66 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeEach1_0Params_Body
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
+ Body = global_TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeAll1_0Params_Body,
+ FilePath = @"",
+ LineNumber = 5
}
);
- global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2), _ => new global::System.Collections.Concurrent.ConcurrentBag());
- global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2)].Add(
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeAll1_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblyBase1.BeforeAll1());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase1_BeforeEach1_Before_Test_GUID;
+internal static class AssemblyBase1_BeforeEach1_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1)].Add(
new InstanceHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
+ InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase2, TestsBase`1"),
- Name = "BeforeEach2",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase1, TestsBase`1"),
+ Name = "BeforeEach1",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase2", () =>
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase1", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase2, TestsBase`1"),
- Name = "AssemblyBase2",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase1, TestsBase`1"),
+ Name = "AssemblyBase1",
Namespace = "TUnit.TestProject.BeforeTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -112,30 +137,64 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeEach2_0Params_Body
+ Body = global_TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeEach1_0Params_Body
}
);
- global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3), _ => new global::System.Collections.Concurrent.ConcurrentBag());
- global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3)].Add(
- new InstanceHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeEach1_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblyBase1)instance;
+ await AsyncConvert.Convert(() => typedInstance.BeforeEach1());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase2_BeforeAll2_Before_Assembly_GUID;
+internal static class AssemblyBase2_BeforeAll2_Before_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2).Assembly;
+ global::TUnit.Core.Sources.BeforeAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
+ new BeforeAssemblyHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase3, TestsBase`1"),
- Name = "BeforeEach3",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase2, TestsBase`1"),
+ Name = "BeforeAll2",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase3", () =>
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase2", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase3, TestsBase`1"),
- Name = "AssemblyBase3",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase2, TestsBase`1"),
+ Name = "AssemblyBase2",
Namespace = "TUnit.TestProject.BeforeTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -153,31 +212,66 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeEach3_0Params_Body
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
+ Body = global_TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeAll2_0Params_Body,
+ FilePath = @"",
+ LineNumber = 20
}
);
- global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
- global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeAll2_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblyBase2.BeforeAll2());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase2_BeforeEach2_Before_Test_GUID;
+internal static class AssemblyBase2_BeforeEach2_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2)].Add(
new InstanceHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
+ InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "Setup",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase2, TestsBase`1"),
+ Name = "BeforeEach2",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase2", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "AssemblySetupTests",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase2, TestsBase`1"),
+ Name = "AssemblyBase2",
Namespace = "TUnit.TestProject.BeforeTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -196,38 +290,64 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_0Params_Body
+ Body = global_TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeEach2_0Params_Body
}
);
- global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
- new InstanceHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeEach2_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblyBase2)instance;
+ await AsyncConvert.Convert(() => typedInstance.BeforeEach2());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase3_BeforeAll3_Before_Assembly_GUID;
+internal static class AssemblyBase3_BeforeAll3_Before_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3).Assembly;
+ global::TUnit.Core.Sources.BeforeAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
+ new BeforeAssemblyHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "Setup",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase3, TestsBase`1"),
+ Name = "BeforeAll3",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = new global::TUnit.Core.ParameterMetadata[]
- {
- new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
- {
- Name = "cancellationToken",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
- IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("Setup", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
- }
- },
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
+ Parameters = global::System.Array.Empty(),
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase3", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "AssemblySetupTests",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase3, TestsBase`1"),
+ Name = "AssemblyBase3",
Namespace = "TUnit.TestProject.BeforeTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -245,39 +365,66 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_1Params_Body
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
+ Body = global_TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeAll3_0Params_Body,
+ FilePath = @"",
+ LineNumber = 35
}
);
- global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeAll3_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblyBase3.BeforeAll3());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblyBase3_BeforeEach3_Before_Test_GUID;
+internal static class AssemblyBase3_BeforeEach3_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3)].Add(
new InstanceHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
+ InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "SetupWithContext",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase3, TestsBase`1"),
+ Name = "BeforeEach3",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = new global::TUnit.Core.ParameterMetadata[]
- {
- new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.TestContext))
- {
- Name = "testContext",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.TestContext, TUnit.Core"),
- IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("SetupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0]
- }
- },
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
+ Parameters = global::System.Array.Empty(),
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase3", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "AssemblySetupTests",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase3, TestsBase`1"),
+ Name = "AssemblyBase3",
Namespace = "TUnit.TestProject.BeforeTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -296,38 +443,57 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWithContext_1Params_Body
+ Body = global_TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeEach3_0Params_Body
}
);
- global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
- new InstanceHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeEach3_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblyBase3)instance;
+ await AsyncConvert.Convert(() => typedInstance.BeforeEach3());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblySetupTests_BeforeAllSetUp_Before_Assembly_GUID;
+internal static class AssemblySetupTests_BeforeAllSetUp_Before_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).Assembly;
+ global::TUnit.Core.Sources.BeforeAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
+ new BeforeAssemblyHookMethod
{
- InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "SetupWithContext",
+ Name = "BeforeAllSetUp",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = new global::TUnit.Core.ParameterMetadata[]
- {
- new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.TestContext))
- {
- Name = "testContext",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.TestContext, TUnit.Core"),
- IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("SetupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
- },
- new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
- {
- Name = "cancellationToken",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
- IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("SetupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1]
- }
- },
+ Parameters = global::System.Array.Empty(),
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
@@ -352,31 +518,75 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWithContext_2Params_Body
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
+ Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUp_0Params_Body,
+ FilePath = @"",
+ LineNumber = 50
}
);
- var TestsBase`1_assembly = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1).Assembly;
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUp_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblySetupTests.BeforeAllSetUp());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblySetupTests_BeforeAllSetUpWithContext_Before_Assembly_GUID;
+internal static class AssemblySetupTests_BeforeAllSetUpWithContext_Before_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).Assembly;
global::TUnit.Core.Sources.BeforeAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
new BeforeAssemblyHookMethod
{
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase1, TestsBase`1"),
- Name = "BeforeAll1",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
+ Name = "BeforeAllSetUpWithContext",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase1", () =>
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.AssemblyHookContext))
+ {
+ Name = "context",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.AssemblyHookContext, TUnit.Core"),
+ IsNullable = false,
+ ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext) }, null)!.GetParameters()[0]
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase1, TestsBase`1"),
- Name = "AssemblyBase1",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
+ Name = "AssemblySetupTests",
Namespace = "TUnit.TestProject.BeforeTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -395,30 +605,65 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeAll1_0Params_Body,
+ Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUpWithContext_1Params_Body,
FilePath = @"",
- LineNumber = 5
+ LineNumber = 56
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUpWithContext_1Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblySetupTests.BeforeAllSetUpWithContext(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblySetupTests_BeforeAllSetUp2_Before_Assembly_GUID;
+internal static class AssemblySetupTests_BeforeAllSetUp2_Before_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).Assembly;
+ global::TUnit.Core.Sources.BeforeAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
new BeforeAssemblyHookMethod
{
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase2, TestsBase`1"),
- Name = "BeforeAll2",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
+ Name = "BeforeAllSetUp2",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase2", () =>
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase2, TestsBase`1"),
- Name = "AssemblyBase2",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
+ Name = "AssemblySetupTests",
Namespace = "TUnit.TestProject.BeforeTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -437,30 +682,81 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeAll2_0Params_Body,
+ Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUp2_0Params_Body,
FilePath = @"",
- LineNumber = 20
+ LineNumber = 62
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUp2_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblySetupTests.BeforeAllSetUp2());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblySetupTests_BeforeAllSetUpWithContext_Before_Assembly_GUID;
+internal static class AssemblySetupTests_BeforeAllSetUpWithContext_Before_Assembly_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ var TestsBase`1_assembly = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).Assembly;
+ global::TUnit.Core.Sources.BeforeAssemblyHooks.GetOrAdd(TestsBase`1_assembly, _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
new BeforeAssemblyHookMethod
{
MethodInfo = new global::TUnit.Core.MethodMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase3, TestsBase`1"),
- Name = "BeforeAll3",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
+ Name = "BeforeAllSetUpWithContext",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = global::System.Array.Empty(),
- Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase3", () =>
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.AssemblyHookContext))
+ {
+ Name = "context",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.AssemblyHookContext, TUnit.Core"),
+ IsNullable = false,
+ ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
+ },
+ new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
+ {
+ Name = "cancellationToken",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
+ IsNullable = false,
+ ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1]
+ }
+ },
+ Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
{
- Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblyBase3, TestsBase`1"),
- Name = "AssemblyBase3",
+ Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
+ Name = "AssemblySetupTests",
Namespace = "TUnit.TestProject.BeforeTests",
Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }),
Parameters = global::System.Array.Empty(),
@@ -479,19 +775,54 @@ public sealed class GeneratedHookRegistry
HookExecutor = DefaultExecutor.Instance,
Order = 0,
RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeAll3_0Params_Body,
+ Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUpWithContext_2Params_Body,
FilePath = @"",
- LineNumber = 35
+ LineNumber = 68
}
);
- global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
- new BeforeAssemblyHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUpWithContext_2Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblySetupTests.BeforeAllSetUpWithContext(context, cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblySetupTests_Setup_Before_Test_GUID;
+internal static class AssemblySetupTests_Setup_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
+ new InstanceHookMethod
{
+ InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "BeforeAllSetUp",
+ Name = "Setup",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
@@ -520,31 +851,65 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUp_0Params_Body,
- FilePath = @"",
- LineNumber = 50
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
+ Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_0Params_Body
}
);
- global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
- new BeforeAssemblyHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblySetupTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.Setup());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblySetupTests_Setup_Before_Test_GUID;
+internal static class AssemblySetupTests_Setup_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
+ new InstanceHookMethod
{
+ InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "BeforeAllSetUpWithContext",
+ Name = "Setup",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = new global::TUnit.Core.ParameterMetadata[]
{
- new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.AssemblyHookContext))
+ new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
{
- Name = "context",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.AssemblyHookContext, TUnit.Core"),
+ Name = "cancellationToken",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext) }, null)!.GetParameters()[0]
+ ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("Setup", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
}
},
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
@@ -571,24 +936,67 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUpWithContext_1Params_Body,
- FilePath = @"",
- LineNumber = 56
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
+ Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_1Params_Body
}
);
- global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
- new BeforeAssemblyHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblySetupTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.Setup(cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblySetupTests_SetupWithContext_Before_Test_GUID;
+internal static class AssemblySetupTests_SetupWithContext_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
+ new InstanceHookMethod
{
+ InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "BeforeAllSetUp2",
+ Name = "SetupWithContext",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
- Parameters = global::System.Array.Empty(),
+ Parameters = new global::TUnit.Core.ParameterMetadata[]
+ {
+ new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.TestContext))
+ {
+ Name = "testContext",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.TestContext, TUnit.Core"),
+ IsNullable = false,
+ ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("SetupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0]
+ }
+ },
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
{
var classMetadata = new global::TUnit.Core.ClassMetadata
@@ -613,38 +1021,72 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUp2_0Params_Body,
- FilePath = @"",
- LineNumber = 62
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
+ Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWithContext_1Params_Body
}
);
- global::TUnit.Core.Sources.BeforeAssemblyHooks[TestsBase`1_assembly].Add(
- new BeforeAssemblyHookMethod
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWithContext_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblySetupTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.SetupWithContext(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.AssemblySetupTests_SetupWithContext_Before_Test_GUID;
+internal static class AssemblySetupTests_SetupWithContext_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
+ global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
+ new InstanceHookMethod
{
+ InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.TestProject.BeforeTests.AssemblySetupTests, TestsBase`1"),
- Name = "BeforeAllSetUpWithContext",
+ Name = "SetupWithContext",
GenericTypeCount = 0,
ReturnType = typeof(global::System.Threading.Tasks.Task),
ReturnTypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.Tasks.Task, System.Private.CoreLib"),
Parameters = new global::TUnit.Core.ParameterMetadata[]
{
- new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.AssemblyHookContext))
+ new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.Core.TestContext))
{
- Name = "context",
- TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.AssemblyHookContext, TUnit.Core"),
+ Name = "testContext",
+ TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("TUnit.Core.TestContext, TUnit.Core"),
IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
+ ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("SetupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0]
},
new global::TUnit.Core.ParameterMetadata(typeof(global::System.Threading.CancellationToken))
{
Name = "cancellationToken",
TypeReference = global::TUnit.Core.TypeReference.CreateConcrete("System.Threading.CancellationToken, System.Private.CoreLib"),
IsNullable = false,
- ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1]
+ ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("SetupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1]
}
},
Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () =>
@@ -671,82 +1113,14 @@ public sealed class GeneratedHookRegistry
},
HookExecutor = DefaultExecutor.Instance,
Order = 0,
- RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeAssemblyHookIndex(),
- Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUpWithContext_2Params_Body,
- FilePath = @"",
- LineNumber = 68
+ RegistrationIndex = global::TUnit.Core.HookRegistrationIndices.GetNextBeforeTestHookIndex(),
+ Body = global_TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWithContext_2Params_Body
}
);
}
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeAll1_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblyBase1.BeforeAll1());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeEach1_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblyBase1)instance;
- await AsyncConvert.Convert(() => typedInstance.BeforeEach1());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeAll2_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblyBase2.BeforeAll2());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeEach2_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblyBase2)instance;
- await AsyncConvert.Convert(() => typedInstance.BeforeEach2());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeAll3_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblyBase3.BeforeAll3());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeEach3_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblyBase3)instance;
- await AsyncConvert.Convert(() => typedInstance.BeforeEach3());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUp_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblySetupTests.BeforeAllSetUp());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUpWithContext_1Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblySetupTests.BeforeAllSetUpWithContext(context));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUp2_0Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblySetupTests.BeforeAllSetUp2());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAllSetUpWithContext_2Params_Body(AssemblyHookContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.AssemblySetupTests.BeforeAllSetUpWithContext(context, cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblySetupTests)instance;
- await AsyncConvert.Convert(() => typedInstance.Setup());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblySetupTests)instance;
- await AsyncConvert.Convert(() => typedInstance.Setup(cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWithContext_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblySetupTests)instance;
- await AsyncConvert.Convert(() => typedInstance.SetupWithContext(context));
- }
private static async ValueTask global_TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWithContext_2Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
{
var typedInstance = (global::TUnit.TestProject.BeforeTests.AssemblySetupTests)instance;
await AsyncConvert.Convert(() => typedInstance.SetupWithContext(context, cancellationToken));
}
}
-internal static class HookModuleInitializer
-{
- [global::System.Runtime.CompilerServices.ModuleInitializer]
- public static void Initialize()
- {
- _ = new GeneratedHookRegistry();
- }
-}
diff --git a/TUnit.Core.SourceGenerator.Tests/Basic.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Basic.Test.verified.txt
index e69de29bb2..5f282702bb 100644
--- a/TUnit.Core.SourceGenerator.Tests/Basic.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/Basic.Test.verified.txt
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt
index 19952834c4..f9d74b8f96 100644
--- a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt
@@ -1,4 +1,4 @@
-//
+//
#pragma warning disable
//
diff --git a/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt
index 7817b4d74a..86217ccbbe 100644
--- a/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt
@@ -1,4 +1,4 @@
-//
+//
#pragma warning disable
//
diff --git a/TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt
index 409059734d..205cdf1d37 100644
--- a/TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt
@@ -15,21 +15,11 @@ using global::TUnit.Core.Hooks;
using global::TUnit.Core.Interfaces.SourceGenerator;
using global::TUnit.Core.Models;
using HookType = global::TUnit.Core.HookType;
-namespace TUnit.Generated.Hooks;
-public sealed class GeneratedHookRegistry
+namespace TUnit.Generated.Hooks.GlobalBase1_AfterEach1_After_Test_GUID;
+internal static class GlobalBase1_AfterEach1_After_Test_GUIDInitializer
{
- static GeneratedHookRegistry()
- {
- try
- {
- PopulateSourcesDictionaries();
- }
- catch (Exception ex)
- {
- throw new global::System.InvalidOperationException($"Failed to initialize hook registry: {ex.Message}", ex);
- }
- }
- private static void PopulateSourcesDictionaries()
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
{
global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.GlobalBase1), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase1)].Add(
@@ -73,6 +63,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_AfterTests_GlobalBase1_AfterEach1_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase1_AfterEach1_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalBase1)instance;
+ await AsyncConvert.Convert(() => typedInstance.AfterEach1());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase2_AfterEach2_After_Test_GUID;
+internal static class GlobalBase2_AfterEach2_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.GlobalBase2), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase2)].Add(
new InstanceHookMethod
@@ -115,6 +139,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_AfterTests_GlobalBase2_AfterEach2_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase2_AfterEach2_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalBase2)instance;
+ await AsyncConvert.Convert(() => typedInstance.AfterEach2());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase3_AfterEach3_After_Test_GUID;
+internal static class GlobalBase3_AfterEach3_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.GlobalBase3), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase3)].Add(
new InstanceHookMethod
@@ -157,6 +215,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_AfterTests_GlobalBase3_AfterEach3_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase3_AfterEach3_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalBase3)instance;
+ await AsyncConvert.Convert(() => typedInstance.AfterEach3());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalCleanUpTests_CleanUp_After_Test_GUID;
+internal static class GlobalCleanUpTests_CleanUp_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
new InstanceHookMethod
@@ -199,6 +291,41 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.CleanUp());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalCleanUpTests_CleanUp_After_Test_GUID;
+internal static class GlobalCleanUpTests_CleanUp_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
new InstanceHookMethod
{
@@ -249,6 +376,41 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp_1Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.CleanUp(cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalCleanUpTests_CleanUpWithContext_After_Test_GUID;
+internal static class GlobalCleanUpTests_CleanUpWithContext_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
new InstanceHookMethod
{
@@ -299,6 +461,41 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWithContext_1Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWithContext_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.CleanUpWithContext(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalCleanUpTests_CleanUpWithContext_After_Test_GUID;
+internal static class GlobalCleanUpTests_CleanUpWithContext_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
new InstanceHookMethod
{
@@ -356,6 +553,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWithContext_2Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWithContext_2Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.CleanUpWithContext(context, cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase1_AfterAll1_AfterEvery_Test_GUID;
+internal static class GlobalBase1_AfterAll1_AfterEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterEveryTestHooks.Add(
new AfterTestHookMethod
{
@@ -407,6 +638,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 5
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase1_AfterAll1_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalBase1.AfterAll1(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase2_AfterAll2_AfterEvery_Test_GUID;
+internal static class GlobalBase2_AfterAll2_AfterEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterEveryTestHooks.Add(
new AfterTestHookMethod
{
@@ -458,6 +722,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 20
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase2_AfterAll2_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalBase2.AfterAll2(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase3_AfterAll3_AfterEvery_Test_GUID;
+internal static class GlobalBase3_AfterAll3_AfterEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterEveryTestHooks.Add(
new AfterTestHookMethod
{
@@ -509,6 +806,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 35
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase3_AfterAll3_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalBase3.AfterAll3(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalCleanUpTests_AfterAllCleanUp_AfterEvery_Test_GUID;
+internal static class GlobalCleanUpTests_AfterAllCleanUp_AfterEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterEveryTestHooks.Add(
new AfterTestHookMethod
{
@@ -560,6 +890,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 50
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCleanUp_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalCleanUpTests.AfterAllCleanUp(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalCleanUpTests_AfterAllCleanUp_AfterEvery_Test_GUID;
+internal static class GlobalCleanUpTests_AfterAllCleanUp_AfterEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterEveryTestHooks.Add(
new AfterTestHookMethod
{
@@ -618,6 +981,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 56
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCleanUp_2Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalCleanUpTests.AfterAllCleanUp(context, cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalCleanUpTests_AfterAllCleanUpWithContext_AfterEvery_Test_GUID;
+internal static class GlobalCleanUpTests_AfterAllCleanUpWithContext_AfterEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterEveryTestHooks.Add(
new AfterTestHookMethod
{
@@ -669,6 +1065,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 62
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCleanUpWithContext_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalCleanUpTests.AfterAllCleanUpWithContext(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalCleanUpTests_AfterAllCleanUpWithContext_AfterEvery_Test_GUID;
+internal static class GlobalCleanUpTests_AfterAllCleanUpWithContext_AfterEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterEveryTestHooks.Add(
new AfterTestHookMethod
{
@@ -728,75 +1157,8 @@ public sealed class GeneratedHookRegistry
}
);
}
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase1_AfterEach1_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalBase1)instance;
- await AsyncConvert.Convert(() => typedInstance.AfterEach1());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase2_AfterEach2_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalBase2)instance;
- await AsyncConvert.Convert(() => typedInstance.AfterEach2());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase3_AfterEach3_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalBase3)instance;
- await AsyncConvert.Convert(() => typedInstance.AfterEach3());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)instance;
- await AsyncConvert.Convert(() => typedInstance.CleanUp());
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)instance;
- await AsyncConvert.Convert(() => typedInstance.CleanUp(cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWithContext_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)instance;
- await AsyncConvert.Convert(() => typedInstance.CleanUpWithContext(context));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWithContext_2Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)instance;
- await AsyncConvert.Convert(() => typedInstance.CleanUpWithContext(context, cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase1_AfterAll1_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalBase1.AfterAll1(context));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase2_AfterAll2_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalBase2.AfterAll2(context));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalBase3_AfterAll3_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalBase3.AfterAll3(context));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCleanUp_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalCleanUpTests.AfterAllCleanUp(context));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCleanUp_2Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalCleanUpTests.AfterAllCleanUp(context, cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCleanUpWithContext_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalCleanUpTests.AfterAllCleanUpWithContext(context));
- }
private static async ValueTask global_TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCleanUpWithContext_2Params_Body(TestContext context, CancellationToken cancellationToken)
{
await AsyncConvert.Convert(() => global::TUnit.TestProject.AfterTests.GlobalCleanUpTests.AfterAllCleanUpWithContext(context, cancellationToken));
}
}
-internal static class HookModuleInitializer
-{
- [global::System.Runtime.CompilerServices.ModuleInitializer]
- public static void Initialize()
- {
- _ = new GeneratedHookRegistry();
- }
-}
diff --git a/TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt
index 31100bb930..85cb6a8cab 100644
--- a/TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt
@@ -15,21 +15,11 @@ using global::TUnit.Core.Hooks;
using global::TUnit.Core.Interfaces.SourceGenerator;
using global::TUnit.Core.Models;
using HookType = global::TUnit.Core.HookType;
-namespace TUnit.Generated.Hooks;
-public sealed class GeneratedHookRegistry
+namespace TUnit.Generated.Hooks.GlobalBase1_BeforeEach1_Before_Test_GUID;
+internal static class GlobalBase1_BeforeEach1_Before_Test_GUIDInitializer
{
- static GeneratedHookRegistry()
- {
- try
- {
- PopulateSourcesDictionaries();
- }
- catch (Exception ex)
- {
- throw new global::System.InvalidOperationException($"Failed to initialize hook registry: {ex.Message}", ex);
- }
- }
- private static void PopulateSourcesDictionaries()
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
{
global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1)].Add(
@@ -73,6 +63,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_BeforeTests_GlobalBase1_BeforeEach1_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase1_BeforeEach1_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalBase1)instance;
+ await AsyncConvert.Convert(() => typedInstance.BeforeEach1());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase2_BeforeEach2_Before_Test_GUID;
+internal static class GlobalBase2_BeforeEach2_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2)].Add(
new InstanceHookMethod
@@ -115,6 +139,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_BeforeTests_GlobalBase2_BeforeEach2_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase2_BeforeEach2_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalBase2)instance;
+ await AsyncConvert.Convert(() => typedInstance.BeforeEach2());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase3_BeforeEach3_Before_Test_GUID;
+internal static class GlobalBase3_BeforeEach3_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3)].Add(
new InstanceHookMethod
@@ -157,6 +215,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_BeforeTests_GlobalBase3_BeforeEach3_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase3_BeforeEach3_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalBase3)instance;
+ await AsyncConvert.Convert(() => typedInstance.BeforeEach3());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalSetUpTests_SetUp_Before_Test_GUID;
+internal static class GlobalSetUpTests_SetUp_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
new InstanceHookMethod
@@ -199,6 +291,41 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.SetUp());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalSetUpTests_SetUp_Before_Test_GUID;
+internal static class GlobalSetUpTests_SetUp_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
new InstanceHookMethod
{
@@ -249,6 +376,41 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp_1Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.SetUp(cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalSetUpTests_SetUpWithContext_Before_Test_GUID;
+internal static class GlobalSetUpTests_SetUpWithContext_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
new InstanceHookMethod
{
@@ -299,6 +461,41 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithContext_1Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithContext_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.SetUpWithContext(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalSetUpTests_SetUpWithContext_Before_Test_GUID;
+internal static class GlobalSetUpTests_SetUpWithContext_Before_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
+ global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
new InstanceHookMethod
{
@@ -356,6 +553,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithContext_2Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithContext_2Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.SetUpWithContext(context, cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase1_BeforeAll1_BeforeEvery_Test_GUID;
+internal static class GlobalBase1_BeforeAll1_BeforeEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeEveryTestHooks.Add(
new BeforeTestHookMethod
{
@@ -407,6 +638,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 5
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase1_BeforeAll1_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalBase1.BeforeAll1(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase2_BeforeAll2_BeforeEvery_Test_GUID;
+internal static class GlobalBase2_BeforeAll2_BeforeEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeEveryTestHooks.Add(
new BeforeTestHookMethod
{
@@ -458,6 +722,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 20
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase2_BeforeAll2_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalBase2.BeforeAll2(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalBase3_BeforeAll3_BeforeEvery_Test_GUID;
+internal static class GlobalBase3_BeforeAll3_BeforeEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeEveryTestHooks.Add(
new BeforeTestHookMethod
{
@@ -509,6 +806,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 35
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase3_BeforeAll3_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalBase3.BeforeAll3(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalSetUpTests_BeforeAllSetUp_BeforeEvery_Test_GUID;
+internal static class GlobalSetUpTests_BeforeAllSetUp_BeforeEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeEveryTestHooks.Add(
new BeforeTestHookMethod
{
@@ -560,6 +890,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 50
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSetUp_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalSetUpTests.BeforeAllSetUp(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalSetUpTests_BeforeAllSetUp_BeforeEvery_Test_GUID;
+internal static class GlobalSetUpTests_BeforeAllSetUp_BeforeEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeEveryTestHooks.Add(
new BeforeTestHookMethod
{
@@ -618,6 +981,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 56
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSetUp_2Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalSetUpTests.BeforeAllSetUp(context, cancellationToken));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalSetUpTests_BeforeAllSetUpWithContext_BeforeEvery_Test_GUID;
+internal static class GlobalSetUpTests_BeforeAllSetUpWithContext_BeforeEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeEveryTestHooks.Add(
new BeforeTestHookMethod
{
@@ -669,6 +1065,39 @@ public sealed class GeneratedHookRegistry
LineNumber = 62
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSetUpWithContext_1Params_Body(TestContext context, CancellationToken cancellationToken)
+ {
+ await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalSetUpTests.BeforeAllSetUpWithContext(context));
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.GlobalSetUpTests_BeforeAllSetUpWithContext_BeforeEvery_Test_GUID;
+internal static class GlobalSetUpTests_BeforeAllSetUpWithContext_BeforeEvery_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.BeforeEveryTestHooks.Add(
new BeforeTestHookMethod
{
@@ -728,75 +1157,8 @@ public sealed class GeneratedHookRegistry
}
);
}
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase1_BeforeEach1_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalBase1)instance;
- await AsyncConvert.Convert(() => typedInstance.BeforeEach1());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase2_BeforeEach2_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalBase2)instance;
- await AsyncConvert.Convert(() => typedInstance.BeforeEach2());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase3_BeforeEach3_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalBase3)instance;
- await AsyncConvert.Convert(() => typedInstance.BeforeEach3());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)instance;
- await AsyncConvert.Convert(() => typedInstance.SetUp());
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)instance;
- await AsyncConvert.Convert(() => typedInstance.SetUp(cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithContext_1Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)instance;
- await AsyncConvert.Convert(() => typedInstance.SetUpWithContext(context));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithContext_2Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)instance;
- await AsyncConvert.Convert(() => typedInstance.SetUpWithContext(context, cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase1_BeforeAll1_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalBase1.BeforeAll1(context));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase2_BeforeAll2_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalBase2.BeforeAll2(context));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalBase3_BeforeAll3_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalBase3.BeforeAll3(context));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSetUp_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalSetUpTests.BeforeAllSetUp(context));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSetUp_2Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalSetUpTests.BeforeAllSetUp(context, cancellationToken));
- }
- private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSetUpWithContext_1Params_Body(TestContext context, CancellationToken cancellationToken)
- {
- await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalSetUpTests.BeforeAllSetUpWithContext(context));
- }
private static async ValueTask global_TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSetUpWithContext_2Params_Body(TestContext context, CancellationToken cancellationToken)
{
await AsyncConvert.Convert(() => global::TUnit.TestProject.BeforeTests.GlobalSetUpTests.BeforeAllSetUpWithContext(context, cancellationToken));
}
}
-internal static class HookModuleInitializer
-{
- [global::System.Runtime.CompilerServices.ModuleInitializer]
- public static void Initialize()
- {
- _ = new GeneratedHookRegistry();
- }
-}
diff --git a/TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt b/TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt
index 86dcf32413..82f7a645b8 100644
--- a/TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt
@@ -15,21 +15,11 @@ using global::TUnit.Core.Hooks;
using global::TUnit.Core.Interfaces.SourceGenerator;
using global::TUnit.Core.Models;
using HookType = global::TUnit.Core.HookType;
-namespace TUnit.Generated.Hooks;
-public sealed class GeneratedHookRegistry
+namespace TUnit.Generated.Hooks.DisposableFieldTests_Setup_Before_Test_GUID;
+internal static class DisposableFieldTests_Setup_Before_Test_GUIDInitializer
{
- static GeneratedHookRegistry()
- {
- try
- {
- PopulateSourcesDictionaries();
- }
- catch (Exception ex)
- {
- throw new global::System.InvalidOperationException($"Failed to initialize hook registry: {ex.Message}", ex);
- }
- }
- private static void PopulateSourcesDictionaries()
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
{
global::TUnit.Core.Sources.BeforeTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.DisposableFieldTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.DisposableFieldTests)].Add(
@@ -73,6 +63,40 @@ public sealed class GeneratedHookRegistry
Body = global_TUnit_TestProject_DisposableFieldTests_Setup_0Params_Body
}
);
+ }
+ private static async ValueTask global_TUnit_TestProject_DisposableFieldTests_Setup_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
+ {
+ var typedInstance = (global::TUnit.TestProject.DisposableFieldTests)instance;
+ await AsyncConvert.Convert(() => typedInstance.Setup());
+ }
+}
+
+
+// ===== FILE SEPARATOR =====
+
+//
+#pragma warning disable
+
+#nullable enable
+#pragma warning disable CS9113 // Parameter is unread.
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using global::TUnit.Core;
+using global::TUnit.Core.Hooks;
+using global::TUnit.Core.Interfaces.SourceGenerator;
+using global::TUnit.Core.Models;
+using HookType = global::TUnit.Core.HookType;
+namespace TUnit.Generated.Hooks.DisposableFieldTests_Blah_After_Test_GUID;
+internal static class DisposableFieldTests_Blah_After_Test_GUIDInitializer
+{
+ [global::System.Runtime.CompilerServices.ModuleInitializer]
+ public static void Initialize()
+ {
global::TUnit.Core.Sources.AfterTestHooks.GetOrAdd(typeof(global::TUnit.TestProject.DisposableFieldTests), _ => new global::System.Collections.Concurrent.ConcurrentBag());
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.DisposableFieldTests)].Add(
new InstanceHookMethod
@@ -116,22 +140,9 @@ public sealed class GeneratedHookRegistry
}
);
}
- private static async ValueTask global_TUnit_TestProject_DisposableFieldTests_Setup_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
- {
- var typedInstance = (global::TUnit.TestProject.DisposableFieldTests)instance;
- await AsyncConvert.Convert(() => typedInstance.Setup());
- }
private static async ValueTask global_TUnit_TestProject_DisposableFieldTests_Blah_0Params_Body(object instance, TestContext context, CancellationToken cancellationToken)
{
var typedInstance = (global::TUnit.TestProject.DisposableFieldTests)instance;
await AsyncConvert.Convert(() => typedInstance.Blah());
}
}
-internal static class HookModuleInitializer
-{
- [global::System.Runtime.CompilerServices.ModuleInitializer]
- public static void Initialize()
- {
- _ = new GeneratedHookRegistry();
- }
-}
diff --git a/TUnit.Core.SourceGenerator.Tests/HooksTests.NullableByteArgumentTests.verified.txt b/TUnit.Core.SourceGenerator.Tests/HooksTests.NullableByteArgumentTests.verified.txt
index e69de29bb2..5f282702bb 100644
--- a/TUnit.Core.SourceGenerator.Tests/HooksTests.NullableByteArgumentTests.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/HooksTests.NullableByteArgumentTests.verified.txt
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt
index 0cac079ff1..824b7fb7f1 100644
--- a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt
@@ -1,4 +1,4 @@
-//
+//
#pragma warning disable
//
diff --git a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt
index 0cac079ff1..824b7fb7f1 100644
--- a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt
@@ -1,4 +1,4 @@
-//
+//
#pragma warning disable
//
diff --git a/TUnit.Core.SourceGenerator.Tests/TestDiscoveryHookTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/TestDiscoveryHookTests.Test.verified.txt
index e69de29bb2..5f282702bb 100644
--- a/TUnit.Core.SourceGenerator.Tests/TestDiscoveryHookTests.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/TestDiscoveryHookTests.Test.verified.txt
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1899.BaseClass.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1899.BaseClass.verified.txt
index e69de29bb2..5f282702bb 100644
--- a/TUnit.Core.SourceGenerator.Tests/Tests1899.BaseClass.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/Tests1899.BaseClass.verified.txt
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2075.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2075.Test.verified.txt
index e69de29bb2..5f282702bb 100644
--- a/TUnit.Core.SourceGenerator.Tests/Tests2075.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/Tests2075.Test.verified.txt
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt
index d443cd25c1..f8d9822f2e 100644
--- a/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt
@@ -1,4 +1,4 @@
-//
+//
#pragma warning disable
//
diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt
index d193a1b047..a0f2c886ee 100644
--- a/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt
@@ -1,4 +1,4 @@
-//
+//
#pragma warning disable
//
@@ -19,13 +19,13 @@ internal sealed class Tests_Test_TestSource_GUID : global::TUnit.Core.Interfaces
[
new global::TUnit.Core.TestAttribute(),
new global::TUnit.Core.ArgumentsAttribute(0, 1L),
- new global::TUnit.Core.ArgumentsAttribute(0, 1),
+ new global::TUnit.Core.ArgumentsAttribute(0, 1L),
new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
],
DataSources = new global::TUnit.Core.IDataSourceAttribute[]
{
new global::TUnit.Core.ArgumentsAttribute(0, 1L),
- new global::TUnit.Core.ArgumentsAttribute(0, 1),
+ new global::TUnit.Core.ArgumentsAttribute(0, 1L),
},
ClassDataSources = new global::TUnit.Core.IDataSourceAttribute[]
{
@@ -187,13 +187,13 @@ internal sealed class Tests_Test2_TestSource_GUID : global::TUnit.Core.Interface
[
new global::TUnit.Core.TestAttribute(),
new global::TUnit.Core.ArgumentsAttribute(0, 1L, 2L, 3L),
- new global::TUnit.Core.ArgumentsAttribute(0, 1, 2, 3),
+ new global::TUnit.Core.ArgumentsAttribute(0, 1L, 2L, 3L),
new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass)
],
DataSources = new global::TUnit.Core.IDataSourceAttribute[]
{
new global::TUnit.Core.ArgumentsAttribute(0, 1L, 2L, 3L),
- new global::TUnit.Core.ArgumentsAttribute(0, 1, 2, 3),
+ new global::TUnit.Core.ArgumentsAttribute(0, 1L, 2L, 3L),
},
ClassDataSources = new global::TUnit.Core.IDataSourceAttribute[]
{
diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2136.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2136.Test.verified.txt
index 6bdeffce76..41d917c306 100644
--- a/TUnit.Core.SourceGenerator.Tests/Tests2136.Test.verified.txt
+++ b/TUnit.Core.SourceGenerator.Tests/Tests2136.Test.verified.txt
@@ -1,4 +1,4 @@
-//
+//
#pragma warning disable
//
diff --git a/TUnit.Core.SourceGenerator.Tests/TestsBase.cs b/TUnit.Core.SourceGenerator.Tests/TestsBase.cs
index 17cac6a3f4..468d28f72c 100644
--- a/TUnit.Core.SourceGenerator.Tests/TestsBase.cs
+++ b/TUnit.Core.SourceGenerator.Tests/TestsBase.cs
@@ -214,6 +214,9 @@ private StringBuilder Scrub(StringBuilder text)
var guidPattern2 = @"_ModuleInitializer_[a-fA-F0-9]{32}";
scrubbedText = System.Text.RegularExpressions.Regex.Replace(scrubbedText, guidPattern2, "_ModuleInitializer_GUID", System.Text.RegularExpressions.RegexOptions.None);
+ var guidPattern3 = @"_(Before|After|BeforeEvery|AfterEvery)_(Test|Class|Assembly|TestSession|TestDiscovery)_[a-fA-F0-9]{32}";
+ scrubbedText = System.Text.RegularExpressions.Regex.Replace(scrubbedText, guidPattern3, "_$1_$2_GUID", System.Text.RegularExpressions.RegexOptions.None);
+
// Scrub file paths - Windows style (e.g., D:\\git\\TUnit\\)
var windowsPathPattern = @"[A-Za-z]:\\\\[^""'\s,)]+";
scrubbedText = System.Text.RegularExpressions.Regex.Replace(scrubbedText, windowsPathPattern, "PATH_SCRUBBED");
diff --git a/TUnit.Core.SourceGenerator/CodeGenerators/DynamicTestsGenerator.cs b/TUnit.Core.SourceGenerator/CodeGenerators/DynamicTestsGenerator.cs
index ad953e5c02..909f407905 100644
--- a/TUnit.Core.SourceGenerator/CodeGenerators/DynamicTestsGenerator.cs
+++ b/TUnit.Core.SourceGenerator/CodeGenerators/DynamicTestsGenerator.cs
@@ -68,7 +68,7 @@ private void GenerateTests(SourceProductionContext context, DynamicTestSourceDat
}
sourceBuilder.EnsureNewLine();
- using (sourceBuilder.BeginBlock("public global::System.Collections.Generic.IReadOnlyList CollectDynamicTests(string sessionId)"))
+ using (sourceBuilder.BeginBlock("public global::System.Collections.Generic.IReadOnlyList CollectDynamicTests(string sessionId)"))
{
using (sourceBuilder.BeginBlock("try"))
{
diff --git a/TUnit.Core.SourceGenerator/CodeGenerators/Writers/FailedTestInitializationWriter.cs b/TUnit.Core.SourceGenerator/CodeGenerators/Writers/FailedTestInitializationWriter.cs
index 025a072b4f..cd18e57587 100644
--- a/TUnit.Core.SourceGenerator/CodeGenerators/Writers/FailedTestInitializationWriter.cs
+++ b/TUnit.Core.SourceGenerator/CodeGenerators/Writers/FailedTestInitializationWriter.cs
@@ -12,11 +12,11 @@ public static void GenerateFailedTestCode(ICodeWriter sourceBuilder,
sourceBuilder.Append("return");
sourceBuilder.Append("[");
- sourceBuilder.Append($"new FailedDynamicTest<{testSourceDataModel.Class.GloballyQualified()}>");
+ sourceBuilder.Append($"new global::TUnit.Core.FailedDynamicTest<{testSourceDataModel.Class.GloballyQualified()}>");
sourceBuilder.Append("{");
sourceBuilder.Append($"TestId = \"{testId}\",");
sourceBuilder.Append($"MethodName = $\"{testSourceDataModel.Method.Name}\",");
- sourceBuilder.Append($"Exception = new TUnit.Core.Exceptions.TestFailedInitializationException(\"{testSourceDataModel.Class.Name}.{testSourceDataModel.Method.Name} failed to initialize\", exception),");
+ sourceBuilder.Append($"Exception = new global::TUnit.Core.Exceptions.TestFailedInitializationException(\"{testSourceDataModel.Class.Name}.{testSourceDataModel.Method.Name} failed to initialize\", exception),");
sourceBuilder.Append($"TestFilePath = @\"{testSourceDataModel.FilePath}\",");
sourceBuilder.Append($"TestLineNumber = {testSourceDataModel.LineNumber},");
sourceBuilder.Append("}");
diff --git a/TUnit.Core.SourceGenerator/Generators/DataSourceHelpersGenerator.cs b/TUnit.Core.SourceGenerator/Generators/DataSourceHelpersGenerator.cs
index 52c6511589..9a8109ee18 100644
--- a/TUnit.Core.SourceGenerator/Generators/DataSourceHelpersGenerator.cs
+++ b/TUnit.Core.SourceGenerator/Generators/DataSourceHelpersGenerator.cs
@@ -17,10 +17,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.CreateSyntaxProvider(
predicate: static (s, _) => s is ClassDeclarationSyntax,
transform: static (ctx, _) => GetTypeWithDataSourceProperties(ctx))
- .Where(static t => t is not null)
- .Collect();
+ .Where(static t => t is not null);
- context.RegisterSourceOutput(typesWithDataSourceProperties, static (spc, types) => GenerateDataSourceHelpers(spc, types!));
+ // Generate individual files for each type instead of collecting them all
+ context.RegisterSourceOutput(typesWithDataSourceProperties, (spc, type) => { if (type != null) GenerateIndividualDataSourceHelper(spc, type); });
}
private static TypeWithDataSourceProperties? GetTypeWithDataSourceProperties(GeneratorSyntaxContext context)
@@ -58,22 +58,17 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
};
}
- private static void GenerateDataSourceHelpers(SourceProductionContext context, ImmutableArray types)
+ private static void GenerateIndividualDataSourceHelper(SourceProductionContext context, TypeWithDataSourceProperties? type)
{
- if (!types.Any())
+ // Skip if null, no properties or abstract class
+ if (type == null || !type.Value.Properties.Any() || type.Value.TypeSymbol.IsAbstract)
{
return;
}
- // Only generate helpers for types that actually have data source properties
- // Don't try to generate for referenced types - the data source attributes handle those
- var filteredTypes = types.Where(t => t.Properties.Any()).ToList();
-
- // Deduplicate types by their fully qualified name
- var uniqueTypes = filteredTypes
- .GroupBy(t => t.TypeSymbol.GloballyQualified())
- .Select(g => g.First())
- .ToArray();
+ var fullyQualifiedType = type.Value.TypeSymbol.GloballyQualified();
+ var safeName = GetSafeTypeName(type.Value.TypeSymbol);
+ var fileName = $"{safeName}_DataSourceHelper.g.cs";
var sb = new StringBuilder();
@@ -85,197 +80,47 @@ private static void GenerateDataSourceHelpers(SourceProductionContext context, I
sb.AppendLine();
sb.AppendLine("namespace TUnit.Core.Generated;");
sb.AppendLine();
- sb.AppendLine("/// ");
- sb.AppendLine("/// AOT-compatible generated helpers for data source property initialization");
- sb.AppendLine("/// ");
- sb.AppendLine("public static class DataSourceHelpers");
- sb.AppendLine("{");
- // Generate module initializer to register all initializers
+ // Generate individual module initializer for this type
+ sb.AppendLine($"internal static class {safeName}_DataSourceInitializer");
+ sb.AppendLine("{");
sb.AppendLine(" [ModuleInitializer]");
sb.AppendLine(" public static void Initialize()");
sb.AppendLine(" {");
- foreach (var typeWithProperties in uniqueTypes)
- {
- // Skip abstract classes - they cannot be instantiated
- if (typeWithProperties.TypeSymbol.IsAbstract)
- {
- continue;
- }
-
- var fullyQualifiedType = typeWithProperties.TypeSymbol.GloballyQualified();
- var safeName = fullyQualifiedType.Replace("global::", "").Replace(".", "_").Replace("<", "_").Replace(">", "_").Replace(",", "_");
- // Only register the property initializer - don't create instances
- sb.AppendLine($" global::TUnit.Core.Helpers.DataSourceHelpers.RegisterPropertyInitializer<{fullyQualifiedType}>(InitializePropertiesAsync_{safeName});");
- }
- sb.AppendLine(" }");
- sb.AppendLine();
-
- // Generate a method to ensure objects are initialized when created by ClassDataSources
- sb.AppendLine(" /// ");
- sb.AppendLine(" /// Ensures that objects created by ClassDataSources have their properties initialized");
- sb.AppendLine(" /// ");
- sb.AppendLine(" internal static async Task EnsureInitializedAsync(T instance, global::TUnit.Core.MethodMetadata testInformation, string testSessionId) where T : class");
- sb.AppendLine(" {");
- sb.AppendLine(" if (instance != null)");
- sb.AppendLine(" {");
- sb.AppendLine(" await global::TUnit.Core.Helpers.DataSourceHelpers.InitializeDataSourcePropertiesAsync(instance, testInformation, testSessionId);");
- sb.AppendLine(" }");
- sb.AppendLine(" return instance;");
+ sb.AppendLine($" global::TUnit.Core.Helpers.DataSourceHelpers.RegisterPropertyInitializer<{fullyQualifiedType}>(InitializePropertiesAsync_{safeName});");
sb.AppendLine(" }");
- sb.AppendLine();
-
- foreach (var typeWithProperties in uniqueTypes)
- {
- GenerateTypeSpecificHelpers(sb, typeWithProperties);
- }
-
- sb.AppendLine("}");
-
- context.AddSource("DataSourceHelpers.g.cs", sb.ToString());
- }
-
- private static bool ShouldGenerateHelperFor(TypeWithDataSourceProperties typeInfo)
- {
- var typeSymbol = typeInfo.TypeSymbol;
-
- // Skip primitive types and built-in .NET types
- if (typeSymbol.SpecialType != SpecialType.None)
- {
- return false;
- }
-
- // Skip string specifically
- if (typeSymbol.ToDisplayString() == "string")
- {
- return false;
- }
-
- // Skip if it's a system type
- var namespaceName = typeSymbol.ContainingNamespace?.ToDisplayString();
- if (namespaceName?.StartsWith("System") == true && !namespaceName.StartsWith("System.Threading.Tasks"))
- {
- return false;
- }
-
- // Skip test classes (classes that have TestAttribute or inherit from test base classes)
- if (IsTestClass(typeSymbol))
- {
- return false;
- }
-
- // Skip classes with complex constructor requirements that are likely test classes
- if (HasComplexConstructorRequirements(typeSymbol))
- {
- return false;
- }
-
- return true;
- }
-
- private static bool IsTestClass(INamedTypeSymbol typeSymbol)
- {
- // Check if the class or any of its methods have Test attributes
- var hasTestAttribute = typeSymbol.GetAttributes().Any(attr =>
- attr.AttributeClass?.Name.Contains("Test") == true);
-
- if (hasTestAttribute)
- {
- return true;
- }
-
- // Check methods for test attributes
- foreach (var member in typeSymbol.GetMembers().OfType())
- {
- if (member.GetAttributes().Any(attr => attr.AttributeClass?.Name.Contains("Test") == true))
- {
- return true;
- }
- }
- return false;
- }
-
- private static bool HasComplexConstructorRequirements(INamedTypeSymbol typeSymbol)
- {
- // If there's no parameterless constructor and all constructors have parameters,
- // it's likely a complex type that we shouldn't generate helpers for
- var constructors = typeSymbol.Constructors.Where(c => !c.IsStatic).ToList();
-
- if (!constructors.Any())
- {
- return true; // No constructors available
- }
-
- // Check if there's a parameterless constructor
- var hasParameterlessConstructor = constructors.Any(c => c.Parameters.Length == 0);
+ // Generate the property initialization method for this specific type
+ GeneratePropertyInitializationMethod(sb, type.Value, safeName, fullyQualifiedType);
- if (hasParameterlessConstructor)
- {
- return false; // We can use the parameterless constructor
- }
+ sb.AppendLine("}");
- // If all constructors require parameters, check if they're simple types we can handle
- foreach (var constructor in constructors)
- {
- if (constructor.Parameters.All(p => CanProvideDefaultValue(p.Type)))
- {
- return false; // We can provide default values for all parameters
- }
- }
-
- return true; // Too complex to handle
+ context.AddSource(fileName, sb.ToString());
}
- private static bool CanProvideDefaultValue(ITypeSymbol type)
+ private static string GetSafeTypeName(INamedTypeSymbol typeSymbol)
{
- // We can provide default values for simple types
- return type.SpecialType != SpecialType.None ||
- type.TypeKind == TypeKind.Enum ||
- type.CanBeReferencedByName;
+ var fullyQualifiedType = typeSymbol.GloballyQualified();
+ return fullyQualifiedType
+ .Replace("global::", "")
+ .Replace(".", "_")
+ .Replace("<", "_")
+ .Replace(">", "_")
+ .Replace(",", "_")
+ .Replace(" ", "")
+ .Replace("`", "_")
+ .Replace("+", "_");
}
- private static void GenerateTypeSpecificHelpers(StringBuilder sb, TypeWithDataSourceProperties typeInfo)
+ private static void GeneratePropertyInitializationMethod(StringBuilder sb, TypeWithDataSourceProperties type, string safeName, string fullyQualifiedType)
{
- var typeSymbol = typeInfo.TypeSymbol;
- var fullyQualifiedTypeName = typeSymbol.GloballyQualified();
- var safeName = fullyQualifiedTypeName.Replace("global::", "").Replace(".", "_").Replace("<", "_").Replace(">", "_").Replace(",", "_");
-
- // Skip abstract classes - they cannot be instantiated
- if (typeSymbol.IsAbstract)
- {
- return;
- }
+ var settableProperties = type.Properties.Where(p => p.Property.SetMethod != null && !p.Property.SetMethod.IsInitOnly).ToList();
+ var initOnlyProperties = type.Properties.Where(p => p.Property.SetMethod?.IsInitOnly == true).ToList();
- // Separate data source properties into init-only and settable
- var initOnlyProperties = new global::System.Collections.Generic.List();
- var settableProperties = new global::System.Collections.Generic.List();
- var staticProperties = new global::System.Collections.Generic.List();
-
- foreach (var prop in typeInfo.Properties)
- {
- if (prop.Property.IsStatic)
- {
- staticProperties.Add(prop);
- }
- else if (prop.Property.SetMethod?.IsInitOnly == true)
- {
- initOnlyProperties.Add(prop);
- }
- else
- {
- settableProperties.Add(prop);
- }
- }
-
- // Generate InitializeProperties method for instance properties
- sb.AppendLine(" /// ");
- sb.AppendLine($" /// Initializes data source properties on an existing instance of {typeSymbol.Name}");
- sb.AppendLine(" /// ");
- sb.AppendLine($" public static async Task InitializePropertiesAsync_{safeName}({fullyQualifiedTypeName} instance, global::TUnit.Core.MethodMetadata testInformation, string testSessionId)");
+ sb.AppendLine($" public static async Task InitializePropertiesAsync_{safeName}({fullyQualifiedType} instance, global::TUnit.Core.MethodMetadata testInformation, string testSessionId)");
sb.AppendLine(" {");
- // First, check and set any init-only properties that are null using reflection
+ // Handle init-only properties with reflection
if (initOnlyProperties.Any())
{
sb.AppendLine(" // Set init-only properties that are null using reflection");
@@ -284,8 +129,6 @@ private static void GenerateTypeSpecificHelpers(StringBuilder sb, TypeWithDataSo
var property = propInfo.Property;
var propertyName = property.Name;
- // For value types (including tuples), we can't compare with null
- // Skip the null check for value types - they always need initialization
if (!property.Type.IsValueType)
{
sb.AppendLine($" if (instance.{propertyName} == null)");
@@ -296,200 +139,44 @@ private static void GenerateTypeSpecificHelpers(StringBuilder sb, TypeWithDataSo
sb.AppendLine(" {");
}
- // Resolve the value for this property
- // Always use runtime resolution - let the data source attribute handle everything
sb.AppendLine($" var value = await global::TUnit.Core.Helpers.DataSourceHelpers.ResolveDataSourcePropertyAsync(");
sb.AppendLine($" instance, \"{propertyName}\", testInformation, testSessionId);");
sb.AppendLine($" var backingField = instance.GetType().GetField(\"<{propertyName}>k__BackingField\", ");
sb.AppendLine(" global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic);");
sb.AppendLine(" backingField?.SetValue(instance, value);");
-
sb.AppendLine(" }");
}
sb.AppendLine();
}
+ // Handle settable properties
foreach (var propInfo in settableProperties)
{
- GeneratePropertyInitialization(sb, propInfo, safeName);
- }
-
- sb.AppendLine(" }");
- sb.AppendLine();
-
- // Generate InitializeStaticProperties method if needed
- if (staticProperties.Any())
- {
- sb.AppendLine(" /// ");
- sb.AppendLine($" /// Initializes static data source properties for {typeSymbol.Name}");
- sb.AppendLine(" /// ");
- sb.AppendLine($" public static async Task InitializeStaticPropertiesAsync_{safeName}(global::TUnit.Core.MethodMetadata testInformation, string testSessionId)");
- sb.AppendLine(" {");
-
- foreach (var propInfo in staticProperties)
- {
- GenerateStaticPropertyInitialization(sb, propInfo, fullyQualifiedTypeName);
- }
-
- sb.AppendLine(" }");
- sb.AppendLine();
- }
- }
-
- private static void GeneratePropertyInitialization(StringBuilder sb, PropertyWithDataSource propInfo, string typeSafeName)
- {
- var property = propInfo.Property;
- var attr = propInfo.DataSourceAttribute;
- var propertyName = property.Name;
-
- if (attr.AttributeClass == null)
- {
- return;
- }
-
- var fullyQualifiedName = attr.AttributeClass.GloballyQualifiedNonGeneric();
-
- sb.AppendLine($" // Initialize {propertyName} property");
-
- if (attr.AttributeClass.IsOrInherits("global::TUnit.Core.AsyncDataSourceGeneratorAttribute") ||
- attr.AttributeClass.IsOrInherits("global::TUnit.Core.AsyncUntypedDataSourceGeneratorAttribute"))
- {
- GenerateAsyncDataSourcePropertyInit(sb, propInfo);
- }
- else if (fullyQualifiedName == "global::TUnit.Core.ArgumentsAttribute")
- {
- GenerateArgumentsPropertyInit(sb, propInfo);
- }
- }
-
- private static void GenerateAsyncDataSourcePropertyInit(StringBuilder sb, PropertyWithDataSource propInfo)
- {
- var property = propInfo.Property;
- var attr = propInfo.DataSourceAttribute;
-
- // Use runtime resolution to ensure the data source attribute's logic is properly invoked
- // This ensures caching, sharing, and other attribute-specific behaviors work correctly
- sb.AppendLine(" {");
- sb.AppendLine($" var dataSourceInstance = await global::TUnit.Core.Helpers.DataSourceHelpers.ResolveDataSourceForPropertyAsync(");
- sb.AppendLine($" typeof({property.ContainingType.GloballyQualified()}),");
- sb.AppendLine($" \"{property.Name}\",");
- sb.AppendLine($" testInformation,");
- sb.AppendLine($" testSessionId);");
- sb.AppendLine($" instance.{property.Name} = ({property.Type.GloballyQualified()})dataSourceInstance;");
- sb.AppendLine(" }");
- }
-
- private static void GenerateArgumentsPropertyInit(StringBuilder sb, PropertyWithDataSource propInfo)
- {
- var property = propInfo.Property;
- var attr = propInfo.DataSourceAttribute;
-
- if (attr.ConstructorArguments.Length > 0)
- {
- if (attr.ConstructorArguments[0].Kind == TypedConstantKind.Array &&
- attr.ConstructorArguments[0].Values.Length > 0)
- {
- var value = FormatConstantValue(attr.ConstructorArguments[0].Values[0]);
- sb.AppendLine($" instance.{property.Name} = {value};");
- }
- else if (attr.ConstructorArguments[0].Kind != TypedConstantKind.Array)
- {
- var value = FormatConstantValue(attr.ConstructorArguments[0]);
- sb.AppendLine($" instance.{property.Name} = {value};");
- }
- }
- }
-
-
- private static void GenerateInitOnlyPropertyResolution(StringBuilder sb, PropertyWithDataSource propInfo, string typeSafeName)
- {
- var property = propInfo.Property;
- var attr = propInfo.DataSourceAttribute;
- var propertyName = property.Name;
- var varName = $"resolved{propertyName}";
-
- if (attr.AttributeClass == null)
- {
- return;
- }
-
- // Handle any data source attribute that derives from IDataSourceAttribute
- if (DataSourceAttributeHelper.IsDataSourceAttribute(attr.AttributeClass))
- {
- // For all data source attributes, we should use runtime resolution to ensure
- // the attribute's logic (including caching) is properly invoked
- sb.AppendLine($" var {varName} = ({property.Type.GloballyQualified()})await global::TUnit.Core.Helpers.DataSourceHelpers.ResolveDataSourceForPropertyAsync(");
- sb.AppendLine($" typeof({property.ContainingType.GloballyQualified()}),");
- sb.AppendLine($" \"{propertyName}\",");
- sb.AppendLine($" testInformation,");
- sb.AppendLine($" testSessionId);");
- sb.AppendLine($" await global::TUnit.Core.ObjectInitializer.InitializeAsync({varName});");
- }
- else
- {
- sb.AppendLine($" var {varName} = default({property.Type.GloballyQualified()})!; // Not a recognized data source attribute");
- }
- }
-
- private static void GenerateInitOnlyPropertyAssignment(StringBuilder sb, PropertyWithDataSource propInfo)
- {
- var property = propInfo.Property;
- var attr = propInfo.DataSourceAttribute;
- var propertyName = property.Name;
- var varName = $"resolved{propertyName}";
-
- if (attr.AttributeClass == null)
- {
- return;
- }
-
- var fullyQualifiedName = attr.AttributeClass.GloballyQualifiedNonGeneric();
-
- sb.AppendLine($" // Initialize {propertyName} property (init-only)");
-
- // Use the pre-resolved value for any data source attribute
- if (DataSourceAttributeHelper.IsDataSourceAttribute(attr.AttributeClass))
- {
- // Special handling for ArgumentsAttribute
- if (fullyQualifiedName == "global::TUnit.Core.ArgumentsAttribute")
+ var property = propInfo.Property;
+ var propertyName = property.Name;
+
+ if (property.IsStatic)
{
- GenerateArgumentsPropertyAssignment(sb, propInfo);
+ // Generate static property initialization
+ sb.AppendLine($" // Initialize static property {propertyName}");
+ sb.AppendLine($" if ({fullyQualifiedType}.{propertyName} == default)");
+ sb.AppendLine(" {");
+ sb.AppendLine($" var value = await global::TUnit.Core.Helpers.DataSourceHelpers.ResolveDataSourcePropertyAsync(");
+ sb.AppendLine($" instance, \"{propertyName}\", testInformation, testSessionId);");
+ sb.AppendLine($" {fullyQualifiedType}.{propertyName} = ({property.Type.GloballyQualified()})value;");
+ sb.AppendLine(" }");
}
else
{
- // All other data source attributes use the resolved variable
- sb.AppendLine($" {propertyName} = {varName},");
+ GeneratePropertyInitialization(sb, propInfo);
}
+ sb.AppendLine();
}
- else
- {
- // Non-data source attributes (shouldn't happen, but handle gracefully)
- sb.AppendLine($" {propertyName} = {varName},");
- }
- }
- private static void GenerateArgumentsPropertyAssignment(StringBuilder sb, PropertyWithDataSource propInfo)
- {
- var property = propInfo.Property;
- var attr = propInfo.DataSourceAttribute;
-
- if (attr.ConstructorArguments.Length > 0)
- {
- if (attr.ConstructorArguments[0].Kind == TypedConstantKind.Array &&
- attr.ConstructorArguments[0].Values.Length > 0)
- {
- var value = FormatConstantValue(attr.ConstructorArguments[0].Values[0]);
- sb.AppendLine($" {property.Name} = {value},");
- }
- else if (attr.ConstructorArguments[0].Kind != TypedConstantKind.Array)
- {
- var value = FormatConstantValue(attr.ConstructorArguments[0]);
- sb.AppendLine($" {property.Name} = {value},");
- }
- }
+ sb.AppendLine(" }");
}
- private static void GenerateStaticPropertyInitialization(StringBuilder sb, PropertyWithDataSource propInfo, string fullyQualifiedTypeName)
+ private static void GeneratePropertyInitialization(StringBuilder sb, PropertyWithDataSource propInfo)
{
var property = propInfo.Property;
var attr = propInfo.DataSourceAttribute;
@@ -500,98 +187,13 @@ private static void GenerateStaticPropertyInitialization(StringBuilder sb, Prope
return;
}
- var fullyQualifiedName = attr.AttributeClass.GloballyQualifiedNonGeneric();
-
- sb.AppendLine($" // Initialize static {propertyName} property");
-
- if (attr.AttributeClass.IsOrInherits("global::TUnit.Core.AsyncDataSourceGeneratorAttribute") ||
- attr.AttributeClass.IsOrInherits("global::TUnit.Core.AsyncUntypedDataSourceGeneratorAttribute"))
- {
- GenerateStaticAsyncDataSourcePropertyInit(sb, propInfo, fullyQualifiedTypeName);
- }
- else if (fullyQualifiedName == "global::TUnit.Core.ArgumentsAttribute")
- {
- GenerateStaticArgumentsPropertyInit(sb, propInfo, fullyQualifiedTypeName);
- }
- }
-
- private static void GenerateStaticAsyncDataSourcePropertyInit(StringBuilder sb, PropertyWithDataSource propInfo, string fullyQualifiedTypeName)
- {
- var property = propInfo.Property;
-
- // Simply delegate to runtime resolution - the data source attribute knows what to do
- sb.AppendLine($" {fullyQualifiedTypeName}.{property.Name} = ({property.Type.GloballyQualified()})await global::TUnit.Core.Helpers.DataSourceHelpers.ResolveDataSourceForPropertyAsync(");
- sb.AppendLine($" typeof({property.ContainingType.GloballyQualified()}),");
- sb.AppendLine($" \"{property.Name}\",");
- sb.AppendLine($" testInformation,");
- sb.AppendLine($" testSessionId);");
- }
-
- private static void GenerateStaticArgumentsPropertyInit(StringBuilder sb, PropertyWithDataSource propInfo, string fullyQualifiedTypeName)
- {
- var property = propInfo.Property;
- var attr = propInfo.DataSourceAttribute;
-
- if (attr.ConstructorArguments.Length > 0)
- {
- if (attr.ConstructorArguments[0].Kind == TypedConstantKind.Array &&
- attr.ConstructorArguments[0].Values.Length > 0)
- {
- var value = FormatConstantValue(attr.ConstructorArguments[0].Values[0]);
- sb.AppendLine($" {fullyQualifiedTypeName}.{property.Name} = {value};");
- }
- else if (attr.ConstructorArguments[0].Kind != TypedConstantKind.Array)
- {
- var value = FormatConstantValue(attr.ConstructorArguments[0]);
- sb.AppendLine($" {fullyQualifiedTypeName}.{property.Name} = {value};");
- }
- }
- }
-
-
- private static string GetDefaultValueForType(ITypeSymbol type)
- {
- return type.SpecialType switch
- {
- SpecialType.System_Boolean => "false",
- SpecialType.System_Byte => "(byte)0",
- SpecialType.System_SByte => "(sbyte)0",
- SpecialType.System_Int16 => "(short)0",
- SpecialType.System_UInt16 => "(ushort)0",
- SpecialType.System_Int32 => "0",
- SpecialType.System_UInt32 => "0U",
- SpecialType.System_Int64 => "0L",
- SpecialType.System_UInt64 => "0UL",
- SpecialType.System_Single => "0f",
- SpecialType.System_Double => "0d",
- SpecialType.System_Decimal => "0m",
- SpecialType.System_Char => "'\\0'",
- SpecialType.System_String => "\"\"",
- SpecialType.System_DateTime => "default(System.DateTime)",
- _ when type.TypeKind == TypeKind.Enum => $"default({type.GloballyQualified()})",
- _ when type.CanBeReferencedByName => $"default({type.GloballyQualified()})",
- _ => "null"
- };
- }
-
- private static string FormatConstantValue(TypedConstant constant)
- {
- return constant.Kind switch
- {
- TypedConstantKind.Primitive when constant.Value is string str => $"\"{str}\"",
- TypedConstantKind.Primitive when constant.Value is char ch => $"'{ch}'",
- TypedConstantKind.Primitive when constant.Value is bool b => b.ToString().ToLowerInvariant(),
- TypedConstantKind.Primitive => constant.Value?.ToString() ?? "null",
- TypedConstantKind.Enum => $"({constant.Type!.GloballyQualified()}){constant.Value}",
- TypedConstantKind.Type => $"typeof({((ITypeSymbol)constant.Value!).GloballyQualified()})",
- _ when constant.IsNull => "null",
- _ => "null"
- };
+ sb.AppendLine($" // Initialize {propertyName} property");
+ sb.AppendLine($" if (instance.{propertyName} == default)");
+ sb.AppendLine(" {");
+ sb.AppendLine($" var value = await global::TUnit.Core.Helpers.DataSourceHelpers.ResolveDataSourcePropertyAsync(");
+ sb.AppendLine($" instance, \"{propertyName}\", testInformation, testSessionId);");
+ sb.AppendLine($" instance.{propertyName} = ({property.Type.GloballyQualified()})value;");
+ sb.AppendLine(" }");
+ sb.AppendLine();
}
}
-
-public class TypeWithDataSourceProperties
-{
- public required INamedTypeSymbol TypeSymbol { get; set; }
- public required List Properties { get; set; }
-}
\ No newline at end of file
diff --git a/TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs b/TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs
index edef52da3a..77dc7fb29b 100644
--- a/TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs
+++ b/TUnit.Core.SourceGenerator/Generators/HookMetadataGenerator.cs
@@ -40,72 +40,279 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
transform: static (ctx, _) => GetHookMethodMetadata(ctx, "AfterEvery"))
.Where(static m => m is not null);
- var beforeHooksCollected = beforeHooks.Collect();
- var afterHooksCollected = afterHooks.Collect();
- var beforeEveryHooksCollected = beforeEveryHooks.Collect();
- var afterEveryHooksCollected = afterEveryHooks.Collect();
-
- var allHooks = beforeHooksCollected
- .Combine(afterHooksCollected)
- .Combine(beforeEveryHooksCollected)
- .Combine(afterEveryHooksCollected);
-
- context.RegisterSourceOutput(allHooks, (sourceProductionContext, data) =>
- {
- var (((beforeHooksList, afterHooksList), beforeEveryHooksList), afterEveryHooksList) = data;
- var directHooks = beforeHooksList
- .Concat(afterHooksList)
- .Concat(beforeEveryHooksList)
- .Concat(afterEveryHooksList)
- .Where(h => h != null)
- .Cast()
- .ToList();
-
- var validHooks = ProcessHooks(directHooks);
- GenerateHookRegistry(sourceProductionContext, validHooks.ToImmutableArray());
+ // Generate individual files for each hook instead of collecting them
+ context.RegisterSourceOutput(beforeHooks, (sourceProductionContext, hook) =>
+ {
+ if (hook != null)
+ {
+ GenerateIndividualHookFile(sourceProductionContext, hook);
+ }
+ });
+
+ context.RegisterSourceOutput(afterHooks, (sourceProductionContext, hook) =>
+ {
+ if (hook != null)
+ {
+ GenerateIndividualHookFile(sourceProductionContext, hook);
+ }
+ });
+
+ context.RegisterSourceOutput(beforeEveryHooks, (sourceProductionContext, hook) =>
+ {
+ if (hook != null)
+ {
+ GenerateIndividualHookFile(sourceProductionContext, hook);
+ }
+ });
+
+ context.RegisterSourceOutput(afterEveryHooks, (sourceProductionContext, hook) =>
+ {
+ if (hook != null)
+ {
+ GenerateIndividualHookFile(sourceProductionContext, hook);
+ }
});
}
- private static List ProcessHooks(List directHooks)
+ private static void GenerateIndividualHookFile(SourceProductionContext context, HookMethodMetadata hook)
{
- var validDirectHooks = directHooks.ToList();
+ try
+ {
+ var safeFileName = GetSafeFileName(hook);
+ using var writer = new CodeWriter();
+
+ writer.AppendLine("#nullable enable");
+ writer.AppendLine("#pragma warning disable CS9113 // Parameter is unread.");
+ writer.AppendLine();
+ writer.AppendLine("using System;");
+ writer.AppendLine("using System.Collections.Generic;");
+ writer.AppendLine("using System.Linq;");
+ writer.AppendLine("using System.Reflection;");
+ writer.AppendLine("using System.Runtime.CompilerServices;");
+ writer.AppendLine("using System.Threading;");
+ writer.AppendLine("using System.Threading.Tasks;");
+ writer.AppendLine("using global::TUnit.Core;");
+ writer.AppendLine("using global::TUnit.Core.Hooks;");
+ writer.AppendLine("using global::TUnit.Core.Interfaces.SourceGenerator;");
+ writer.AppendLine("using global::TUnit.Core.Models;");
+ writer.AppendLine("using HookType = global::TUnit.Core.HookType;");
+ writer.AppendLine();
+
+ writer.AppendLine($"namespace TUnit.Generated.Hooks.{safeFileName};");
+ writer.AppendLine();
- return validDirectHooks
- .GroupBy(h => h, new HookEqualityComparer())
- .Select(g => g.First())
- .ToList();
+ using (writer.BeginBlock($"internal static class {safeFileName}Initializer"))
+ {
+ writer.AppendLine("[global::System.Runtime.CompilerServices.ModuleInitializer]");
+ using (writer.BeginBlock("public static void Initialize()"))
+ {
+ GenerateHookRegistration(writer, hook);
+ }
+
+ writer.AppendLine();
+ GenerateHookDelegate(writer, hook);
+ }
+
+ context.AddSource($"{safeFileName}.Hook.g.cs", writer.ToString());
+ }
+ catch (Exception ex)
+ {
+ var descriptor = new DiagnosticDescriptor(
+ "THG001",
+ "Hook metadata generation failed",
+ "Failed to generate hook metadata for {0}: {1}",
+ "TUnit",
+ DiagnosticSeverity.Error,
+ isEnabledByDefault: true);
+
+ var hookName = $"{hook.TypeSymbol.Name}.{hook.MethodSymbol.Name}";
+ context.ReportDiagnostic(Diagnostic.Create(descriptor, Location.None, hookName, ex.Message));
+ }
}
- private class HookEqualityComparer : IEqualityComparer
+ private static string GetSafeFileName(HookMethodMetadata hook)
{
- public bool Equals(HookMethodMetadata? x, HookMethodMetadata? y)
+ var typeName = hook.TypeSymbol.Name;
+ var methodName = hook.MethodSymbol.Name;
+
+ // Remove generic type parameters from type name for file safety
+ if (hook.TypeSymbol.IsGenericType)
{
- if (x == null || y == null)
+ var genericIndex = typeName.IndexOf('`');
+ if (genericIndex > 0)
{
- return x == y;
+ typeName = typeName.Substring(0, genericIndex);
}
-
- return SymbolEqualityComparer.Default.Equals(x.TypeSymbol, y.TypeSymbol) &&
- SymbolEqualityComparer.Default.Equals(x.MethodSymbol, y.MethodSymbol);
}
- public int GetHashCode(HookMethodMetadata? obj)
+ var safeTypeName = typeName
+ .Replace(".", "_")
+ .Replace("<", "_")
+ .Replace(">", "_")
+ .Replace(",", "_")
+ .Replace(" ", "")
+ .Replace("`", "_")
+ .Replace("+", "_");
+
+ var safeMethodName = methodName
+ .Replace(".", "_")
+ .Replace("<", "_")
+ .Replace(">", "_")
+ .Replace(",", "_")
+ .Replace(" ", "");
+
+ var guid = System.Guid.NewGuid().ToString("N");
+
+ return $"{safeTypeName}_{safeMethodName}_{hook.HookKind}_{hook.HookType}_{guid}";
+ }
+
+ private static void GenerateHookRegistration(CodeWriter writer, HookMethodMetadata hook)
+ {
+ var typeDisplay = hook.TypeSymbol.GloballyQualified();
+ var isInstance = hook.HookKind is "Before" or "After" && hook.HookType == "Test";
+
+ if (hook.HookType == "Test")
{
- if (obj == null)
+ if (hook.HookKind == "Before")
{
- return 0;
+ if (isInstance)
+ {
+ GenerateInstanceHookRegistration(writer, "BeforeTestHooks", typeDisplay, hook);
+ }
+ else
+ {
+ GenerateGlobalHookRegistration(writer, "BeforeEveryTestHooks", hook);
+ }
+ }
+ else if (hook.HookKind == "After")
+ {
+ if (isInstance)
+ {
+ GenerateInstanceHookRegistration(writer, "AfterTestHooks", typeDisplay, hook);
+ }
+ else
+ {
+ GenerateGlobalHookRegistration(writer, "AfterEveryTestHooks", hook);
+ }
+ }
+ else if (hook.HookKind == "BeforeEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "BeforeEveryTestHooks", hook);
+ }
+ else if (hook.HookKind == "AfterEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "AfterEveryTestHooks", hook);
+ }
+ }
+ else if (hook.HookType == "Class")
+ {
+ if (hook.HookKind == "Before")
+ {
+ GenerateTypeHookRegistration(writer, "BeforeClassHooks", typeDisplay, hook);
}
+ else if (hook.HookKind == "After")
+ {
+ GenerateTypeHookRegistration(writer, "AfterClassHooks", typeDisplay, hook);
+ }
+ else if (hook.HookKind == "BeforeEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "BeforeEveryClassHooks", hook);
+ }
+ else if (hook.HookKind == "AfterEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "AfterEveryClassHooks", hook);
+ }
+ }
+ else if (hook.HookType == "Assembly")
+ {
+ var assemblyName = hook.TypeSymbol.ContainingAssembly.Name.Replace(".", "_").Replace("-", "_");
+ writer.AppendLine($"var {assemblyName}_assembly = typeof({typeDisplay}).Assembly;");
- unchecked
+ if (hook.HookKind == "Before")
+ {
+ GenerateAssemblyHookRegistration(writer, "BeforeAssemblyHooks", assemblyName, hook);
+ }
+ else if (hook.HookKind == "After")
+ {
+ GenerateAssemblyHookRegistration(writer, "AfterAssemblyHooks", assemblyName, hook);
+ }
+ else if (hook.HookKind == "BeforeEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "BeforeEveryAssemblyHooks", hook);
+ }
+ else if (hook.HookKind == "AfterEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "AfterEveryAssemblyHooks", hook);
+ }
+ }
+ else if (hook.HookType == "TestSession")
+ {
+ if (hook.HookKind is "Before" or "BeforeEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "BeforeTestSessionHooks", hook);
+ }
+ else if (hook.HookKind is "After" or "AfterEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "AfterTestSessionHooks", hook);
+ }
+ }
+ else if (hook.HookType == "TestDiscovery")
+ {
+ if (hook.HookKind is "Before" or "BeforeEvery")
{
- var hash = 17;
- hash = hash * 31 + SymbolEqualityComparer.Default.GetHashCode(obj.TypeSymbol);
- hash = hash * 31 + SymbolEqualityComparer.Default.GetHashCode(obj.MethodSymbol);
- return hash;
+ GenerateGlobalHookRegistration(writer, "BeforeTestDiscoveryHooks", hook);
+ }
+ else if (hook.HookKind is "After" or "AfterEvery")
+ {
+ GenerateGlobalHookRegistration(writer, "AfterTestDiscoveryHooks", hook);
}
}
}
+ private static void GenerateInstanceHookRegistration(CodeWriter writer, string dictionaryName, string typeDisplay, HookMethodMetadata hook)
+ {
+ var hookType = GetConcreteHookType(dictionaryName, true);
+ writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}.GetOrAdd(typeof({typeDisplay}), _ => new global::System.Collections.Concurrent.ConcurrentBag());");
+ writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}[typeof({typeDisplay})].Add(");
+ writer.Indent();
+ GenerateHookObject(writer, hook, true);
+ writer.Unindent();
+ writer.AppendLine(");");
+ }
+
+ private static void GenerateTypeHookRegistration(CodeWriter writer, string dictionaryName, string typeDisplay, HookMethodMetadata hook)
+ {
+ var hookType = GetConcreteHookType(dictionaryName, false);
+ writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}.GetOrAdd(typeof({typeDisplay}), _ => new global::System.Collections.Concurrent.ConcurrentBag());");
+ writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}[typeof({typeDisplay})].Add(");
+ writer.Indent();
+ GenerateHookObject(writer, hook, false);
+ writer.Unindent();
+ writer.AppendLine(");");
+ }
+
+ private static void GenerateAssemblyHookRegistration(CodeWriter writer, string dictionaryName, string assemblyVarName, HookMethodMetadata hook)
+ {
+ var assemblyVar = assemblyVarName + "_assembly";
+ var hookType = GetConcreteHookType(dictionaryName, false);
+ writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}.GetOrAdd({assemblyVar}, _ => new global::System.Collections.Concurrent.ConcurrentBag());");
+ writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}[{assemblyVar}].Add(");
+ writer.Indent();
+ GenerateHookObject(writer, hook, false);
+ writer.Unindent();
+ writer.AppendLine(");");
+ }
+
+ private static void GenerateGlobalHookRegistration(CodeWriter writer, string listName, HookMethodMetadata hook)
+ {
+ writer.AppendLine($"global::TUnit.Core.Sources.{listName}.Add(");
+ writer.Indent();
+ GenerateHookObject(writer, hook, false);
+ writer.Unindent();
+ writer.AppendLine(");");
+ }
+
+
private static HookMethodMetadata? GetHookMethodMetadata(GeneratorAttributeSyntaxContext context, string hookKind)
{
if (context.TargetSymbol is not IMethodSymbol methodSymbol)
@@ -296,256 +503,10 @@ private static string GetConcreteHookType(string dictionaryName, bool isInstance
};
}
- private static void GenerateHookRegistry(SourceProductionContext context, ImmutableArray hooks)
- {
- try
- {
- var validHooks = hooks
- .Where(h => h != null)
- .ToList();
- if (!validHooks.Any())
- {
- return;
- }
- using var writer = new CodeWriter();
- writer.AppendLine("#nullable enable");
- writer.AppendLine("#pragma warning disable CS9113 // Parameter is unread.");
- writer.AppendLine();
- writer.AppendLine("using System;");
- writer.AppendLine("using System.Collections.Generic;");
- writer.AppendLine("using System.Linq;");
- writer.AppendLine("using System.Reflection;");
- writer.AppendLine("using System.Runtime.CompilerServices;");
- writer.AppendLine("using System.Threading;");
- writer.AppendLine("using System.Threading.Tasks;");
- writer.AppendLine("using global::TUnit.Core;");
- writer.AppendLine("using global::TUnit.Core.Hooks;");
- writer.AppendLine("using global::TUnit.Core.Interfaces.SourceGenerator;");
- writer.AppendLine("using global::TUnit.Core.Models;");
- writer.AppendLine("using HookType = global::TUnit.Core.HookType;");
- writer.AppendLine();
-
- writer.AppendLine("namespace TUnit.Generated.Hooks;");
- writer.AppendLine();
-
- using (writer.BeginBlock("public sealed class GeneratedHookRegistry"))
- {
- GenerateStaticConstructor(writer, validHooks);
-
- GenerateHookDelegates(writer, validHooks);
- }
-
- writer.AppendLine();
-
- using (writer.BeginBlock("internal static class HookModuleInitializer"))
- {
- writer.AppendLine("[global::System.Runtime.CompilerServices.ModuleInitializer]");
- using (writer.BeginBlock("public static void Initialize()"))
- {
- writer.AppendLine("_ = new GeneratedHookRegistry();");
- }
- }
-
- context.AddSource("GeneratedHookSource.g.cs", writer.ToString());
- }
- catch (Exception ex)
- {
- var descriptor = new DiagnosticDescriptor(
- "THG001",
- "Hook metadata generation failed",
- "Failed to generate hook metadata: {0}",
- "TUnit",
- DiagnosticSeverity.Error,
- isEnabledByDefault: true);
-
- context.ReportDiagnostic(Diagnostic.Create(descriptor, Location.None, ex.ToString()));
- }
- }
-
- private static void GenerateStaticConstructor(CodeWriter writer, List hooks)
- {
- using (writer.BeginBlock("static GeneratedHookRegistry()"))
- {
- writer.AppendLine("try");
- writer.AppendLine("{");
- writer.Indent();
- writer.AppendLine("PopulateSourcesDictionaries();");
- writer.Unindent();
- writer.AppendLine("}");
- writer.AppendLine("catch (Exception ex)");
- writer.AppendLine("{");
- writer.Indent();
- writer.AppendLine("throw new global::System.InvalidOperationException($\"Failed to initialize hook registry: {ex.Message}\", ex);");
- writer.Unindent();
- writer.AppendLine("}");
- }
-
- writer.AppendLine();
-
- using (writer.BeginBlock("private static void PopulateSourcesDictionaries()"))
- {
- var hooksByType = hooks.GroupBy(h => h.TypeSymbol, SymbolEqualityComparer.Default);
-
- foreach (var typeGroup in hooksByType)
- {
- var typeSymbol = (INamedTypeSymbol)typeGroup.Key!;
-
- var typeDisplay = typeSymbol.GloballyQualified();
-
- var testHooks = typeGroup.Where(h => h.HookType == "Test").ToList();
- var classHooks = typeGroup.Where(h => h.HookType == "Class").ToList();
-
- if (testHooks.Any())
- {
-
- var beforeTestHooks = testHooks.Where(h => h.HookKind == "Before").ToList();
- if (beforeTestHooks.Any())
- {
- GenerateHookListPopulation(writer, "BeforeTestHooks", typeDisplay, beforeTestHooks, isInstance: true);
- }
-
- var afterTestHooks = testHooks.Where(h => h.HookKind == "After").ToList();
- if (afterTestHooks.Any())
- {
- GenerateHookListPopulation(writer, "AfterTestHooks", typeDisplay, afterTestHooks, isInstance: true);
- }
-
- }
-
- if (classHooks.Any())
- {
-
- var beforeClassHooks = classHooks.Where(h => h.HookKind == "Before").ToList();
- if (beforeClassHooks.Any())
- {
- GenerateHookListPopulation(writer, "BeforeClassHooks", typeDisplay, beforeClassHooks, isInstance: false);
- }
-
- var afterClassHooks = classHooks.Where(h => h.HookKind == "After").ToList();
- if (afterClassHooks.Any())
- {
- GenerateHookListPopulation(writer, "AfterClassHooks", typeDisplay, afterClassHooks, isInstance: false);
- }
- }
- }
-
- // Handle global "Every" hooks for tests
- var globalBeforeEveryTestHooks = hooks.Where(h => h.HookType == "Test" && h.HookKind == "BeforeEvery").ToList();
- if (globalBeforeEveryTestHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "BeforeEveryTestHooks", globalBeforeEveryTestHooks);
- }
- var globalAfterEveryTestHooks = hooks.Where(h => h.HookType == "Test" && h.HookKind == "AfterEvery").ToList();
- if (globalAfterEveryTestHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "AfterEveryTestHooks", globalAfterEveryTestHooks);
- }
-
- // Handle global "Every" hooks for classes
- var globalBeforeEveryClassHooks = hooks.Where(h => h.HookType == "Class" && h.HookKind == "BeforeEvery").ToList();
- if (globalBeforeEveryClassHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "BeforeEveryClassHooks", globalBeforeEveryClassHooks);
- }
-
- var globalAfterEveryClassHooks = hooks.Where(h => h.HookType == "Class" && h.HookKind == "AfterEvery").ToList();
- if (globalAfterEveryClassHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "AfterEveryClassHooks", globalAfterEveryClassHooks);
- }
-
- var assemblyHookGroups = hooks.Where(h => h.HookType == "Assembly")
- .GroupBy(h => h.TypeSymbol.ContainingAssembly, SymbolEqualityComparer.Default);
-
- foreach (var assemblyGroup in assemblyHookGroups)
- {
- var assembly = (IAssemblySymbol)assemblyGroup.Key!;
- var assemblyName = assembly.Name;
-
- writer.AppendLine($"var {assemblyName.Replace(".", "_").Replace("-", "_")}_assembly = typeof({assemblyGroup.First().TypeSymbol.GloballyQualified()}).Assembly;");
-
- var beforeAssemblyHooks = assemblyGroup.Where(h => h.HookKind == "Before").ToList();
- if (beforeAssemblyHooks.Any())
- {
- GenerateAssemblyHookListPopulation(writer, "BeforeAssemblyHooks", assemblyName, beforeAssemblyHooks);
- }
-
- var afterAssemblyHooks = assemblyGroup.Where(h => h.HookKind == "After").ToList();
- if (afterAssemblyHooks.Any())
- {
- GenerateAssemblyHookListPopulation(writer, "AfterAssemblyHooks", assemblyName, afterAssemblyHooks);
- }
- }
-
- // Handle global "Every" hooks for assemblies
- var globalBeforeEveryAssemblyHooks = hooks.Where(h => h.HookType == "Assembly" && h.HookKind == "BeforeEvery").ToList();
- if (globalBeforeEveryAssemblyHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "BeforeEveryAssemblyHooks", globalBeforeEveryAssemblyHooks);
- }
-
- var globalAfterEveryAssemblyHooks = hooks.Where(h => h.HookType == "Assembly" && h.HookKind == "AfterEvery").ToList();
- if (globalAfterEveryAssemblyHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "AfterEveryAssemblyHooks", globalAfterEveryAssemblyHooks);
- }
-
- var testSessionHooks = hooks.Where(h => h.HookType == "TestSession").ToList();
- if (testSessionHooks.Any())
- {
-
- var beforeTestSessionHooks = testSessionHooks.Where(h => h.HookKind is "Before" or "BeforeEvery").ToList();
- if (beforeTestSessionHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "BeforeTestSessionHooks", beforeTestSessionHooks);
- }
-
- var afterTestSessionHooks = testSessionHooks.Where(h => h.HookKind is "After" or "AfterEvery").ToList();
- if (afterTestSessionHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "AfterTestSessionHooks", afterTestSessionHooks);
- }
- }
-
- var testDiscoveryHooks = hooks.Where(h => h.HookType == "TestDiscovery").ToList();
- if (testDiscoveryHooks.Any())
- {
-
- var beforeTestDiscoveryHooks = testDiscoveryHooks.Where(h => h.HookKind is "Before" or "BeforeEvery").ToList();
- if (beforeTestDiscoveryHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "BeforeTestDiscoveryHooks", beforeTestDiscoveryHooks);
- }
-
- var afterTestDiscoveryHooks = testDiscoveryHooks.Where(h => h.HookKind is "After" or "AfterEvery").ToList();
- if (afterTestDiscoveryHooks.Any())
- {
- GenerateGlobalHookListPopulation(writer, "AfterTestDiscoveryHooks", afterTestDiscoveryHooks);
- }
- }
- }
-
- writer.AppendLine();
- }
-
-
-
- private static void GenerateHookDelegates(CodeWriter writer, List hooks)
- {
-
- var uniqueMethods = hooks
- .GroupBy(h => h.MethodSymbol, SymbolEqualityComparer.Default)
- .Select(g => g.First());
-
- foreach (var hook in uniqueMethods)
- {
- GenerateHookDelegate(writer, hook);
- }
- }
private static void GenerateHookDelegate(CodeWriter writer, HookMethodMetadata hook)
{
@@ -745,51 +706,6 @@ private static void GenerateHookDelegate(CodeWriter writer, HookMethodMetadata h
writer.AppendLine();
}
- private static void GenerateHookListPopulation(CodeWriter writer, string dictionaryName, string typeDisplay, List hooks, bool isInstance)
- {
- var hookType = GetConcreteHookType(dictionaryName, isInstance);
- writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}.GetOrAdd(typeof({typeDisplay}), _ => new global::System.Collections.Concurrent.ConcurrentBag());");
-
- foreach (var hook in hooks.OrderBy(h => h.Order))
- {
- writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}[typeof({typeDisplay})].Add(");
- writer.Indent();
- GenerateHookObject(writer, hook, isInstance);
- writer.Unindent();
- writer.AppendLine(");");
- }
- writer.AppendLine();
- }
-
- private static void GenerateAssemblyHookListPopulation(CodeWriter writer, string dictionaryName, string assemblyVarName, List hooks)
- {
- var assemblyVar = assemblyVarName.Replace(".", "_").Replace("-", "_") + "_assembly";
- var hookType = GetConcreteHookType(dictionaryName, false);
- writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}.GetOrAdd({assemblyVar}, _ => new global::System.Collections.Concurrent.ConcurrentBag());");
-
- foreach (var hook in hooks.OrderBy(h => h.Order))
- {
- writer.AppendLine($"global::TUnit.Core.Sources.{dictionaryName}[{assemblyVar}].Add(");
- writer.Indent();
- GenerateHookObject(writer, hook, false);
- writer.Unindent();
- writer.AppendLine(");");
- }
- writer.AppendLine();
- }
-
- private static void GenerateGlobalHookListPopulation(CodeWriter writer, string listName, List hooks)
- {
- foreach (var hook in hooks.OrderBy(h => h.Order))
- {
- writer.AppendLine($"global::TUnit.Core.Sources.{listName}.Add(");
- writer.Indent();
- GenerateHookObject(writer, hook, false);
- writer.Unindent();
- writer.AppendLine(");");
- }
- writer.AppendLine();
- }
private static void GenerateHookObject(CodeWriter writer, HookMethodMetadata hook, bool isInstance)
{
diff --git a/TUnit.Core.SourceGenerator/Generators/PropertyInjectionSourceGenerator.cs b/TUnit.Core.SourceGenerator/Generators/PropertyInjectionSourceGenerator.cs
index b36551b079..08f1a47afd 100644
--- a/TUnit.Core.SourceGenerator/Generators/PropertyInjectionSourceGenerator.cs
+++ b/TUnit.Core.SourceGenerator/Generators/PropertyInjectionSourceGenerator.cs
@@ -18,9 +18,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.Where(x => x != null)
.Select((x, _) => x!);
- var collectedClasses = classesWithPropertyInjection.Collect();
-
- context.RegisterSourceOutput(collectedClasses, GeneratePropertyInjectionSources);
+ // Generate individual files for each class instead of collecting them all
+ context.RegisterSourceOutput(classesWithPropertyInjection, GenerateIndividualPropertyInjectionSource);
}
private static bool IsClassWithDataSourceProperties(SyntaxNode node)
@@ -132,41 +131,56 @@ private static bool IsPubliclyAccessible(INamedTypeSymbol typeSymbol)
return true;
}
- private static void GeneratePropertyInjectionSources(SourceProductionContext context, ImmutableArray classes)
+ private static void GenerateIndividualPropertyInjectionSource(SourceProductionContext context, ClassWithDataSourceProperties classInfo)
{
- if (classes.IsEmpty)
+ if (classInfo.Properties.Length == 0)
{
return;
}
- var sourceBuilder = new StringBuilder();
+ var sourceClassName = GetPropertySourceClassName(classInfo.ClassSymbol);
+ var safeName = GetSafeClassName(classInfo.ClassSymbol);
+ var fileName = $"{safeName}_PropertyInjection.g.cs";
+ var sourceBuilder = new StringBuilder();
WriteFileHeader(sourceBuilder);
+
+ // Generate individual module initializer for this class
+ GenerateIndividualModuleInitializer(sourceBuilder, classInfo, sourceClassName);
+
+ // Generate property source for this class
+ GeneratePropertySource(sourceBuilder, classInfo, sourceClassName);
+
+ context.AddSource(fileName, sourceBuilder.ToString());
+ }
- // Deduplicate classes by symbol to prevent duplicate source generation
- var uniqueClasses = classes
- .GroupBy(c => c.ClassSymbol, SymbolEqualityComparer.Default)
- .Select(g => g.First())
- .Where(x => x.Properties.Length > 0)
- .ToImmutableArray();
-
- // Generate all property sources first with stable names
- var classNameMapping = new Dictionary(SymbolEqualityComparer.Default);
- foreach (var classInfo in uniqueClasses)
- {
- var sourceClassName = GetPropertySourceClassName(classInfo.ClassSymbol);
- classNameMapping[classInfo.ClassSymbol] = sourceClassName;
- }
-
- GenerateModuleInitializer(sourceBuilder, uniqueClasses, classNameMapping);
-
- foreach (var classInfo in uniqueClasses)
- {
- GeneratePropertySource(sourceBuilder, classInfo, classNameMapping[classInfo.ClassSymbol]);
- }
-
+ private static string GetSafeClassName(INamedTypeSymbol classSymbol)
+ {
+ var fullyQualified = classSymbol.GloballyQualified();
+ return fullyQualified
+ .Replace("global::", "")
+ .Replace(".", "_")
+ .Replace("<", "_")
+ .Replace(">", "_")
+ .Replace(",", "_")
+ .Replace(" ", "")
+ .Replace("`", "_")
+ .Replace("+", "_");
+ }
- context.AddSource("PropertyInjectionSources.g.cs", sourceBuilder.ToString());
+ private static void GenerateIndividualModuleInitializer(StringBuilder sb, ClassWithDataSourceProperties classInfo, string sourceClassName)
+ {
+ var safeName = GetSafeClassName(classInfo.ClassSymbol);
+
+ sb.AppendLine($"internal static class {safeName}_PropertyInjectionInitializer");
+ sb.AppendLine("{");
+ sb.AppendLine(" [global::System.Runtime.CompilerServices.ModuleInitializer]");
+ sb.AppendLine(" public static void Initialize()");
+ sb.AppendLine(" {");
+ sb.AppendLine($" global::TUnit.Core.PropertySourceRegistry.Register(typeof({classInfo.ClassSymbol.GloballyQualified()}), new {sourceClassName}());");
+ sb.AppendLine(" }");
+ sb.AppendLine("}");
+ sb.AppendLine();
}
private static void WriteFileHeader(StringBuilder sb)
@@ -182,27 +196,6 @@ private static void WriteFileHeader(StringBuilder sb)
sb.AppendLine();
}
- private static void GenerateModuleInitializer(StringBuilder sb, ImmutableArray classes, Dictionary classNameMapping)
- {
- sb.AppendLine("internal static class PropertyInjectionInitializer");
- sb.AppendLine("{");
- sb.AppendLine(" [global::System.Runtime.CompilerServices.ModuleInitializer]");
- sb.AppendLine(" public static void InitializePropertyInjectionSources()");
- sb.AppendLine(" {");
-
- foreach (var classInfo in classes)
- {
- var sourceClassName = classNameMapping[classInfo.ClassSymbol];
- var classTypeName = classInfo.ClassSymbol.GloballyQualified();
- sb.AppendLine($" PropertySourceRegistry.Register(typeof({classTypeName}), new {sourceClassName}());");
- }
-
- sb.AppendLine(" }");
- sb.AppendLine();
-
- sb.AppendLine("}");
- sb.AppendLine();
- }
private static void GeneratePropertySource(StringBuilder sb, ClassWithDataSourceProperties classInfo, string sourceClassName)
{
diff --git a/TUnit.Core.SourceGenerator/Models/DynamicTestSourceDataModel.cs b/TUnit.Core.SourceGenerator/Models/DynamicTestSourceDataModel.cs
index 9fd5d8307b..6301acbf0c 100644
--- a/TUnit.Core.SourceGenerator/Models/DynamicTestSourceDataModel.cs
+++ b/TUnit.Core.SourceGenerator/Models/DynamicTestSourceDataModel.cs
@@ -16,8 +16,10 @@ public virtual bool Equals(DynamicTestSourceDataModel? other)
return true;
}
- return FilePath == other.FilePath
- && LineNumber == other.LineNumber;
+ return FilePath == other.FilePath &&
+ LineNumber == other.LineNumber &&
+ SymbolEqualityComparer.Default.Equals(Class, other.Class) &&
+ SymbolEqualityComparer.Default.Equals(Method, other.Method);
}
public override int GetHashCode()
@@ -27,6 +29,8 @@ public override int GetHashCode()
var hash = 17;
hash = hash * 31 + FilePath.GetHashCode();
hash = hash * 31 + LineNumber.GetHashCode();
+ hash = hash * 31 + SymbolEqualityComparer.Default.GetHashCode(Class);
+ hash = hash * 31 + SymbolEqualityComparer.Default.GetHashCode(Method);
return hash;
}
}
diff --git a/TUnit.Core.SourceGenerator/Models/HooksDataModel.cs b/TUnit.Core.SourceGenerator/Models/HooksDataModel.cs
index 12122df894..f93e1716a4 100644
--- a/TUnit.Core.SourceGenerator/Models/HooksDataModel.cs
+++ b/TUnit.Core.SourceGenerator/Models/HooksDataModel.cs
@@ -48,7 +48,13 @@ public override int GetHashCode()
var hashCode = FullyQualifiedTypeName.GetHashCode();
hashCode = (hashCode * 397) ^ MinimalTypeName.GetHashCode();
hashCode = (hashCode * 397) ^ MethodName.GetHashCode();
- hashCode = (hashCode * 397) ^ ParameterTypes.GetHashCode();
+
+ // Hash array contents, not array reference
+ foreach (var paramType in ParameterTypes)
+ {
+ hashCode = (hashCode * 397) ^ paramType.GetHashCode();
+ }
+
hashCode = (hashCode * 397) ^ HookLevel.GetHashCode();
return hashCode;
}
diff --git a/TUnit.Core.SourceGenerator/Models/PropertyInjectionContext.cs b/TUnit.Core.SourceGenerator/Models/PropertyInjectionContext.cs
index 51a85707c6..3e404365cf 100644
--- a/TUnit.Core.SourceGenerator/Models/PropertyInjectionContext.cs
+++ b/TUnit.Core.SourceGenerator/Models/PropertyInjectionContext.cs
@@ -5,10 +5,39 @@ namespace TUnit.Core.SourceGenerator.Models;
///
/// Context for property injection generation containing all necessary information
///
-public class PropertyInjectionContext
+public class PropertyInjectionContext : IEquatable
{
public required INamedTypeSymbol ClassSymbol { get; init; }
public required string ClassName { get; init; }
public required string SafeClassName { get; init; }
public DiagnosticContext? DiagnosticContext { get; init; }
+
+ public bool Equals(PropertyInjectionContext? other)
+ {
+ if (ReferenceEquals(null, other))
+ return false;
+ if (ReferenceEquals(this, other))
+ return true;
+
+ return SymbolEqualityComparer.Default.Equals(ClassSymbol, other.ClassSymbol) &&
+ ClassName == other.ClassName &&
+ SafeClassName == other.SafeClassName;
+ // Note: DiagnosticContext is not included in equality as it's contextual/runtime state
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return Equals(obj as PropertyInjectionContext);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ var hashCode = SymbolEqualityComparer.Default.GetHashCode(ClassSymbol);
+ hashCode = (hashCode * 397) ^ ClassName.GetHashCode();
+ hashCode = (hashCode * 397) ^ SafeClassName.GetHashCode();
+ return hashCode;
+ }
+ }
}
\ No newline at end of file
diff --git a/TUnit.Core.SourceGenerator/Models/TestDefinitionContext.cs b/TUnit.Core.SourceGenerator/Models/TestDefinitionContext.cs
index 3a6fd6a9c1..e97be27235 100644
--- a/TUnit.Core.SourceGenerator/Models/TestDefinitionContext.cs
+++ b/TUnit.Core.SourceGenerator/Models/TestDefinitionContext.cs
@@ -6,12 +6,13 @@ namespace TUnit.Core.SourceGenerator.Models;
/// Context used when building individual test definitions.
/// This is a subset of TestGenerationContext focused on what's needed for a single test.
///
-public class TestDefinitionContext
+public class TestDefinitionContext : IEquatable
{
public required TestMetadataGenerationContext GenerationContext { get; init; }
public required AttributeData? ClassDataAttribute { get; init; }
public required AttributeData? MethodDataAttribute { get; init; }
public required int TestIndex { get; init; }
+ public required int RepeatIndex { get; init; }
///
/// Creates contexts for all test definitions based on data attributes
@@ -29,18 +30,29 @@ public static IEnumerable CreateContexts(TestMetadataGene
.Where(attr => IsCompileTimeDataSourceAttribute(attr))
.ToList();
+ // Extract repeat count
+ var repeatCount = ExtractRepeatCount(testInfo.MethodSymbol);
+ if (repeatCount == 0)
+ {
+ repeatCount = 1; // Default to 1 if no repeat attribute
+ }
+
var testIndex = 0;
- // If no attributes, create one test with empty data providers
+ // If no attributes, create tests based on repeat count
if (!classDataAttrs.Any() && !methodDataAttrs.Any())
{
- yield return new TestDefinitionContext
+ for (var repeatIndex = 0; repeatIndex < repeatCount; repeatIndex++)
{
- GenerationContext = generationContext,
- ClassDataAttribute = null,
- MethodDataAttribute = null,
- TestIndex = testIndex
- };
+ yield return new TestDefinitionContext
+ {
+ GenerationContext = generationContext,
+ ClassDataAttribute = null,
+ MethodDataAttribute = null,
+ TestIndex = testIndex++,
+ RepeatIndex = repeatIndex
+ };
+ }
yield break;
}
@@ -49,13 +61,17 @@ public static IEnumerable CreateContexts(TestMetadataGene
{
foreach (var classAttr in classDataAttrs)
{
- yield return new TestDefinitionContext
+ for (var repeatIndex = 0; repeatIndex < repeatCount; repeatIndex++)
{
- GenerationContext = generationContext,
- ClassDataAttribute = classAttr,
- MethodDataAttribute = null,
- TestIndex = testIndex++
- };
+ yield return new TestDefinitionContext
+ {
+ GenerationContext = generationContext,
+ ClassDataAttribute = classAttr,
+ MethodDataAttribute = null,
+ TestIndex = testIndex++,
+ RepeatIndex = repeatIndex
+ };
+ }
}
}
// If we have method data but no class data
@@ -63,13 +79,17 @@ public static IEnumerable CreateContexts(TestMetadataGene
{
foreach (var methodAttr in methodDataAttrs)
{
- yield return new TestDefinitionContext
+ for (var repeatIndex = 0; repeatIndex < repeatCount; repeatIndex++)
{
- GenerationContext = generationContext,
- ClassDataAttribute = null,
- MethodDataAttribute = methodAttr,
- TestIndex = testIndex++
- };
+ yield return new TestDefinitionContext
+ {
+ GenerationContext = generationContext,
+ ClassDataAttribute = null,
+ MethodDataAttribute = methodAttr,
+ TestIndex = testIndex++,
+ RepeatIndex = repeatIndex
+ };
+ }
}
}
// If we have both class and method data - create cartesian product
@@ -79,18 +99,38 @@ public static IEnumerable CreateContexts(TestMetadataGene
{
foreach (var methodAttr in methodDataAttrs)
{
- yield return new TestDefinitionContext
+ for (var repeatIndex = 0; repeatIndex < repeatCount; repeatIndex++)
{
- GenerationContext = generationContext,
- ClassDataAttribute = classAttr,
- MethodDataAttribute = methodAttr,
- TestIndex = testIndex++
- };
+ yield return new TestDefinitionContext
+ {
+ GenerationContext = generationContext,
+ ClassDataAttribute = classAttr,
+ MethodDataAttribute = methodAttr,
+ TestIndex = testIndex++,
+ RepeatIndex = repeatIndex
+ };
+ }
}
}
}
}
+ private static int ExtractRepeatCount(IMethodSymbol methodSymbol)
+ {
+ var repeatAttribute = methodSymbol.GetAttributes()
+ .FirstOrDefault(a => a.AttributeClass?.Name == "RepeatAttribute");
+
+ if (repeatAttribute is { ConstructorArguments.Length: > 0 })
+ {
+ if (repeatAttribute.ConstructorArguments[0].Value is int count)
+ {
+ return count;
+ }
+ }
+
+ return 0;
+ }
+
private static bool IsCompileTimeDataSourceAttribute(AttributeData attr)
{
var attrName = attr.AttributeClass?.Name;
@@ -118,4 +158,59 @@ private static bool IsCompileTimeDataSourceAttribute(AttributeData attr)
return false;
}
+
+ public bool Equals(TestDefinitionContext? other)
+ {
+ if (ReferenceEquals(null, other))
+ return false;
+ if (ReferenceEquals(this, other))
+ return true;
+
+ return GenerationContext.Equals(other.GenerationContext) &&
+ AttributeDataEquals(ClassDataAttribute, other.ClassDataAttribute) &&
+ AttributeDataEquals(MethodDataAttribute, other.MethodDataAttribute) &&
+ TestIndex == other.TestIndex &&
+ RepeatIndex == other.RepeatIndex;
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return Equals(obj as TestDefinitionContext);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ var hashCode = GenerationContext.GetHashCode();
+ hashCode = (hashCode * 397) ^ AttributeDataGetHashCode(ClassDataAttribute);
+ hashCode = (hashCode * 397) ^ AttributeDataGetHashCode(MethodDataAttribute);
+ hashCode = (hashCode * 397) ^ TestIndex;
+ hashCode = (hashCode * 397) ^ RepeatIndex;
+ return hashCode;
+ }
+ }
+
+ private static bool AttributeDataEquals(AttributeData? x, AttributeData? y)
+ {
+ if (ReferenceEquals(x, y)) return true;
+ if (x is null || y is null) return false;
+
+ return SymbolEqualityComparer.Default.Equals(x.AttributeClass, y.AttributeClass) &&
+ x.ConstructorArguments.Length == y.ConstructorArguments.Length &&
+ x.ConstructorArguments.Zip(y.ConstructorArguments, (a, b) => TypedConstantEquals(a, b)).All(eq => eq);
+ }
+
+ private static bool TypedConstantEquals(TypedConstant x, TypedConstant y)
+ {
+ if (x.Kind != y.Kind) return false;
+ if (!SymbolEqualityComparer.Default.Equals(x.Type, y.Type)) return false;
+ return Equals(x.Value, y.Value);
+ }
+
+ private static int AttributeDataGetHashCode(AttributeData? attr)
+ {
+ if (attr is null) return 0;
+ return SymbolEqualityComparer.Default.GetHashCode(attr.AttributeClass);
+ }
}
diff --git a/TUnit.Core.SourceGenerator/Models/TestMetadataGenerationContext.cs b/TUnit.Core.SourceGenerator/Models/TestMetadataGenerationContext.cs
index 789d7ccc2d..45041f01e5 100644
--- a/TUnit.Core.SourceGenerator/Models/TestMetadataGenerationContext.cs
+++ b/TUnit.Core.SourceGenerator/Models/TestMetadataGenerationContext.cs
@@ -6,7 +6,7 @@ namespace TUnit.Core.SourceGenerator.Models;
/// Encapsulates all the context needed for test metadata generation, avoiding long parameter lists
/// and making it easier to pass state between components.
///
-public class TestMetadataGenerationContext
+public class TestMetadataGenerationContext : IEquatable
{
public required TestMethodMetadata TestInfo { get; init; }
public required string ClassName { get; init; }
@@ -16,7 +16,6 @@ public class TestMetadataGenerationContext
public required bool HasParameterlessConstructor { get; init; }
public required string SafeClassName { get; init; }
public required string SafeMethodName { get; init; }
- public required string Guid { get; init; }
public required bool CanUseStaticDefinition { get; init; }
///
@@ -57,7 +56,6 @@ public static TestMetadataGenerationContext Create(TestMethodMetadata testInfo)
HasParameterlessConstructor = hasParameterlessConstructor,
SafeClassName = safeClassName,
SafeMethodName = safeMethodName,
- Guid = System.Guid.NewGuid().ToString("N"),
CanUseStaticDefinition = DetermineIfStaticTestDefinition(testInfo)
};
}
@@ -228,4 +226,43 @@ private static bool IsRuntimeDataSourceAttribute(AttributeData attr, ITypeSymbol
return false;
}
+
+ public bool Equals(TestMetadataGenerationContext? other)
+ {
+ if (ReferenceEquals(null, other))
+ return false;
+ if (ReferenceEquals(this, other))
+ return true;
+
+ return TestInfo.Equals(other.TestInfo) &&
+ ClassName == other.ClassName &&
+ MethodName == other.MethodName &&
+ RequiredProperties.SequenceEqual(other.RequiredProperties, SymbolEqualityComparer.Default) &&
+ SymbolEqualityComparer.Default.Equals(ConstructorWithParameters, other.ConstructorWithParameters) &&
+ HasParameterlessConstructor == other.HasParameterlessConstructor &&
+ SafeClassName == other.SafeClassName &&
+ SafeMethodName == other.SafeMethodName &&
+ CanUseStaticDefinition == other.CanUseStaticDefinition;
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return Equals(obj as TestMetadataGenerationContext);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ var hashCode = TestInfo.GetHashCode();
+ hashCode = (hashCode * 397) ^ ClassName.GetHashCode();
+ hashCode = (hashCode * 397) ^ MethodName.GetHashCode();
+ hashCode = (hashCode * 397) ^ (ConstructorWithParameters != null ? SymbolEqualityComparer.Default.GetHashCode(ConstructorWithParameters) : 0);
+ hashCode = (hashCode * 397) ^ HasParameterlessConstructor.GetHashCode();
+ hashCode = (hashCode * 397) ^ SafeClassName.GetHashCode();
+ hashCode = (hashCode * 397) ^ SafeMethodName.GetHashCode();
+ hashCode = (hashCode * 397) ^ CanUseStaticDefinition.GetHashCode();
+ return hashCode;
+ }
+ }
}
diff --git a/TUnit.Core.SourceGenerator/Models/TestMethodMetadata.cs b/TUnit.Core.SourceGenerator/Models/TestMethodMetadata.cs
index c37b401bc8..e97d4fb74c 100644
--- a/TUnit.Core.SourceGenerator/Models/TestMethodMetadata.cs
+++ b/TUnit.Core.SourceGenerator/Models/TestMethodMetadata.cs
@@ -7,7 +7,7 @@ namespace TUnit.Core.SourceGenerator.Models;
///
/// Contains all the metadata about a test method discovered by the source generator.
///
-public class TestMethodMetadata
+public class TestMethodMetadata : IEquatable
{
public required IMethodSymbol MethodSymbol { get; init; }
public required INamedTypeSymbol TypeSymbol { get; init; }
@@ -31,4 +31,42 @@ public class TestMethodMetadata
/// 2 = method is inherited from base's base class, etc.
///
public int InheritanceDepth { get; init; } = 0;
+
+ public bool Equals(TestMethodMetadata? other)
+ {
+ if (ReferenceEquals(null, other))
+ return false;
+ if (ReferenceEquals(this, other))
+ return true;
+
+ return SymbolEqualityComparer.Default.Equals(MethodSymbol, other.MethodSymbol) &&
+ SymbolEqualityComparer.Default.Equals(TypeSymbol, other.TypeSymbol) &&
+ FilePath == other.FilePath &&
+ LineNumber == other.LineNumber &&
+ IsGenericType == other.IsGenericType &&
+ IsGenericMethod == other.IsGenericMethod &&
+ InheritanceDepth == other.InheritanceDepth;
+ // Note: Skipping MethodAttributes comparison to avoid complexity - these rarely change independently
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return Equals(obj as TestMethodMetadata);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ var hashCode = SymbolEqualityComparer.Default.GetHashCode(MethodSymbol);
+ hashCode = (hashCode * 397) ^ SymbolEqualityComparer.Default.GetHashCode(TypeSymbol);
+ hashCode = (hashCode * 397) ^ FilePath.GetHashCode();
+ hashCode = (hashCode * 397) ^ LineNumber;
+ hashCode = (hashCode * 397) ^ IsGenericType.GetHashCode();
+ hashCode = (hashCode * 397) ^ IsGenericMethod.GetHashCode();
+ hashCode = (hashCode * 397) ^ InheritanceDepth;
+ return hashCode;
+ }
+ }
+
}
diff --git a/TUnit.Core.SourceGenerator/Models/TypeWithDataSourceProperties.cs b/TUnit.Core.SourceGenerator/Models/TypeWithDataSourceProperties.cs
new file mode 100644
index 0000000000..b95834a9f4
--- /dev/null
+++ b/TUnit.Core.SourceGenerator/Models/TypeWithDataSourceProperties.cs
@@ -0,0 +1,9 @@
+using Microsoft.CodeAnalysis;
+
+namespace TUnit.Core.SourceGenerator.Models;
+
+public struct TypeWithDataSourceProperties
+{
+ public INamedTypeSymbol TypeSymbol { get; init; }
+ public List Properties { get; init; }
+}
diff --git a/TUnit.Core/DynamicTest.cs b/TUnit.Core/AbstractDynamicTest.cs
similarity index 87%
rename from TUnit.Core/DynamicTest.cs
rename to TUnit.Core/AbstractDynamicTest.cs
index f4a9428d6a..afa495adcb 100644
--- a/TUnit.Core/DynamicTest.cs
+++ b/TUnit.Core/AbstractDynamicTest.cs
@@ -35,40 +35,40 @@ public class DynamicDiscoveryResult : DiscoveryResult
| DynamicallyAccessedMemberTypes.PublicFields
| DynamicallyAccessedMemberTypes.NonPublicFields)]
public Type? TestClassType { get; set; }
-
+
///
/// The file path where the dynamic test was created
///
public string? CreatorFilePath { get; set; }
-
+
///
/// The line number where the dynamic test was created
///
public int? CreatorLineNumber { get; set; }
}
-public abstract class DynamicTest
+public abstract class AbstractDynamicTest
{
public abstract IEnumerable GetTests();
}
-public abstract class DynamicTest<[DynamicallyAccessedMembers(
+public abstract class AbstractDynamicTest<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.NonPublicConstructors
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.NonPublicMethods
| DynamicallyAccessedMemberTypes.PublicFields
- | DynamicallyAccessedMemberTypes.NonPublicFields)] T> : DynamicTest where T : class;
+ | DynamicallyAccessedMemberTypes.NonPublicFields)] T> : AbstractDynamicTest where T : class;
-public class DynamicTestInstance<[DynamicallyAccessedMembers(
+public class DynamicTest<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicConstructors
| DynamicallyAccessedMemberTypes.NonPublicConstructors
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.NonPublicMethods
| DynamicallyAccessedMemberTypes.PublicFields
- | DynamicallyAccessedMemberTypes.NonPublicFields)]T> : DynamicTest, IDynamicTestCreatorLocation where T : class
+ | DynamicallyAccessedMemberTypes.NonPublicFields)]T> : AbstractDynamicTest, IDynamicTestCreatorLocation where T : class
{
public Expression>? TestMethod { get; set; }
public object?[]? TestClassArguments { get; set; }
@@ -76,12 +76,12 @@ public class DynamicTestInstance<[DynamicallyAccessedMembers(
public List Attributes { get; set; } =
[
];
-
+
///
/// The file path where this dynamic test was created
///
public string? CreatorFilePath { get; set; }
-
+
///
/// The line number where this dynamic test was created
///
@@ -111,7 +111,7 @@ public static class DynamicTestHelper
public interface IDynamicTestSource
{
- IReadOnlyList CollectDynamicTests(string sessionId);
+ IReadOnlyList CollectDynamicTests(string sessionId);
}
public class FailedDynamicTest<[DynamicallyAccessedMembers(
@@ -119,7 +119,7 @@ public class FailedDynamicTest<[DynamicallyAccessedMembers(
| DynamicallyAccessedMemberTypes.NonPublicConstructors
| DynamicallyAccessedMemberTypes.PublicProperties
| DynamicallyAccessedMemberTypes.PublicMethods
- | DynamicallyAccessedMemberTypes.NonPublicMethods)] T> : DynamicTest where T : class
+ | DynamicallyAccessedMemberTypes.NonPublicMethods)] T> : AbstractDynamicTest where T : class
{
public string TestId { get; set; } = string.Empty;
public string MethodName { get; set; } = string.Empty;
diff --git a/TUnit.Core/AbstractExecutableTest.cs b/TUnit.Core/AbstractExecutableTest.cs
index a6c8f1def4..fbbf55ca5e 100644
--- a/TUnit.Core/AbstractExecutableTest.cs
+++ b/TUnit.Core/AbstractExecutableTest.cs
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
+using TUnit.Core.Models;
namespace TUnit.Core;
@@ -30,6 +31,11 @@ public required TestContext Context
public ResolvedDependency[] Dependencies { get; set; } = [];
+ ///
+ /// Execution context information for this test, used to coordinate class hooks properly
+ ///
+ public TestExecutionContext? ExecutionContext { get; set; }
+
public TestState State { get; set; } = TestState.NotStarted;
public TestResult? Result
@@ -44,63 +50,31 @@ public DateTimeOffset? StartTime
set => Context.TestStart = value ?? DateTimeOffset.UtcNow;
}
- private readonly object _executionLock = new();
-
- internal Func? ExecutorDelegate { get; set; }
-
- internal CancellationToken ExecutionCancellationToken { get; set; }
-
///
- /// Gets the task representing this test's execution.
- /// The task is started lazily on first access in a thread-safe manner.
+ /// Gets the task representing this test's execution, set directly by the scheduler.
///
- [field: AllowNull, MaybeNull]
- public Task ExecutionTask
- {
- get
- {
- lock (_executionLock)
- {
- if (field == null)
- {
- if (ExecutorDelegate == null)
- {
- field = Task.FromException(new InvalidOperationException(
- $"Test {TestId} execution was accessed before executor was set"));
- }
- else
- {
- field = Task.Run(async () =>
- {
- try
- {
- await ExecutorDelegate(this, ExecutionCancellationToken).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- Debug.WriteLine($"Test {TestId} execution failed: {ex}");
- }
- });
- }
- }
- return field;
- }
- }
- }
+ public Task? ExecutionTask { get; internal set; }
- ///
- /// Allows the scheduler to trigger execution if not already started
- ///
- internal void EnsureStarted()
- {
- _ = ExecutionTask;
- }
-
- public Task CompletionTask => ExecutionTask;
+ public Task CompletionTask => ExecutionTask ?? Task.CompletedTask;
public DateTimeOffset? EndTime { get => Context.TestEnd; set => Context.TestEnd = value; }
public TimeSpan? Duration => StartTime.HasValue && EndTime.HasValue
? EndTime.Value - StartTime.Value
: null;
+
+ public void SetResult(TestState state, Exception? exception = null)
+ {
+ State = state;
+ Context.Result ??= new TestResult
+ {
+ State = state,
+ Exception = exception,
+ ComputerName = Environment.MachineName,
+ Duration = Duration,
+ End = EndTime ??= DateTimeOffset.UtcNow,
+ Start = StartTime ??= DateTimeOffset.UtcNow,
+ Output = Context.GetOutput() + Environment.NewLine + Environment.NewLine + Context.GetErrorOutput()
+ };
+ }
}
diff --git a/TUnit.Core/Attributes/RunOnDiscoveryAttribute.cs b/TUnit.Core/Attributes/RunOnDiscoveryAttribute.cs
deleted file mode 100644
index 7693dfa381..0000000000
--- a/TUnit.Core/Attributes/RunOnDiscoveryAttribute.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using TUnit.Core.Interfaces;
-
-namespace TUnit.Core;
-
-public class RunOnDiscoveryAttribute : TUnitAttribute, ITestDiscoveryEventReceiver
-{
- public int Order => 0;
-
- public ValueTask OnTestDiscovered(DiscoveredTestContext context)
- {
- context.SetRunOnDiscovery(true);
- return default(ValueTask);
- }
-}
diff --git a/TUnit.Core/Attributes/TestData/AsyncDataSourceGeneratorAttribute.cs b/TUnit.Core/Attributes/TestData/AsyncDataSourceGeneratorAttribute.cs
index 33bedebb74..3826979471 100644
--- a/TUnit.Core/Attributes/TestData/AsyncDataSourceGeneratorAttribute.cs
+++ b/TUnit.Core/Attributes/TestData/AsyncDataSourceGeneratorAttribute.cs
@@ -12,16 +12,16 @@ public override async IAsyncEnumerable>> GetTypedDataRowsAsync(Data
{
// Inject properties into the data source attribute itself if we have context
// This is needed for custom data sources that have their own data source properties
- if (dataGeneratorMetadata is { TestBuilderContext: not null, TestInformation: not null })
+ if (dataGeneratorMetadata is { TestInformation: not null })
{
- await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
- dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
- dataGeneratorMetadata.TestInformation,
+ await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
+ dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
+ dataGeneratorMetadata.TestInformation,
dataGeneratorMetadata.TestBuilderContext.Current.Events);
}
-
+
await ObjectInitializer.InitializeAsync(this);
-
+
await foreach (var generateDataSource in GenerateDataSourcesAsync(dataGeneratorMetadata))
{
yield return generateDataSource;
@@ -41,16 +41,16 @@ public abstract class AsyncDataSourceGeneratorAttribute<
public override async IAsyncEnumerable>> GetTypedDataRowsAsync(DataGeneratorMetadata dataGeneratorMetadata)
{
// Inject properties into the data source attribute itself if we have context
- if (dataGeneratorMetadata is { TestBuilderContext: not null, TestInformation: not null })
+ if (dataGeneratorMetadata is { TestInformation: not null })
{
- await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
- dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
- dataGeneratorMetadata.TestInformation,
+ await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
+ dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
+ dataGeneratorMetadata.TestInformation,
dataGeneratorMetadata.TestBuilderContext.Current.Events);
}
-
+
await ObjectInitializer.InitializeAsync(this);
-
+
await foreach (var generateDataSource in GenerateDataSourcesAsync(dataGeneratorMetadata))
{
yield return generateDataSource;
@@ -72,16 +72,16 @@ public abstract class AsyncDataSourceGeneratorAttribute<
public override async IAsyncEnumerable>> GetTypedDataRowsAsync(DataGeneratorMetadata dataGeneratorMetadata)
{
// Inject properties into the data source attribute itself if we have context
- if (dataGeneratorMetadata is { TestBuilderContext: not null, TestInformation: not null })
+ if (dataGeneratorMetadata is { TestInformation: not null })
{
- await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
- dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
- dataGeneratorMetadata.TestInformation,
+ await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
+ dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
+ dataGeneratorMetadata.TestInformation,
dataGeneratorMetadata.TestBuilderContext.Current.Events);
}
-
+
await ObjectInitializer.InitializeAsync(this);
-
+
await foreach (var generateDataSource in GenerateDataSourcesAsync(dataGeneratorMetadata))
{
yield return generateDataSource;
@@ -105,16 +105,16 @@ public abstract class AsyncDataSourceGeneratorAttribute<
public override async IAsyncEnumerable>> GetTypedDataRowsAsync(DataGeneratorMetadata dataGeneratorMetadata)
{
// Inject properties into the data source attribute itself if we have context
- if (dataGeneratorMetadata is { TestBuilderContext: not null, TestInformation: not null })
+ if (dataGeneratorMetadata is { TestInformation: not null })
{
- await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
- dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
- dataGeneratorMetadata.TestInformation,
+ await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
+ dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
+ dataGeneratorMetadata.TestInformation,
dataGeneratorMetadata.TestBuilderContext.Current.Events);
}
-
+
await ObjectInitializer.InitializeAsync(this);
-
+
await foreach (var generateDataSource in GenerateDataSourcesAsync(dataGeneratorMetadata))
{
yield return generateDataSource;
@@ -140,16 +140,16 @@ public abstract class AsyncDataSourceGeneratorAttribute<
public override async IAsyncEnumerable>> GetTypedDataRowsAsync(DataGeneratorMetadata dataGeneratorMetadata)
{
// Inject properties into the data source attribute itself if we have context
- if (dataGeneratorMetadata is { TestBuilderContext: not null, TestInformation: not null })
+ if (dataGeneratorMetadata is { TestInformation: not null })
{
- await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
- dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
- dataGeneratorMetadata.TestInformation,
+ await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this,
+ dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag,
+ dataGeneratorMetadata.TestInformation,
dataGeneratorMetadata.TestBuilderContext.Current.Events);
}
-
+
await ObjectInitializer.InitializeAsync(this);
-
+
await foreach (var generateDataSource in GenerateDataSourcesAsync(dataGeneratorMetadata))
{
yield return generateDataSource;
diff --git a/TUnit.Core/Attributes/TestData/AsyncUntypedDataSourceSourceGeneratorAttribute.cs b/TUnit.Core/Attributes/TestData/AsyncUntypedDataSourceSourceGeneratorAttribute.cs
index ba6ec867de..7dfd686d8d 100644
--- a/TUnit.Core/Attributes/TestData/AsyncUntypedDataSourceSourceGeneratorAttribute.cs
+++ b/TUnit.Core/Attributes/TestData/AsyncUntypedDataSourceSourceGeneratorAttribute.cs
@@ -11,7 +11,7 @@ public abstract class AsyncUntypedDataSourceGeneratorAttribute : Attribute, IAsy
public async IAsyncEnumerable>> GenerateAsync(DataGeneratorMetadata dataGeneratorMetadata)
{
- if (dataGeneratorMetadata is { TestBuilderContext: not null, TestInformation: not null })
+ if (dataGeneratorMetadata is { TestInformation: not null })
{
await PropertyInjectionService.InjectPropertiesIntoObjectAsync(this, dataGeneratorMetadata.TestBuilderContext.Current.ObjectBag, dataGeneratorMetadata.TestInformation, dataGeneratorMetadata.TestBuilderContext.Current.Events);
}
diff --git a/TUnit.Core/Attributes/TestData/ClassDataSources.cs b/TUnit.Core/Attributes/TestData/ClassDataSources.cs
index 3d5eebd623..b5fb3d1a97 100644
--- a/TUnit.Core/Attributes/TestData/ClassDataSources.cs
+++ b/TUnit.Core/Attributes/TestData/ClassDataSources.cs
@@ -12,7 +12,7 @@ private ClassDataSources()
{
}
- public static readonly GetOnlyDictionary SourcesPerSession = new();
+ public static readonly ThreadSafeDictionary SourcesPerSession = new();
public static ClassDataSources Get(string sessionId)
{
diff --git a/TUnit.Core/Attributes/TestMetadata/SkipAttribute.cs b/TUnit.Core/Attributes/TestMetadata/SkipAttribute.cs
index 32ff38f936..0b5b7e6feb 100644
--- a/TUnit.Core/Attributes/TestMetadata/SkipAttribute.cs
+++ b/TUnit.Core/Attributes/TestMetadata/SkipAttribute.cs
@@ -22,6 +22,7 @@ public async ValueTask OnTestRegistered(TestRegisteredContext context)
{
// Store skip reason directly on TestContext
context.TestContext.SkipReason = Reason;
+ context.TestContext.TestDetails.ClassInstance = SkippedTestInstance.Instance;
}
}
diff --git a/TUnit.Core/Context.cs b/TUnit.Core/Context.cs
index 2818b8dcf7..3d3b972b5e 100644
--- a/TUnit.Core/Context.cs
+++ b/TUnit.Core/Context.cs
@@ -49,12 +49,12 @@ public void RestoreExecutionContext()
{
ExecutionContext.Restore(ExecutionContext);
}
-
- RestoreContextAsyncLocal();
+
+ SetAsyncLocalContext();
#endif
}
- internal abstract void RestoreContextAsyncLocal();
+ internal abstract void SetAsyncLocalContext();
public void AddAsyncLocalValues()
{
diff --git a/TUnit.Core/Contexts/DiscoveredTestContext.cs b/TUnit.Core/Contexts/DiscoveredTestContext.cs
index 6346885cb3..e589c5437c 100644
--- a/TUnit.Core/Contexts/DiscoveredTestContext.cs
+++ b/TUnit.Core/Contexts/DiscoveredTestContext.cs
@@ -12,7 +12,6 @@ public class DiscoveredTestContext
public TestContext TestContext { get; }
public TestDetails TestDetails => TestContext.TestDetails;
- public bool RunOnTestDiscovery { get; private set; }
public DiscoveredTestContext(string testName, TestContext testContext)
{
@@ -71,11 +70,6 @@ public void AddArgumentDisplayFormatter(ArgumentDisplayFormatter formatter)
TestContext.ArgumentDisplayFormatters.Add(obj => formatter.CanHandle(obj) ? formatter.FormatValue(obj) : null);
}
- public void SetRunOnDiscovery(bool runOnDiscovery)
- {
- RunOnTestDiscovery = runOnDiscovery;
- }
-
public void SetPriority(Priority priority)
{
TestContext.ExecutionPriority = priority;
diff --git a/TUnit.Core/Data/ScopedDictionary.cs b/TUnit.Core/Data/ScopedDictionary.cs
index 3e7c924530..ebb3a1ab1b 100644
--- a/TUnit.Core/Data/ScopedDictionary.cs
+++ b/TUnit.Core/Data/ScopedDictionary.cs
@@ -5,11 +5,11 @@ namespace TUnit.Core.Data;
public class ScopedDictionary
where TScope : notnull
{
- private readonly GetOnlyDictionary> _scopedContainers = new();
+ private readonly ThreadSafeDictionary> _scopedContainers = new();
public object? GetOrCreate(TScope scope, Type type, Func factory)
{
- var innerDictionary = _scopedContainers.GetOrAdd(scope, _ => new GetOnlyDictionary());
+ var innerDictionary = _scopedContainers.GetOrAdd(scope, _ => new ThreadSafeDictionary());
var obj = innerDictionary.GetOrAdd(type, factory);
diff --git a/TUnit.Core/Data/GetOnlyDictionary.cs b/TUnit.Core/Data/ThreadSafeDictionary.cs
similarity index 97%
rename from TUnit.Core/Data/GetOnlyDictionary.cs
rename to TUnit.Core/Data/ThreadSafeDictionary.cs
index 2d88debfa2..85db43b39e 100644
--- a/TUnit.Core/Data/GetOnlyDictionary.cs
+++ b/TUnit.Core/Data/ThreadSafeDictionary.cs
@@ -7,7 +7,7 @@ namespace TUnit.Core.Data;
#if !DEBUG
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
#endif
-public class GetOnlyDictionary
where TKey : notnull
{
diff --git a/TUnit.Core/DynamicTestBuilderContext.cs b/TUnit.Core/DynamicTestBuilderContext.cs
index a857986bef..25d5225fec 100644
--- a/TUnit.Core/DynamicTestBuilderContext.cs
+++ b/TUnit.Core/DynamicTestBuilderContext.cs
@@ -5,7 +5,7 @@ namespace TUnit.Core;
///
public class DynamicTestBuilderContext
{
- private readonly List _tests =
+ private readonly List _tests =
[
];
@@ -18,9 +18,9 @@ public DynamicTestBuilderContext(string filePath, int lineNumber)
public string FilePath { get; }
public int LineNumber { get; }
- public IReadOnlyList Tests => _tests.AsReadOnly();
+ public IReadOnlyList Tests => _tests.AsReadOnly();
- public void AddTest(DynamicTest test)
+ public void AddTest(AbstractDynamicTest test)
{
// Set creator location if the test implements IDynamicTestCreatorLocation
if (test is IDynamicTestCreatorLocation testWithLocation)
diff --git a/TUnit.Core/Exceptions/CircularDependencyException.cs b/TUnit.Core/Exceptions/CircularDependencyException.cs
new file mode 100644
index 0000000000..54ee878c6e
--- /dev/null
+++ b/TUnit.Core/Exceptions/CircularDependencyException.cs
@@ -0,0 +1,19 @@
+namespace TUnit.Core.Exceptions;
+
+///
+/// Exception thrown when circular test dependencies are detected.
+///
+public class CircularDependencyException : Exception
+{
+ public CircularDependencyException() : base()
+ {
+ }
+
+ public CircularDependencyException(string message) : base(message)
+ {
+ }
+
+ public CircularDependencyException(string message, Exception innerException) : base(message, innerException)
+ {
+ }
+}
\ No newline at end of file
diff --git a/TUnit.Core/Extensions/TestContextExtensions.cs b/TUnit.Core/Extensions/TestContextExtensions.cs
index 1373cb2c48..ba50b41e97 100644
--- a/TUnit.Core/Extensions/TestContextExtensions.cs
+++ b/TUnit.Core/Extensions/TestContextExtensions.cs
@@ -31,7 +31,7 @@ public static string GetClassTypeName(this TestContext context)
| DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.NonPublicMethods
| DynamicallyAccessedMemberTypes.PublicFields
- | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this TestContext context, DynamicTestInstance dynamicTest) where T : class
+ | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(this TestContext context, DynamicTest dynamicTest) where T : class
{
await context.GetService()!.AddDynamicTest(context, dynamicTest);;
}
diff --git a/TUnit.Core/Interfaces/ITestRegistry.cs b/TUnit.Core/Interfaces/ITestRegistry.cs
index 5c6cda9889..51305ece09 100644
--- a/TUnit.Core/Interfaces/ITestRegistry.cs
+++ b/TUnit.Core/Interfaces/ITestRegistry.cs
@@ -21,6 +21,6 @@ public interface ITestRegistry
| DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.NonPublicMethods
| DynamicallyAccessedMemberTypes.PublicFields
- | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(TestContext context, DynamicTestInstance dynamicTest)
+ | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(TestContext context, DynamicTest dynamicTest)
where T : class;
}
\ No newline at end of file
diff --git a/TUnit.Core/Models/AssemblyHookContext.cs b/TUnit.Core/Models/AssemblyHookContext.cs
index 4d149d2ab9..9387037a49 100644
--- a/TUnit.Core/Models/AssemblyHookContext.cs
+++ b/TUnit.Core/Models/AssemblyHookContext.cs
@@ -10,7 +10,11 @@ public class AssemblyHookContext : Context
public static new AssemblyHookContext? Current
{
get => Contexts.Value;
- internal set => Contexts.Value = value;
+ internal set
+ {
+ Contexts.Value = value;
+ TestSessionContext.Current = value?.TestSessionContext;
+ }
}
internal AssemblyHookContext(TestSessionContext testSessionContext) : base(testSessionContext)
@@ -47,7 +51,7 @@ internal void RemoveClass(ClassHookContext classContext)
}
}
- internal override void RestoreContextAsyncLocal()
+ internal override void SetAsyncLocalContext()
{
Current = this;
}
diff --git a/TUnit.Core/Models/BeforeTestDiscoveryContext.cs b/TUnit.Core/Models/BeforeTestDiscoveryContext.cs
index 3eb1b2e003..5a1044c19a 100644
--- a/TUnit.Core/Models/BeforeTestDiscoveryContext.cs
+++ b/TUnit.Core/Models/BeforeTestDiscoveryContext.cs
@@ -29,7 +29,7 @@ internal BeforeTestDiscoveryContext() : base(GlobalContext.Current)
///
public required string? TestFilter { get; init; }
- internal override void RestoreContextAsyncLocal()
+ internal override void SetAsyncLocalContext()
{
Current = this;
}
diff --git a/TUnit.Core/Models/ClassHookContext.cs b/TUnit.Core/Models/ClassHookContext.cs
index f477b7ee26..14e96c35b1 100644
--- a/TUnit.Core/Models/ClassHookContext.cs
+++ b/TUnit.Core/Models/ClassHookContext.cs
@@ -10,7 +10,11 @@ public class ClassHookContext : Context
public static new ClassHookContext? Current
{
get => Contexts.Value;
- internal set => Contexts.Value = value;
+ internal set
+ {
+ Contexts.Value = value;
+ AssemblyHookContext.Current = value?.AssemblyContext;
+ }
}
internal ClassHookContext(AssemblyHookContext assemblyHookContext) : base(assemblyHookContext)
@@ -79,7 +83,7 @@ internal void RemoveTest(TestContext test)
}
}
- internal override void RestoreContextAsyncLocal()
+ internal override void SetAsyncLocalContext()
{
Current = this;
}
diff --git a/TUnit.Core/Models/GlobalContext.cs b/TUnit.Core/Models/GlobalContext.cs
index 00562e3474..57834c4ae2 100644
--- a/TUnit.Core/Models/GlobalContext.cs
+++ b/TUnit.Core/Models/GlobalContext.cs
@@ -33,7 +33,7 @@ internal Disposer Disposer
set;
}
- internal override void RestoreContextAsyncLocal()
+ internal override void SetAsyncLocalContext()
{
Current = this;
}
diff --git a/TUnit.Core/Models/TestDiscoveryContext.cs b/TUnit.Core/Models/TestDiscoveryContext.cs
index 9d8fab220a..5996e44e3c 100644
--- a/TUnit.Core/Models/TestDiscoveryContext.cs
+++ b/TUnit.Core/Models/TestDiscoveryContext.cs
@@ -35,7 +35,7 @@ public void AddTests(IEnumerable tests)
public IReadOnlyList AllTests { get; private set; } = [];
- internal override void RestoreContextAsyncLocal()
+ internal override void SetAsyncLocalContext()
{
Current = this;
}
diff --git a/TUnit.Core/Models/TestExecutionContext.cs b/TUnit.Core/Models/TestExecutionContext.cs
new file mode 100644
index 0000000000..83043f0165
--- /dev/null
+++ b/TUnit.Core/Models/TestExecutionContext.cs
@@ -0,0 +1,48 @@
+namespace TUnit.Core.Models;
+
+///
+/// Represents the execution context for tests, indicating how they should be coordinated
+///
+public enum ExecutionContextType
+{
+ ///
+ /// Tests can run in full parallel without coordination
+ ///
+ Parallel,
+
+ ///
+ /// Tests must run sequentially, one at a time globally
+ ///
+ NotInParallel,
+
+ ///
+ /// Tests must run sequentially within the same key
+ ///
+ KeyedNotInParallel,
+
+ ///
+ /// Tests run in parallel groups with internal ordering
+ ///
+ ParallelGroup
+}
+
+///
+/// Execution context information for a test, used to coordinate class hooks properly
+///
+public record TestExecutionContext
+{
+ public required ExecutionContextType ContextType { get; init; }
+
+ ///
+ /// For KeyedNotInParallel: the constraint key
+ /// For ParallelGroup: the group name
+ /// Null for other types
+ ///
+ public string? GroupKey { get; init; }
+
+ ///
+ /// For ParallelGroup: the execution order within the group
+ /// Null for other types
+ ///
+ public int? Order { get; init; }
+}
\ No newline at end of file
diff --git a/TUnit.Core/Models/TestSessionContext.cs b/TUnit.Core/Models/TestSessionContext.cs
index d844696fb0..09598aa39d 100644
--- a/TUnit.Core/Models/TestSessionContext.cs
+++ b/TUnit.Core/Models/TestSessionContext.cs
@@ -6,7 +6,11 @@ public class TestSessionContext : Context
public static new TestSessionContext? Current
{
get => Contexts.Value;
- internal set => Contexts.Value = value;
+ internal set
+ {
+ Contexts.Value = value;
+ TestDiscoveryContext.Current = value?.TestDiscoveryContext;
+ }
}
///
@@ -47,7 +51,7 @@ internal TestSessionContext(TestDiscoveryContext beforeTestDiscoveryContext) : b
Current = this;
}
- public BeforeTestDiscoveryContext TestDiscoveryContext => (BeforeTestDiscoveryContext) Parent!;
+ public TestDiscoveryContext TestDiscoveryContext => (TestDiscoveryContext) Parent!;
public required string Id { get; init; }
@@ -80,7 +84,7 @@ internal void RemoveAssembly(AssemblyHookContext assemblyContext)
_assemblies.Remove(assemblyContext);
}
- internal override void RestoreContextAsyncLocal()
+ internal override void SetAsyncLocalContext()
{
Current = this;
}
diff --git a/TUnit.Core/ParallelLimitLockProvider.cs b/TUnit.Core/ParallelLimitLockProvider.cs
index 4580af3e32..a69b982917 100644
--- a/TUnit.Core/ParallelLimitLockProvider.cs
+++ b/TUnit.Core/ParallelLimitLockProvider.cs
@@ -5,7 +5,7 @@ namespace TUnit.Core;
public class ParallelLimitLockProvider
{
- private readonly GetOnlyDictionary _locks = new();
+ private readonly ThreadSafeDictionary _locks = new();
internal SemaphoreSlim GetLock(IParallelLimit parallelLimit)
{
diff --git a/TUnit.Core/PropertyInjectionService.cs b/TUnit.Core/PropertyInjectionService.cs
index 63eaa1286e..5fadb44f01 100644
--- a/TUnit.Core/PropertyInjectionService.cs
+++ b/TUnit.Core/PropertyInjectionService.cs
@@ -21,9 +21,9 @@ internal sealed class PropertyInjectionPlan
public sealed class PropertyInjectionService
{
- private static readonly GetOnlyDictionary