Skip to content

feat: add TestFixAll method to CodeFixTestFixture#18

Merged
Arthurvdv merged 2 commits into
masterfrom
feature/testfixall
Apr 29, 2026
Merged

feat: add TestFixAll method to CodeFixTestFixture#18
Arthurvdv merged 2 commits into
masterfrom
feature/testfixall

Conversation

@Arthurvdv

@Arthurvdv Arthurvdv commented Apr 29, 2026

Copy link
Copy Markdown
Member

Summary

Adds FixAll testing support to CodeFixTestFixture to catch bugs where individual code fixes work but applying all fixes simultaneously fails (e.g., overlapping text changes silently dropped by BatchFixer).

New Public API

// Primary: markup with [| |] markers + expected output + diagnostic ID
fixture.TestFixAll(markupCode, expectedCode, diagnosticId);

// With DiagnosticDescriptor
fixture.TestFixAll(markupCode, expectedCode, DiagnosticDescriptors.Rule);

How it works

  1. Parses [| |] markers to identify expected diagnostic locations
  2. Runs the analyzer, asserts diagnostic count matches marker count
  3. Auto-detects EquivalenceKey from the first diagnostic's CodeAction
  4. Creates a FixAllContext with a custom DiagnosticProvider at FixAllScope.Document scope
  5. Invokes the CodeFix's real FixAllProvider.GetFixAsync()
  6. Compares the result against the expected code string

Files changed

File Change
TestDiagnosticProvider.cs New: implements FixAllContext.DiagnosticProvider
CodeFixTestFixture.cs Add TestFixAll overloads
RoslynTestKitException.cs Add FixAll-specific error factories
README.md Add TestFixAll examples and update folder structure

Arthurvdv and others added 2 commits April 29, 2026 09:50
Add FixAll testing support to catch bugs where individual code fixes work
but applying all fixes simultaneously fails (e.g., overlapping text changes
silently dropped by BatchFixer).

New public API:
- CodeFixTestFixture.TestFixAll(markupCode, expected, diagnosticId)
- CodeFixTestFixture.TestFixAll(markupCode, expected, descriptor)

Implementation:
- TestDiagnosticProvider: implements FixAllContext.DiagnosticProvider for
  feeding pre-computed diagnostics to the FixAll infrastructure
- Auto-detects EquivalenceKey from first diagnostic's CodeAction
- Asserts marker count matches diagnostic count
- Uses FixAllScope.Document, tests the CodeFix's real FixAllProvider

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Arthurvdv Arthurvdv merged commit e6c14c5 into master Apr 29, 2026
1 check passed
@Arthurvdv Arthurvdv deleted the feature/testfixall branch April 29, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant