Improves the subject identification for chained assertions and those that use Which by dennisdoomen · Pull Request #3000 · fluentassertions/fluentassertions · GitHub
Skip to content

Improves the subject identification for chained assertions and those that use Which#3000

Merged
dennisdoomen merged 1 commit into
fluentassertions:mainfrom
dennisdoomen:fix/2747
Feb 7, 2025
Merged

Improves the subject identification for chained assertions and those that use Which#3000
dennisdoomen merged 1 commit into
fluentassertions:mainfrom
dennisdoomen:fix/2747

Conversation

@dennisdoomen

@dennisdoomen dennisdoomen commented Feb 1, 2025

Copy link
Copy Markdown
Member

Given the following chained assertion

collection.Should().ContainSingle().Which.Parameters.Should().ContainSingle().Which.Should().Be(3)

If the second ContainSingle, fails, this PR ensures that the subject is displayed as

collection[0].Parameters[0].

This required several changes to make this possible:

  • Establishes the term "subject identification" instead of "caller identifier"
  • The existing CallerIdentifier has received a new method DetermineCallerIdentities that extracts all subjects from a chained assertion like the one above.
  • The AssertionChain delegates tracking which subject to use for its failures using a new SubjectIdentificationBuilder class. This one also takes into account any ambient AssertionScopes and modifications that Which does to the subject/
  • The names CallerIdentifier and CallerStatementBuilder are really not correct, but I've decided to keep that out of this PR.

Fixes #2747

IMPORTANT

  • If the PR touches the public API, the changes have been approved in a separate issue with the "api-approved" label.
  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by unit tests which follow the Arrange-Act-Assert syntax and the naming conventions such as is used in these tests.
  • If the PR adds a feature or fixes a bug, please update the release notes with a functional description that explains what the change means to consumers of this library, which are published on the website.
  • If the PR changes the public API the changes needs to be included by running AcceptApiChanges.ps1 or AcceptApiChanges.sh.
  • If the PR affects the documentation, please include your changes in this pull request so the documentation will appear on the website.
    • Please also run ./build.sh --target spellcheck or .\build.ps1 --target spellcheck before pushing and check the good outcome

@github-actions

github-actions Bot commented Feb 1, 2025

Copy link
Copy Markdown

@dennisdoomen dennisdoomen force-pushed the fix/2747 branch 5 times, most recently from aeb55e4 to b4d656c Compare February 2, 2025 13:09
@coveralls

coveralls commented Feb 2, 2025

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 13194283284

Details

  • 109 of 109 (100.0%) changed or added relevant lines in 12 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 97.422%

Totals Coverage Status
Change from base Build 13151290807: 0.02%
Covered Lines: 12314
Relevant Lines: 12498

💛 - Coveralls

@dennisdoomen dennisdoomen changed the title Improves the caller identifier for chained assertions and those that use Which Improves the subject identification for chained assertions and those that use Which Feb 2, 2025
@dennisdoomen dennisdoomen marked this pull request as ready for review February 2, 2025 14:56
@dennisdoomen dennisdoomen requested a review from jnyrup February 2, 2025 14:56
Comment thread Tests/FluentAssertions.Specs/Execution/CallerIdentificationSpecs.cs Outdated
Comment thread Tests/FluentAssertions.Specs/Execution/CallerIdentificationSpecs.cs
Comment thread Tests/FluentAssertions.Specs/Execution/CallerIdentificationSpecs.cs
Comment thread Tests/FluentAssertions.Specs/Execution/CallerIdentificationSpecs.cs
Comment thread Src/FluentAssertions/CallerIdentification/WhichParsingStrategy.cs
Comment thread Src/FluentAssertions/CallerIdentification/WhichParsingStrategy.cs Outdated
Comment thread Src/FluentAssertions/CallerIdentification/WhichParsingStrategy.cs Outdated

@jnyrup jnyrup left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to update release notes

@dennisdoomen dennisdoomen added this to the 8.1.0 milestone Feb 7, 2025
@dennisdoomen dennisdoomen merged commit 7b53b8a into fluentassertions:main Feb 7, 2025
jnyrup added a commit to jnyrup/fluentassertions that referenced this pull request Feb 27, 2025
Fixes fluentassertions#3031
Regression from fluentassertions#3000 where previously `getCallerIdentifier() + callerPostfix` would return an empty string.
@jnyrup jnyrup mentioned this pull request Feb 27, 2025
7 tasks
jnyrup added a commit that referenced this pull request Feb 27, 2025
Fixes #3031
Regression from #3000 where previously `getCallerIdentifier() + callerPostfix` would return an empty string.
@dennisdoomen dennisdoomen deleted the fix/2747 branch March 13, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caller identification always ignores the caller of a chained assertion

3 participants