Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Xceed-DelvaJB
Copy link
Contributor

This implements issue #3056

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

CONTRIBUTOR LICENSE GRANT

By submitting this contribution, the contributor hereby irrevocably grants to the project owners and maintainers a perpetual, worldwide, royalty-free, irrevocable license to use, reproduce, modify, distribute, sublicense, and create derivative works of the contribution for any purpose and under any terms, including proprietary licensing.

The contributor waives any moral rights in the contribution to the extent permitted by law and agrees not to assert any claim of authorship or control over the contribution. The contributor represents that they are the sole author of the contribution and that it is provided free of any third-party claims.

The contributor understands and agrees that the maintainers may, at their sole discretion, use, license, or redistribute the contribution as part of any work and under any terms they choose, without further permission or attribution.

  • I have read the Contributor License Grant and accept the conditions
  • I'm interested in a free license for Fluent Assertions and will share my email address through [email protected]

Copy link

github-actions bot commented Jun 19, 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 [email protected]

…() test.

Added When_async_method_throws_any_exception_within_timespan_it_should_succeed() test.
@dennisdoomen dennisdoomen reopened this Jun 20, 2025
@dennisdoomen
Copy link
Member

@Xceed-DelvaJB did you accidentally close the PR?

@coveralls
Copy link

coveralls commented Jun 20, 2025

Pull Request Test Coverage Report for Build 15834460770

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 97.319%

Totals Coverage Status
Change from base Build 15795830311: 0.001%
Covered Lines: 12474
Relevant Lines: 12673

💛 - Coveralls

}

[Fact]
public async Task When_async_method_throws_any_exception_it_should_succeed()
Copy link
Member

Choose a reason for hiding this comment

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

🔧We try to use a more fact-based naming convention these days and avoid words like should and when. So in this case Succeeds_for_any_thrown_exception. We also started to group the test cases in nested classes named like the API. See for example CollectionAssertionSpecs. There we even used partial classes to keep things organized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok for the names and organizing. Take a look at my changes. I might have gone overboard with the nested classes. Let me know if it's presentable.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm afraid I've sent you into a rabbit hole. The idea is that we group the tests under the nested classes and use names to represent them based on API or capability, e.g. NotThrowAfterAsync, Actions or NogGenericAsyncFunctions (without the Assertions part). And if we do decide to refactor such a big class we either do that

  1. In a separate PR
  2. In a separate commit if your PR has been properly organized into focused commits we want to keep after merging.

In your case, we will squash the PR as you have merged the main branch into the feature branch. We only do rebases.

So let's remove these nested classed you've added so we can look at this at a later point of time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, done.

I read your article about source control history and will try to put it to use for the next pull request.


