Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for TUnit v0.10 Signature Changes #1394

Merged
merged 1 commit into from
Feb 3, 2025
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
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<PackageVersion Include="System.IO.Hashing" Version="9.0.1" />
<PackageVersion Include="System.Memory" Version="4.6.0" />
<PackageVersion Include="TextCopy" Version="6.2.1" />
<PackageVersion Include="TUnit" Version="0.7.9" />
<PackageVersion Include="TUnit.Core" Version="0.7.9" />
<PackageVersion Include="TUnit" Version="0.10.6" />
<PackageVersion Include="TUnit.Core" Version="0.10.6" />
<PackageVersion Include="Xunit" Version="2.9.3" />
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
<PackageVersion Include="xunit.extensibility.execution" Version="2.9.3" />
Expand Down
13 changes: 7 additions & 6 deletions src/Verify.TUnit/TUnitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ static class TUnitExtensions
{
public static IReadOnlyList<string>? GetParameterNames(this TestDetails details)
{
var methodParameterNames = details.MethodInfo.ParameterNames();
var methodParameterNames = details.TestMethod.Parameters.Select(x => x.Name).ToList();

var constructorParameterNames = GetConstructorParameterNames(details);
if (methodParameterNames == null)
if (methodParameterNames.Count is 0)
{
if (constructorParameterNames.Count == 0)
{
Expand All @@ -26,12 +26,13 @@ static class TUnitExtensions

static List<string> GetConstructorParameterNames(TestDetails details)
{
var constructors = details.ClassType.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
if (constructors.Length <= 1)
var parameters = details.TestClass.Parameters;
if (parameters.Length is 0)
{
return constructors[0].GetParameters().Select(_ => _.Name!).ToList();
return [];
}

throw new("Found multiple constructors. Unable to derive names of parameters. Instead use UseParameters to pass in explicit parameter.");
return parameters.Select(_ => _.Name).ToList();

}
}
6 changes: 3 additions & 3 deletions src/Verify.TUnit/Verifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b
}

var details = TestContext.Current!.TestDetails;
var type = details.ClassType;
var type = details.TestClass.Type;
var classArguments = details.TestClassArguments;
var methodArguments = details.TestMethodArguments;
if (!settings.HasParameters &&
Expand All @@ -42,8 +42,8 @@ static InnerVerifier BuildVerifier(string sourceFile, VerifySettings settings, b

VerifierSettings.AssignTargetAssembly(type.Assembly);

var method = details.MethodInfo;
var pathInfo = GetPathInfo(sourceFile, type, method);
var method = details.TestMethod;
var pathInfo = GetPathInfo(sourceFile, type, method.ReflectionInformation);
return new(
sourceFile,
settings,
Expand Down
2 changes: 1 addition & 1 deletion src/Verify.TUnit/VerifyChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class VerifyChecks
public static Task Run()
{
var details = TestContext.Current!.TestDetails;
var type = details.ClassType;
var type = details.TestClass.Type;
VerifierSettings.AssignTargetAssembly(type.Assembly);
return InnerVerifyChecks.Run(type.Assembly);
}
Expand Down