Skip to content

fix: #4807 xUnit Assert.Contains predicate parameter transposition#4813

Merged
thomhurst merged 2 commits intothomhurst:mainfrom
ascott18:ascott/xunit-assert-contains
Feb 15, 2026
Merged

fix: #4807 xUnit Assert.Contains predicate parameter transposition#4813
thomhurst merged 2 commits intothomhurst:mainfrom
ascott18:ascott/xunit-assert-contains

Conversation

@ascott18
Copy link
Contributor

Description

XUnitTwoPhaseAnalyzer was missing logic that exists in XUnitMigrationCodeFixProvider for translating xunit's Contains with predicates

Related Issue

Fixes #4807

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Performance improvement
  • Refactoring (no functional changes)

Checklist

Required

  • I have read the Contributing Guidelines
  • If this is a new feature, I started a discussion first and received agreement
  • My code follows the project's code style (modern C# syntax, proper naming conventions)
  • I have written tests that prove my fix is effective or my feature works

TUnit-Specific Requirements

  • Dual-Mode Implementation: If this change affects test discovery/execution, I have implemented it in BOTH:
    • Source Generator path (TUnit.Core.SourceGenerator)
    • Reflection path (TUnit.Engine)
  • Snapshot Tests: If I changed source generator output or public APIs:
    • I ran TUnit.Core.SourceGenerator.Tests and/or TUnit.PublicAPI tests
    • I reviewed the .received.txt files and accepted them as .verified.txt
    • I committed the updated .verified.txt files
  • Performance: If this change affects hot paths (test discovery, execution, assertions):
    • I minimized allocations and avoided LINQ in hot paths
    • I cached reflection results where appropriate
  • AOT Compatibility: If this change uses reflection:
    • I added appropriate [DynamicallyAccessedMembers] annotations
    • I verified the change works with dotnet publish -p:PublishAot=true

Testing

  • All existing tests pass (dotnet test)
  • I have added tests that cover my changes
  • I have tested both source-generated and reflection modes (if applicable)

Additional Notes

@ascott18 ascott18 changed the title Fix xUnit Assert.Contains parameter transposition bug fix: #4807 xUnit Assert.Contains predicate parameter transposition Feb 15, 2026
@claude
Copy link
Contributor

claude bot commented Feb 15, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

The PR correctly addresses issue #4807 by fixing parameter ordering for xUnit's predicate overload of Assert.Contains and Assert.DoesNotContain. The implementation uses semantic analysis to detect when the predicate overload is being used and swaps parameters appropriately. The test coverage is comprehensive and the changes follow existing patterns in the codebase.

@thomhurst thomhurst enabled auto-merge (squash) February 15, 2026 19:15
@thomhurst thomhurst merged commit c70f49f into thomhurst:main Feb 15, 2026
8 of 11 checks passed
This was referenced Feb 16, 2026
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.

[Bug]: xUnit code fixer transposes arguments of Assert.Contains with lambda

2 participants