Skip to content

Commit

Permalink
Fix for TUnit v0.10 Signature Changes (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhurst authored Feb 3, 2025
1 parent 47b9156 commit 1c9ad5b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
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

0 comments on commit 1c9ad5b

Please # to comment.