fix: support nested Member after IsTypeOf - #6540
Open
mvanhorn wants to merge 1 commit into
Open
Conversation
Open
1 task
Greptile SummaryThe PR fixes nested
Confidence Score: 5/5The PR appears safe to merge; the nested result preserves the complete assertion chain and the tests cover both successful and failing execution paths. The new branch extracts the assertion that
|
| Filename | Overview |
|---|---|
| src/TUnit.Assertions/Conditions/MemberAssertion.cs | Adds an internal interface that exposes the fully composed erased assertion already held by a member result. |
| src/TUnit.Assertions/Extensions/AssertionExtensions.cs | Recognizes nested member results in the object-returning fallback while preserving reflection handling and diagnostics for other values. |
| tests/TUnit.Assertions.Tests/Bugs/Issue6528Tests.cs | Covers the successful chain and independently verifies failures from both the nested value assertion and preceding type assertion. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Outer Member lambda] --> B[IsTypeOf InnerEx]
B --> C[And nested Member]
C --> D[MemberAssertionResult InnerEx]
D --> E[ITypeErasedMemberAssertion]
E --> F[Already-composed Assertion object]
F --> G[Outer BuildMemberResult]
G --> H[Execute type and nested member checks]
Reviews (1): Last reviewed commit: "fix: support nested Member after IsTypeO..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add a small internal production-facing type-erasure contract in
MemberAssertion.csthat letsMemberAssertionResult<TObject>expose its already-composedAssertion<object?>without changing the public fluent API or re-running only part of the chain. UpdateWrapMemberAssertionto recognize that contract before its reflection-basedAssertion<T>fallback, preserving existing handling for ordinary transformed assertions and existing diagnostics for unsupported return values. This keeps the nested result on the same execution path used by normal member chaining and avoids making the public result type inherit a different base class.An outer
Memberassertion currently selects its object-returning fallback when the assertion lambda ends in anotherMemberAssertionResult<T>. In the reported chain,IsTypeOf<InnerEx>().And.Member(...)produces that result, butWrapMemberAssertiononly recognizes classes derived fromAssertion<T>and throwsInvalidOperationExceptionbefore evaluating the assertions. The member result already implements the non-generic assertion contract and contains the combined type and nested-member checks, so rejecting it is inconsistent with the supported chaining model. There are no claims, competing PRs, or closed-unmerged attempts associated with the issue.Closes #6528
Related Issue
Fixes #
Type of Change
Checklist
Not applicable to this change.
Required
TUnit-Specific Requirements
TUnit.Core.SourceGenerator)Not run: no test command resolved in this workspace, so nothing was executed to pass.
TUnit.Engine)Not run: no test command resolved in this workspace, so nothing was executed to pass.
TUnit.Core.SourceGenerator.Testsand/orTUnit.PublicAPItestsNot run: no test command resolved in this workspace, so nothing was executed to pass.
.received.txtfiles and accepted them as.verified.txtNot run: no test command resolved in this workspace, so nothing was executed to pass.
.verified.txtfilesNot run: no test command resolved in this workspace, so nothing was executed to pass.
[DynamicallyAccessedMembers]annotationsNot run: no test command resolved in this workspace, so nothing was executed to pass.
dotnet publish -p:PublishAot=trueNot run: no test command resolved in this workspace, so nothing was executed to pass.
Testing
dotnet test)Not run: no test command resolved in this workspace, so nothing was executed to pass.
ThrowsExactly<OuterEx>().And.Member(... IsTypeOf<InnerEx>().And.Member(Code, IsEqualTo(5)))chain completes successfully for anInnerExwhose code is5. - The same chain with a differentCodevalue throws the normal assertion exception, proving the nested member assertion is executed instead of being silently skipped or rejected as an unexpected type.Additional Notes
Nothing beyond what is described above.