Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst committed Feb 20, 2025
1 parent fd9ac6f commit bb36ad6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ file partial class Hooks_BaseTests : global::TUnit.Core.Interfaces.SourceGenerat
Properties = [],
}),
},
Body = (classInstance, context, cancellationToken) => ((dynamic)classInstance).Setup(),
Body = (classInstance, context, cancellationToken) => typeof(global::TUnit.TestProject.Bugs._1589.BaseTests<>).GetMethod("Setup", []).Invoke(classInstance, []),
HookExecutor = DefaultExecutor.Instance,
Order = 0,
MethodAttributes =
Expand Down
4 changes: 2 additions & 2 deletions TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ file partial class Hooks_ParentTests : global::TUnit.Core.Interfaces.SourceGener
Properties = [],
}),
},
Body = (classInstance, context, cancellationToken) => ((dynamic)classInstance).SetupParentTests(),
Body = (classInstance, context, cancellationToken) => typeof(global::TUnit.TestProject.Bugs._1594.ParentTests<>).GetMethod("SetupParentTests", []).Invoke(classInstance, []),
HookExecutor = DefaultExecutor.Instance,
Order = 0,
MethodAttributes =
Expand Down Expand Up @@ -295,7 +295,7 @@ file partial class Hooks_GrandParentTests : global::TUnit.Core.Interfaces.Source
Properties = [],
}),
},
Body = (classInstance, context, cancellationToken) => ((dynamic)classInstance).SetupBase(),
Body = (classInstance, context, cancellationToken) => typeof(global::TUnit.TestProject.Bugs._1594.GrandParentTests<>).GetMethod("SetupBase", []).Invoke(classInstance, []),
HookExecutor = DefaultExecutor.Instance,
Order = 0,
MethodAttributes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ file partial class Hooks_BaseClass : global::TUnit.Core.Interfaces.SourceGenerat
Properties = [],
}),
},
Body = (classInstance, context, cancellationToken) => ((dynamic)classInstance).Setup(),
Body = (classInstance, context, cancellationToken) => typeof(global::TUnit.TestProject.Library.Bugs._1899.BaseClass<>).GetMethod("Setup", []).Invoke(classInstance, []),
HookExecutor = DefaultExecutor.Instance,
Order = 0,
MethodAttributes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ public static void Execute(SourceCodeWriter sourceBuilder, HooksDataModel model)
}
else
{
sourceBuilder.WriteLine($"Body = (classInstance, context, cancellationToken) => ((typeof({model.FullyQualifiedTypeName}))classInstance).{model.MethodName}({GetArgs(model)}),");
sourceBuilder.WriteLine($"Body = (classInstance, context, cancellationToken) => (({model.FullyQualifiedTypeName})classInstance).{model.MethodName}({GetArgs(model)}),");
}
}
else
{
if (model.ClassType.IsGenericDefinition())
{
sourceBuilder.WriteLine($"AsyncBody = (classInstance, context, cancellationToken) => await ((global::System.Threading.Tasks.Task) typeof({model.FullyQualifiedTypeName}).GetMethod(\"{model.MethodName}\", [{string.Join(", ", model.ParameterTypes.Select(x => $"typeof({x})"))}]).Invoke(classInstance, {GetArgsOrEmptyArray(model)})),");
sourceBuilder.WriteLine($"AsyncBody = (classInstance, context, cancellationToken) => AsyncConvert.Convert(() => typeof({model.FullyQualifiedTypeName}).GetMethod(\"{model.MethodName}\", [{string.Join(", ", model.ParameterTypes.Select(x => $"typeof({x})"))}]).Invoke(classInstance, {GetArgsOrEmptyArray(model)})),");
}
else
{
sourceBuilder.WriteLine($"AsyncBody = (classInstance, context, cancellationToken) => AsyncConvert.Convert(() => ((typeof({model.FullyQualifiedTypeName}))classInstance).{model.MethodName}({GetArgs(model)})),");
sourceBuilder.WriteLine($"AsyncBody = (classInstance, context, cancellationToken) => AsyncConvert.Convert(() => (({model.FullyQualifiedTypeName})classInstance).{model.MethodName}({GetArgs(model)})),");
}
}

Expand Down

0 comments on commit bb36ad6

Please sign in to comment.