fix: xUnit code fixer bugs for Assert.Single, Assert.Collection, and Assert.All#4821
fix: xUnit code fixer bugs for Assert.Single, Assert.Collection, and Assert.All#4821
Conversation
Code ReviewI found one architectural issue that affects both code paths in this PR: 🔴 Missing
|
…Assert.All (#4805, #4806, #4811) - Assert.Single with predicate now converts to .Where(predicate).HasSingleItem() instead of dropping the predicate lambda - Assert.Collection TODO comment now preserves element inspector code so assertions aren't silently lost during migration - Assert.All with multi-statement lambda bodies no longer produces invalid TUnit code; skips conversion when predicate can't be extracted Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5875ecf to
fc02525
Compare
|
The review concern about missing All tests pass after rebase (13 assertion code fixer tests, 67 migration analyzer tests). |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. The PR successfully fixes three xUnit migration bugs:
All logic changes are correct and improve the migration tooling without introducing any regressions. |
Summary
Fixes three xUnit code fixer bugs reported in #4805, #4806, and #4811:
Assert.Single(collection, predicate)now correctly converts toAssert.That(collection.Where(predicate)).HasSingleItem()instead of silently dropping the predicateAssert.Collectionassertions #4806 - Assert.Collection drops element inspectors: The TODO comment now preserves the full text of each element inspector (e.g.[0]: x => Assert.Equal(1, x)) so assertions aren't silently lost during migrationAssert.Allwith item action #4811 - Assert.All produces invalid code: WhenAssert.Allhas a multi-statement lambda body that can't be converted to a simple predicate, the two-phase analyzer now skips conversion instead of producing invalidAssert.That(items).All(item => { Assert.True(...); })codeBoth the assertion code fixer (
XUnitAssertionCodeFixProvider) and the two-phase migration analyzer (XUnitTwoPhaseAnalyzer) are updated where applicable.Test plan
Assert.Singlewith and without predicate in assertion code fixerAssert_Collection_Adds_Todo_Commenttest updated to match improved TODO message🤖 Generated with Claude Code