Allow WithoutMessage when using Should().Throw() and ThrowAsync()#3100
Conversation
Qodana for .NETIt 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 Contact Qodana teamContact us at [email protected]
|
c083348 to
e4789f3
Compare
Pull Request Test Coverage Report for Build 17926661819Details
💛 - Coveralls |
e4789f3 to
01a1bd3
Compare
01a1bd3 to
f1b1f19
Compare
There was a problem hiding this comment.
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
WithoutMessagemethod 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.
f1b1f19 to
3866643
Compare
3866643 to
9ff3e51
Compare
jnyrup
left a comment
There was a problem hiding this comment.
As missing handling of AssertionScopes also exists in main it's not blocking for merging this PR.
9ff3e51 to
cd0262a
Compare
Updated [FluentAssertions](https://github.com/fluentassertions/fluentassertions) from 8.1.1 to 8.8.0. <details> <summary>Release notes</summary> _Sourced from [FluentAssertions's releases](https://github.com/fluentassertions/fluentassertions/releases)._ ## 8.8.0 <!-- Release notes generated using configuration in .github/release.yml at main --> ## What's Changed ### New features * Add support for MSTest4 by @jnyrup in fluentassertions/fluentassertions#3111 ### Improvements * Allow WithoutMessage when using Should().Throw() and ThrowAsync() by @dennisdoomen in fluentassertions/fluentassertions#3100 * Improve reporting of the differences between long strings by @dennisdoomen in fluentassertions/fluentassertions#3101 * Allow customizing the equivalency behavior for BeXmlSerializable by @logiclrd in fluentassertions/fluentassertions#3107 ### Documentation * Add docs for `config` parameter by @jnyrup in fluentassertions/fluentassertions#3104 ### Others * Refreshed readme by @dennisdoomen in fluentassertions/fluentassertions#3106 * Merge hotfix 8.7.1 back to main by @dennisdoomen in fluentassertions/fluentassertions#3109 * Fix release notes by @jnyrup in fluentassertions/fluentassertions#3112 * Bump github/codeql-action from 3 to 4 by @dependabot[bot] in fluentassertions/fluentassertions#3113 **Full Changelog**: fluentassertions/fluentassertions@8.7.1...8.8.0 ## 8.7.1 <!-- Release notes generated using configuration in .github/release.yml at hotfix/8.7.1 --> ## What's Changed ### Others * JSON assertions did not properly handle floats, doubles and unsigned … by @dennisdoomen in fluentassertions/fluentassertions#3105 * Fixed ambiguity when using Should on a JsonNode derived class ... by @JSkimming in fluentassertions/fluentassertions#3102 **Full Changelog**: fluentassertions/fluentassertions@8.7.0...8.7.1 ## 8.7.0 <!-- Release notes generated using configuration in .github/release.yml at ae620add07cf6666841e568fd3bf8a0733478bb5 --> ## What's Changed ### New features * Added System.Text.Json assertion APIs and BeEquivalentTo support by @dennisdoomen in fluentassertions/fluentassertions#3094 ### Others * Address a bunch of Qodana issues by @dennisdoomen in fluentassertions/fluentassertions#3082 * Bump actions/checkout from 4 to 5 by @dependabot[bot] in fluentassertions/fluentassertions#3085 * Bump JetBrains/qodana-action from 2025.1 to 2025.2 by @dependabot[bot] in fluentassertions/fluentassertions#3086 * Bump actions/download-artifact from 4 to 5 by @dependabot[bot] in fluentassertions/fluentassertions#3087 * Bump cspell from 9.2.0 to 9.2.1 by @dependabot[bot] in fluentassertions/fluentassertions#3090 * Bump actions/setup-dotnet from 4 to 5 by @dependabot[bot] in fluentassertions/fluentassertions#3092 * Add lock file for nuget packages by @jnyrup in fluentassertions/fluentassertions#3084 * Set `DisableImplicitNuGetFallbackFolder` by @jnyrup in fluentassertions/fluentassertions#3095 * Bump Nugets by @jnyrup in fluentassertions/fluentassertions#3096 * Revert package locking by @jnyrup in fluentassertions/fluentassertions#3098 * Clean-up tests related to exceptions by @dennisdoomen in fluentassertions/fluentassertions#3099 **Full Changelog**: fluentassertions/fluentassertions@8.6.0...8.7.0 ## 8.6.0 <!-- Release notes generated using configuration in .github/release.yml at main --> ## What's Changed ### Improvements * Add support for inline assertions using `Value.ThatMatches` and `Value.ThatSatisfies` by @dennisdoomen in fluentassertions/fluentassertions#3076 ### Others * Remove Microsoft.SourceLink.GitHub by @SimonCropp in fluentassertions/fluentassertions#3072 * Bump cspell from 9.1.3 to 9.1.5 by @dependabot[bot] in fluentassertions/fluentassertions#3073 * Added PackageGuard to the build pipeline by @dennisdoomen in fluentassertions/fluentassertions#3075 * Bump cspell from 9.1.5 to 9.2.0 by @dependabot[bot] in fluentassertions/fluentassertions#3077 * Remove dependencies on Bogus by @jnyrup in fluentassertions/fluentassertions#3080 * Update nuget packages by @jnyrup in fluentassertions/fluentassertions#3081 * Follow-up to #3076 by @jnyrup in fluentassertions/fluentassertions#3079 * Documentation and typo fixes by @jnyrup in fluentassertions/fluentassertions#3078 ## New Contributors * @SimonCropp made their first contribution in fluentassertions/fluentassertions#3072 **Full Changelog**: fluentassertions/fluentassertions@8.5.0...8.6.0 ## 8.5.0 <!-- Release notes generated using configuration in .github/release.yml at main --> ## What's Changed ### New features * Extended BeEquivalentTo with support for checking the type of the properties by @dennisdoomen in fluentassertions/fluentassertions#3066 ### Fixes * Ensured WithTracing is safe when used with BeEquivalentTo globally by @dennisdoomen in fluentassertions/fluentassertions#3067 ### Others * Revisit the .editorconfig rules by @dennisdoomen in fluentassertions/fluentassertions#3063 * Bump cspell from 9.1.1 to 9.1.2 by @dependabot[bot] in fluentassertions/fluentassertions#3068 * Use .NET 9 SDK by @jnyrup in fluentassertions/fluentassertions#3069 * Bump cspell from 9.1.2 to 9.1.3 by @dependabot[bot] in fluentassertions/fluentassertions#3071 **Full Changelog**: fluentassertions/fluentassertions@8.4.0...8.5.0 ## 8.4.0 <!-- Release notes generated using configuration in .github/release.yml at main --> ## What's Changed ### Improvements * Allow excluding properties by name anywhere in the graph by @dennisdoomen in fluentassertions/fluentassertions#3062 * Added Should().Throw(), ThrowAsync() and ThrowWithinAsync() flavors that don’t require a specific exception type by @Xceed-DelvaJB in fluentassertions/fluentassertions#3059 ### Others * Bump cspell from 9.0.1 to 9.0.2 by @dependabot in fluentassertions/fluentassertions#3050 * Bump JetBrains/qodana-action from 2024.2 to 2025.1 by @dependabot in fluentassertions/fluentassertions#3044 * Fix qodana warnings by @jnyrup in fluentassertions/fluentassertions#3053 * Add contributor grant by @dennisdoomen in fluentassertions/fluentassertions#3055 * Bump cspell from 9.0.2 to 9.1.1 by @dependabot in fluentassertions/fluentassertions#3058 ## New Contributors * @Xceed-DelvaJB made their first contribution in fluentassertions/fluentassertions#3059 **Full Changelog**: fluentassertions/fluentassertions@8.3.0...8.4.0 ## 8.3.0 <!-- Release notes generated using configuration in .github/release.yml at main --> ## What's Changed ### Improvements * Improve rendering of exception messages when using WithMessage by @dennisdoomen in fluentassertions/fluentassertions#3039 * Clarify the date/time type when comparing dates, times and combinations of those by @dennisdoomen in fluentassertions/fluentassertions#3049 ### Others * Bump cspell from 8.17.5 to 8.18.1 by @dependabot in fluentassertions/fluentassertions#3041 * Bump cspell from 8.18.1 to 8.19.2 by @dependabot in fluentassertions/fluentassertions#3042 * Bump cspell from 8.19.2 to 8.19.3 by @dependabot in fluentassertions/fluentassertions#3043 * Bump cspell from 8.19.3 to 9.0.0 by @dependabot in fluentassertions/fluentassertions#3045 * Bump cspell from 9.0.0 to 9.0.1 by @dependabot in fluentassertions/fluentassertions#3046 * Fix links to test suites in bug report template by @robvanuden in fluentassertions/fluentassertions#3047 **Full Changelog**: fluentassertions/fluentassertions@8.2.0...8.3.0 ## 8.2.0 <!-- Release notes generated using configuration in .github/release.yml at main --> ## What's Changed ### Improvements * Optimize various string operations by @jnyrup in fluentassertions/fluentassertions#3037 * Reworked formatting and support multi-dimensional arrays. by @dennisdoomen in fluentassertions/fluentassertions#3009 ### Fixes * Restore `StringSyntax` annotations by @jnyrup in fluentassertions/fluentassertions#3033 * Regex fixups by @jnyrup in fluentassertions/fluentassertions#3034 * Handle missing caller identifier by @jnyrup in fluentassertions/fluentassertions#3036 ### Others * Bump cspell from 8.17.3 to 8.17.5 by @dependabot in fluentassertions/fluentassertions#3035 **Full Changelog**: fluentassertions/fluentassertions@8.1.1...8.2.0 Commits viewable in [compare view](fluentassertions/fluentassertions@8.1.1...8.8.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This PR adds a new
WithoutMessagemethod 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
WithoutMessagethat mirror the existingWithMessagefunctionality, but useNotMatchEquivalentOfinstead ofMatchEquivalentOffor 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