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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,7 @@ doc/plans/
*speedscope*.json

# Dotnet trace files
*.nettrace
*.nettrace

# Git worktrees
.worktrees/
11 changes: 10 additions & 1 deletion TUnit.Core/TestMetadata`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class TestMetadata<
{
private Func<Type[], object?[], T>? _instanceFactory;
private Func<T, object?[], Task>? _testInvoker;
private Func<ExecutableTestCreationContext, TestMetadata, AbstractExecutableTest>? _cachedExecutableTestFactory;

/// <summary>
/// Strongly typed instance factory
Expand Down Expand Up @@ -63,10 +64,16 @@ public override Func<ExecutableTestCreationContext, TestMetadata, AbstractExecut
{
get
{
// Return cached factory if available
if (_cachedExecutableTestFactory != null)
{
return _cachedExecutableTestFactory;
}

// For AOT mode, create delegates from the strongly-typed ones
if (InstanceFactory != null && InvokeTypedTest != null)
{
return (context, metadata) =>
_cachedExecutableTestFactory = (context, metadata) =>
{
var typedMetadata = (TestMetadata<T>)metadata;

Expand Down Expand Up @@ -109,6 +116,8 @@ public override Func<ExecutableTestCreationContext, TestMetadata, AbstractExecut
Context = context.Context
};
};

return _cachedExecutableTestFactory;
}

throw new InvalidOperationException($"InstanceFactory and InvokeTypedTest must be set for {typeof(T).Name}");
Expand Down
Loading