|
1 |
| -namespace TUnit.Core.Hooks; |
| 1 | +using System.Diagnostics.CodeAnalysis; |
| 2 | +using System.Reflection; |
| 3 | +using TUnit.Core.Extensions; |
| 4 | +using TUnit.Core.Interfaces; |
2 | 5 |
|
3 |
| -public class HookMethod |
| 6 | +namespace TUnit.Core.Hooks; |
| 7 | + |
| 8 | +#if !DEBUG |
| 9 | +[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] |
| 10 | +#endif |
| 11 | +public abstract record HookMethod |
4 | 12 | {
|
5 |
| - public StaticHookMethod? StaticHookMethod { get; } |
6 |
| - public InstanceHookMethod? InstanceHookMethod { get; } |
| 13 | + public required MethodMetadata MethodInfo { get; init; } |
| 14 | + |
| 15 | + [field: AllowNull, MaybeNull] |
| 16 | + public string Name => field ??= $"{ClassType.Name}.{MethodInfo.Name}({string.Join(", ", MethodInfo.Parameters.Select(x => x.Name))})"; |
| 17 | + |
| 18 | + public abstract Type ClassType { get; } |
| 19 | + public virtual Assembly? Assembly => ClassType?.Assembly; |
| 20 | + |
| 21 | + [field: AllowNull, MaybeNull] |
| 22 | + public IEnumerable<Attribute> Attributes => field ??= MethodInfo.GetCustomAttributes(); |
| 23 | + |
| 24 | + public TAttribute? GetAttribute<TAttribute>() where TAttribute : Attribute => Attributes.OfType<TAttribute>().FirstOrDefault(); |
7 | 25 |
|
8 |
| - public HookMethod(InstanceHookMethod instanceHookMethod) |
9 |
| - { |
10 |
| - InstanceHookMethod = instanceHookMethod; |
11 |
| - } |
| 26 | + /// <summary> |
| 27 | + /// Gets the timeout for this hook method. This will be set during hook registration |
| 28 | + /// by the event receiver infrastructure, falling back to the default 5-minute timeout. |
| 29 | + /// </summary> |
| 30 | + public TimeSpan? Timeout { get; internal set; } = TimeSpan.FromMinutes(5); |
12 | 31 |
|
13 |
| - public HookMethod(StaticHookMethod staticHookMethod) |
14 |
| - { |
15 |
| - StaticHookMethod = staticHookMethod; |
16 |
| - } |
| 32 | + public required IHookExecutor HookExecutor { get; init; } |
17 | 33 |
|
18 |
| - public static implicit operator HookMethod(InstanceHookMethod instanceHookMethod) => new(instanceHookMethod); |
19 |
| - public static implicit operator HookMethod(StaticHookMethod staticHookMethod) => new(staticHookMethod); |
| 34 | + public required int Order { get; init; } |
| 35 | + |
| 36 | + public required int RegistrationIndex { get; init; } |
20 | 37 | }
|
0 commit comments