Skip to content

Conversation

@dennisdoomen
Copy link
Member

@dennisdoomen dennisdoomen commented Sep 20, 2025

This PR adds a new WithoutMessage method to FluentAssertions for exception testing that validates an exception message does NOT match a given wildcard pattern.

The implementation adds both synchronous and asynchronous variants of WithoutMessage that mirror the existing WithMessage functionality, but use NotMatchEquivalentOf instead of MatchEquivalentOf for the inverse assertion.

The code also refactors the internal message assertion logic to be more generic by accepting an action delegate that defines how to assert against the message, allowing both positive and negative message matching to share the same underlying infrastructure.
Minor improvements include changing the error message identifier from "exception message" to "the exception message" for better readability.

Closes #3093

@github-actions
Copy link

github-actions bot commented Sep 20, 2025

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@coveralls
Copy link

coveralls commented Sep 21, 2025

Pull Request Test Coverage Report for Build 17926661819

Details

  • 17 of 18 (94.44%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 97.16%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/ExceptionAssertionsExtensions.cs 1 2 50.0%
Totals Coverage Status
Change from base Build 17882324418: 0.003%
Covered Lines: 12771
Relevant Lines: 12990

💛 - Coveralls

@dennisdoomen dennisdoomen changed the title Allow WithoutMessage when using Should().Throw() Allow WithoutMessage when using Should().Throw() and ThrowAsync() Sep 21, 2025
@dennisdoomen dennisdoomen marked this pull request as ready for review September 21, 2025 06:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new WithoutMessage method to FluentAssertions that validates an exception message does NOT match a given wildcard pattern, providing the inverse functionality to the existing WithMessage method.

  • Adds WithoutMessage method to both synchronous and asynchronous exception assertions
  • Refactors internal message assertion logic to use a generic action delegate approach
  • Updates error messages from "exception message" to "the exception message" for consistency

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
docs/_pages/releases.md Documents the new WithoutMessage feature in release notes
Tests/FluentAssertions.Specs/Exceptions/ExceptionMessageSpecs.cs Adds new test file with test cases for the WithoutMessage functionality
Tests/FluentAssertions.Specs/Exceptions/OuterExceptionSpecs.cs Updates test expectations to match new error message format
Tests/FluentAssertions.Specs/Exceptions/AggregateExceptionSpecs.cs Fixes class name from ExceptionAssertionSpecs to AggregateExceptionSpecs
Tests/Approval.Tests/ApprovedApi/* Updates API approval tests to include new WithoutMessage methods
Src/FluentAssertions/Specialized/ExceptionAssertions.cs Implements the core WithoutMessage method and refactors message assertion logic
Src/FluentAssertions/ExceptionAssertionsExtensions.cs Adds async extension method for WithoutMessage

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@dennisdoomen dennisdoomen requested a review from jnyrup September 21, 2025 11:06
@dennisdoomen dennisdoomen added this to the 8.7.0 milestone Sep 21, 2025
Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

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

As missing handling of AssertionScopes also exists in main it's not blocking for merging this PR.

This was referenced Jan 8, 2026
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.

[API Proposal]: Allow WithoutMessage when using Should().Throw() and ThrowAsync()

3 participants