-
Notifications
You must be signed in to change notification settings - Fork 731
Add support for inline assertions using Value.ThatMatches and Value.ThatSatisfies #3076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for inline assertions using Value.ThatMatches and Value.ThatSatisfies #3076
Conversation
8da533b to
456e992
Compare
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 qodana-support@jetbrains.com
|
4752b7b to
3518996
Compare
There was a problem hiding this 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 introduces support for inline assertions in equivalency comparisons through two new methods: Value.ThatMatches for condition-based assertions and Value.ThatSatisfies for action-based assertions.
- Adds
Value.ThatMatches<T>()to check conditions inline during equivalency comparisons - Adds
Value.ThatSatisfies<T>()to run assertion actions inline during equivalency comparisons - Implements a new equivalency step to handle inline assertions in the comparison pipeline
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Tests/FluentAssertions.Equivalency.Specs/InlineAssertionsSpecs.cs | Comprehensive test coverage for both ThatMatches and ThatSatisfies functionality |
| Src/FluentAssertions/Value.cs | Public API entry point providing the ThatMatches and ThatSatisfies static methods |
| Src/FluentAssertions/Equivalency/Inlining/InlineEquivalencyStep.cs | Equivalency step that handles inline assertions during comparisons |
| Src/FluentAssertions/Equivalency/Inlining/IInlineEquivalencyAssertion.cs | Interface defining the contract for inline assertions |
| Src/FluentAssertions/Equivalency/Inlining/ConditionBasedInlineAssertion.cs | Implementation for condition-based inline assertions (ThatMatches) |
| Src/FluentAssertions/Equivalency/Inlining/ActionBasedInlineAssertion.cs | Implementation for action-based inline assertions (ThatSatisfies) |
| Src/FluentAssertions/Equivalency/EquivalencyPlan.cs | Integration of the new inline equivalency step into the comparison pipeline |
Src/FluentAssertions/Equivalency/Inlining/ActionBasedInlineAssertion.cs
Outdated
Show resolved
Hide resolved
e6e0dc2 to
50b3fb8
Compare
Pull Request Test Coverage Report for Build 16694245755Details
💛 - Coveralls |
50b3fb8 to
f99ab19
Compare
jnyrup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great feature!
| if (condition is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(condition), "A boolean condition is required"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we evaluate this here instead of in Value.ThatMatches using Guard.ThrowIfArgumentIsNull? 🤔
Included in draft-PR #3079
| .ForCondition(comparands.Subject is T) | ||
| .FailWith("Expected {context:subject} to be of type {0}, but found {1}.", typeof(T), comparands.Subject?.GetType()) | ||
| .Then | ||
| .ForCondition(condition.Compile()((T)comparands.Subject)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the call to BeEquivalentTo is inside an AssertionScope, we don't stop evaluating and get an InvalidCastException.
Can be observed adding using var _ = new AssertionScope(); to The_type_of_the_condition_must_be_met_too and running it in debug mode.
Included in draft-PR #3079
Closes #3070
IMPORTANT
./build.sh --target spellcheckor.\build.ps1 --target spellcheckbefore pushing and check the good outcomeCONTRIBUTOR 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.