Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1),
Expand Down Expand Up @@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2),
Expand Down Expand Up @@ -119,7 +119,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3),
Expand Down Expand Up @@ -161,7 +161,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
Expand Down Expand Up @@ -202,7 +202,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
Expand Down Expand Up @@ -252,7 +252,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
Expand Down Expand Up @@ -302,7 +302,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1),
Expand Down Expand Up @@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2),
Expand Down Expand Up @@ -119,7 +119,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3),
Expand Down Expand Up @@ -161,7 +161,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
Expand Down Expand Up @@ -202,7 +202,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
Expand Down Expand Up @@ -252,7 +252,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
Expand Down Expand Up @@ -302,7 +302,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase1)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase1),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase1),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalBase1),
Expand Down Expand Up @@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase2)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase2),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase2),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalBase2),
Expand Down Expand Up @@ -119,7 +119,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalBase3)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase3),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalBase3),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalBase3),
Expand Down Expand Up @@ -161,7 +161,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
Expand Down Expand Up @@ -202,7 +202,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
Expand Down Expand Up @@ -252,7 +252,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
Expand Down Expand Up @@ -302,7 +302,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
InitClassType = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1),
Expand Down Expand Up @@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2),
Expand Down Expand Up @@ -119,7 +119,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3),
Expand Down Expand Up @@ -161,7 +161,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
Expand Down Expand Up @@ -202,7 +202,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
Expand Down Expand Up @@ -252,7 +252,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
Expand Down Expand Up @@ -302,7 +302,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
InitClassType = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.BeforeTestHooks[typeof(global::TUnit.TestProject.DisposableFieldTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.DisposableFieldTests),
InitClassType = typeof(global::TUnit.TestProject.DisposableFieldTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.DisposableFieldTests),
Expand Down Expand Up @@ -77,7 +77,7 @@ public sealed class GeneratedHookRegistry
global::TUnit.Core.Sources.AfterTestHooks[typeof(global::TUnit.TestProject.DisposableFieldTests)].Add(
new InstanceHookMethod
{
ClassType = typeof(global::TUnit.TestProject.DisposableFieldTests),
InitClassType = typeof(global::TUnit.TestProject.DisposableFieldTests),
MethodInfo = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.DisposableFieldTests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void Execute(ICodeWriter sourceBuilder, HooksDataModel model)

sourceBuilder.Append("new global::TUnit.Core.Hooks.InstanceHookMethod");
sourceBuilder.Append("{");
sourceBuilder.Append($"ClassType = typeof({model.FullyQualifiedTypeName}),");
sourceBuilder.Append($"InitClassType = typeof({model.FullyQualifiedTypeName}),");
sourceBuilder.Append("MethodInfo = ");
SourceInformationWriter.GenerateMethodInformation(sourceBuilder, model.Context.SemanticModel.Compilation, model.ClassType, model.Method, null, ',');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ private static void GenerateHookObject(CodeWriter writer, HookMethodMetadata hoo

if (isInstance)
{
writer.AppendLine($"ClassType = typeof({hook.TypeSymbol.GloballyQualified()}),");
writer.AppendLine($"InitClassType = typeof({hook.TypeSymbol.GloballyQualified()}),");
}

writer.Append("MethodInfo = ");
Expand Down
9 changes: 8 additions & 1 deletion TUnit.Core/Attributes/TestMetadata/TimeoutAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace TUnit.Core;
/// </code>
/// </example>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
public class TimeoutAttribute(int timeoutInMilliseconds) : TUnitAttribute, ITestDiscoveryEventReceiver, IScopedAttribute<TimeoutAttribute>
public class TimeoutAttribute(int timeoutInMilliseconds) : TUnitAttribute, ITestDiscoveryEventReceiver, IHookRegisteredEventReceiver, IScopedAttribute<TimeoutAttribute>
{
/// <inheritdoc />
public int Order => 0;
Expand All @@ -49,4 +49,11 @@ public ValueTask OnTestDiscovered(DiscoveredTestContext context)
context.TestDetails.Timeout = Timeout;
return default(ValueTask);
}

/// <inheritdoc />
public ValueTask OnHookRegistered(HookRegisteredContext context)
{
context.Timeout = Timeout;
return default(ValueTask);
}
}
28 changes: 28 additions & 0 deletions TUnit.Core/Contexts/HookRegisteredContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using TUnit.Core.Hooks;

namespace TUnit.Core;

/// <summary>
/// Context for hook registration phase
/// </summary>
public class HookRegisteredContext
{
private TimeSpan? _timeout;

public HookMethod HookMethod { get; }
public string HookName => HookMethod.Name;

/// <summary>
/// Gets or sets the timeout for this hook
/// </summary>
public TimeSpan? Timeout
{
get => _timeout;
set => _timeout = value;
}

public HookRegisteredContext(HookMethod hookMethod)
{
HookMethod = hookMethod;
}
}
Loading
Loading