fix: multiple migration code fixer issues#4347
Conversation
Fixes #4333 - xUnit Assert.Same now converts to IsSameReferenceAs (not IsSameReference) Fixes #4331 - xUnit Assert.Throws now has proper await keyword spacing Fixes #4330 - System.Threading.Tasks using is now added for async methods Fixes #4338 - NUnit [Ignore] attribute now converts to [Skip] Fixes #4343 - NUnit [Theory] and [Description] attributes now handled Fixes #4341 - Methods with ref/out/in parameters are no longer converted to async Changes: - XUnitMigrationCodeFixProvider: Fixed IsSameReferenceAs method names, added proper await keyword trivia to ConvertThrows/ThrowsAsync/ThrowsAny/IsType methods - MigrationHelpers: Added AddSystemThreadingTasksUsing method, added NUnit Theory and Description mappings, added Ignore -> Skip mapping - BaseMigrationCodeFixProvider: Always add System.Threading.Tasks for async code - AsyncMethodSignatureRewriter: Skip methods with ref/out/in parameters - NUnitMigrationCodeFixProvider: Added Theory and Description to IsFrameworkAttribute - Updated XUnit tests to expect System.Threading.Tasks using directive Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryFixes multiple migration code fixer issues including Assert.Same conversion, await keyword spacing, System.Threading.Tasks using, NUnit Ignore/Theory/Description attributes, and ref/out parameter handling. Critical IssuesNone found ✅ Suggestions1. Missing Test Coverage for ref/out Parameter FixThe fix in [Test]
public async Task Method_With_Ref_Parameter_Not_Converted_To_Async()
{
await CodeFixer.VerifyCodeFixAsync(
"""
{|#0:using NUnit.Framework;
public class MyClass
{
private static void HandleRealized(object sender, ref bool realized)
{
Assert.AreSame(sender, sender);
realized = true;
}
}|}
""",
Verifier.Diagnostic(Rules.NUnitMigration).WithLocation(0),
"""
using TUnit.Core;
using TUnit.Assertions;
using static TUnit.Assertions.Assert;
using TUnit.Assertions.Extensions;
public class MyClass
{
// Method should remain non-async due to ref parameter
private static void HandleRealized(object sender, ref bool realized)
{
Assert.That(sender).IsSameReferenceAs(sender).Wait();
realized = true;
}
}
""",
ConfigureNUnitTest
);
}2. Consider Extracting
|
Updated Assert_Same_Can_Be_Converted and Assert_NotSame_Can_Be_Converted tests to include the using System.Threading.Tasks directive that the code fixer now adds for async methods. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryThis PR fixes multiple migration code fixer issues including await keyword spacing, System.Threading.Tasks using directive addition, NUnit Ignore/Theory/Description attribute handling, and prevention of async conversion for methods with ref/out/in parameters. Critical IssuesNone found ✅ All changes are analyzer/code fixer improvements that don't touch core engine code, so TUnit's critical rules (dual-mode, AOT, VSTest, performance) don't apply here. Suggestions1. Missing Test Coverage for ref/out/in Parameter Fix (Important)The fix in Recommendation: Add a test case to verify methods with ref/out/in parameters are not converted to async: [Test]
public async Task NUnit_Method_With_Ref_Parameter_Not_Converted_To_Async()
{
await CodeFixer.VerifyCodeFixAsync(
"""
using NUnit.Framework;
{|#0:public class MyClass|}
{
private static void HandleRealized(object sender, ref bool realized)
{
Assert.AreSame(sender, sender);
realized = true;
}
}
""",
Verifier.Diagnostic(Rules.NUnitMigration).WithLocation(0),
"""
using TUnit.Core;
using TUnit.Assertions;
using static TUnit.Assertions.Assert;
using TUnit.Assertions.Extensions;
public class MyClass
{
// Should remain non-async due to ref parameter
private static void HandleRealized(object sender, ref bool realized)
{
Assert.That(sender).IsSameReferenceAs(sender).Wait();
realized = true;
}
}
""",
ConfigureNUnitTest
);
}2. Missing Test Coverage for await Keyword Spacing FixThe fix in Recommendation: Consider adding a test that explicitly validates the spacing in generated code for 3.
|
- Add NUnit_Method_With_Ref_Parameter_Not_Converted_To_Async test - Add NUnit_Method_With_Out_Parameter_Not_Converted_To_Async test - Ensure methods with ref/out/in parameters use .Wait() instead of await - Update AssertionRewriter base class to track method context for async eligibility - Update NUnitMigrationCodeFixProvider to use WrapAssertionForAsync consistently This addresses the PR review comment requesting test coverage for issue #4341. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryFixes multiple migration code fixer issues including reference assertion naming, await keyword spacing, using directive handling for async methods, and handling of methods with ref/out/in parameters. Critical IssuesNone found ✅ SuggestionsPre-existing bug in MSTest migrator (not blocking this PR)The MSTest migrator uses incorrect assertion names Reference: Verdict✅ APPROVE - No critical issues This PR successfully addresses all the issues mentioned:
The implementation is well-tested with comprehensive test coverage. The code is clean and follows TUnit patterns. No TUnit rule violations detected. |
…xer-issues Resolved conflict in NUnitMigrationAnalyzerTests.cs by keeping all three test cases: ref/out parameter tests from PR and InterfaceImplementation test from main. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryFixes multiple issues in xUnit and NUnit migration code fixers, including correct assertion conversions, async keyword spacing, proper handling of ref/out/in parameters, and System.Threading.Tasks using directive management. Critical IssuesNone found ✅ Suggestions1. Duplicate await keyword creation in XUnitMigrationCodeFixProvider.csThe XUnit migration code fixes duplicate the await keyword creation logic in multiple places instead of using the inherited Locations:
Why this matters: XUnit tests won't have ref/out/in parameters in practice (xUnit doesn't support them), so this works. However, the inconsistency with the NUnit code (which properly uses Suggestion: Consider using 2. Inconsistent variable namingIn var awaitKeyword2 = SyntaxFactory.Token(SyntaxKind.AwaitKeyword)This appears to be a copy-paste artifact and could simply be Verdict✅ APPROVE - No critical issues. The PR correctly fixes all the reported bugs. The suggestions are minor maintainability improvements that don't affect correctness. |
…tion The Assert_All_Can_Be_Converted test expected output now includes the System.Threading.Tasks using directive, which is correctly added by the code fixer when converting methods to async Task. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryFixes multiple migration code fixer issues: Assert.Same conversion, await keyword spacing, System.Threading.Tasks using directive handling, NUnit attribute mappings, and proper handling of methods with ref/out/in parameters. Critical IssuesNone found - No TUnit rules apply (analyzer-only changes) Suggestions
VerdictAPPROVE - All reported bugs fixed with good test coverage for most changes |
- Added Platform attribute handling from main - Kept ref/out parameter tests from this branch - All tests pass Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SummaryFixes multiple migration code fixer issues including handling of ref/out/in parameters, Theory attribute, and await keyword spacing. Critical IssuesNone found ✅ SuggestionsPragmatic Exception to "NEVER block on async" RuleThe PR introduces
Recommendation: Consider documenting this exception in CLAUDE.md or mandatory-rules.md to clarify when blocking on async is acceptable: **NEVER block on async** - No `.Result` or `.GetAwaiter().GetResult()`.
Exception: Code generation/migration tools may use `.Wait()` when targeting methods that cannot be async (e.g., methods with ref/out/in parameters).This would prevent future confusion and make the trade-off explicit. Test CoverageThe PR includes comprehensive test coverage for the ref/out parameter scenarios. Well done on the thorough testing approach! Verdict✅ APPROVE - No critical issues The |
Summary
Fixes multiple issues in the xUnit and NUnit migration code fixers:
Assert.Samenow converts toIsSameReferenceAs(notIsSameReference)Assert.Throwsnow has proper await keyword spacing (was generatingawaitAssert.ThrowsAsync)System.Threading.Tasksusing is now added for async methods even whenShouldAddTUnitUsings()is false[Ignore]attribute not converted to[Skip]#4338 - NUnit[Ignore]attribute now converts to[Skip][Theory]and[Description]attributes not converted #4343 - NUnit[Theory]and[Description]attributes now handledref/out/inparameters are no longer incorrectly converted to asyncTest plan
🤖 Generated with Claude Code