* Clarify the date/time type when comparing non-compatible dates and times in `BeEquivalentTo` - [3049](https://github.com/fluentassertions/fluentassertions/pull/3049)
* Improve the rendering of exception messages when using `WithMessage` for better readability - [3039](https://github.com/fluentassertions/fluentassertions/pull/3039)
* Added `Should().Throw()`, `ThrowAsync()` and `ThrowWithinAsync()` flavors that don’t require a specific exception type - [3056](https://github.com/fluentassertions/fluentassertions/issues/3056)
Copy link
Member

Choose a reason for hiding this comment

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

🔧 This needs to become part of a new 8.4.0 section.

Copy link
Member

Choose a reason for hiding this comment

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

Additionally we link to the PR resolving an issue and not the issue itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should have noticed that. For future reference, I need to create a pull request, then update the release notes files with the number and link?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly.

@dennisdoomen dennisdoomen added this to the 8.4.0 milestone Jun 20, 2025
@dennisdoomen dennisdoomen requested review from jnyrup and Copilot June 20, 2025 05:32
Copy link

@Copilot 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

Adds non-generic overloads for exception assertions so consumers can assert “any exception” without specifying a type.

  • Introduces Should().Throw() on delegates and actions.
  • Adds ThrowAsync() and ThrowWithinAsync() on async functions.
  • Updates release notes and API approvals to reflect the new overloads.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/_pages/releases.md Added release note for new Throw()/ThrowAsync()/ThrowWithinAsync() overloads
Tests/FluentAssertions.Specs/Exceptions/ThrowAssertionsSpecs.cs Added unit tests for new non-generic Throw() overload
Tests/FluentAssertions.Specs/Exceptions/AsyncFunctionExceptionAssertionSpecs.cs Added tests for ThrowAsync() and ThrowWithinAsync()
Tests/Approval.Tests/ApprovedApi/FluentAssertions/*.verified.txt Updated approved API files to include new overload signatures
Src/FluentAssertions/Specialized/DelegateAssertions.cs Implemented non-generic Throw() in delegate assertions
Src/FluentAssertions/Specialized/AsyncFunctionAssertions.cs Implemented non-generic ThrowAsync() and ThrowWithinAsync()
Comments suppressed due to low confidence (3)

docs/_pages/releases.md:16

  • Consider adding a new version header (e.g., ## 8.3.0) above this entry to group the new feature under the correct release section, ensuring consistency in the release notes structure.
* Added `Should().Throw()`, `ThrowAsync()` and `ThrowWithinAsync()` flavors that don’t require a specific exception type - [3056](https://github.com/fluentassertions/fluentassertions/issues/3056)

Tests/FluentAssertions.Specs/Exceptions/ThrowAssertionsSpecs.cs:9

  • Add a negative test to verify that invoking Should().Throw() on a delegate that does not throw any exception results in an assertion failure, covering the failure path for the new overload.
    [Fact]

Tests/FluentAssertions.Specs/Exceptions/AsyncFunctionExceptionAssertionSpecs.cs:938

  • Add a test case to verify that ThrowAsync() and ThrowWithinAsync() fail as expected when the asynchronous operation does not throw an exception, covering the negative scenario for the new overloads.
    [Fact]

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.

Besides a tiny comment, I don't have anything to add to Dennis' review.


* Clarify the date/time type when comparing non-compatible dates and times in `BeEquivalentTo` - [3049](https://github.com/fluentassertions/fluentassertions/pull/3049)
* Improve the rendering of exception messages when using `WithMessage` for better readability - [3039](https://github.com/fluentassertions/fluentassertions/pull/3039)
* Added `Should().Throw()`, `ThrowAsync()` and `ThrowWithinAsync()` flavors that don’t require a specific exception type - [3056](https://github.com/fluentassertions/fluentassertions/issues/3056)
Copy link
Member

Choose a reason for hiding this comment

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

Additionally we link to the PR resolving an issue and not the issue itself.

@dennisdoomen dennisdoomen marked this pull request as ready for review June 20, 2025 13:40
Xceed-DelvaJB and others added 3 commits June 22, 2025 11:25
Grouped tests in nested classes based on API.
Updated some test names to fit with new naming-style.

## 8.4.0

* Added `Should().Throw()`, `ThrowAsync()` and `ThrowWithinAsync()` flavors that don’t require a specific exception type - [3059](https://github.com/fluentassertions/fluentassertions/pull/3059)
Copy link
Member

Choose a reason for hiding this comment

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

🔧 This should be placed under the "enhancements" section. See also previous versions.

}

[Fact]
public async Task When_async_method_throws_any_exception_it_should_succeed()
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm afraid I've sent you into a rabbit hole. The idea is that we group the tests under the nested classes and use names to represent them based on API or capability, e.g. NotThrowAfterAsync, Actions or NogGenericAsyncFunctions (without the Assertions part). And if we do decide to refactor such a big class we either do that

  1. In a separate PR
  2. In a separate commit if your PR has been properly organized into focused commits we want to keep after merging.

In your case, we will squash the PR as you have merged the main branch into the feature branch. We only do rebases.

So let's remove these nested classed you've added so we can look at this at a later point of time.

Put release note in its proper section.
@dennisdoomen dennisdoomen merged commit cc607f1 into fluentassertions:main Jun 24, 2025
8 checks passed
@dennisdoomen
Copy link
Member

Thanks @Xceed-DelvaJB

This was referenced Sep 15, 2025
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.

4 participants