Limit Mock.Verify() recursion to framework-created inner mocks - #1708
Conversation
Co-authored-by: kzu <169707+kzu@users.noreply.github.com>
Mock.Verify() recursion to framework-created inner mocks
🧪 Details on Microsoft Windows 10.0.26100from retest v1.1.0 on .NET 10.0.12 with 💜 by @devlooped |
|
@copilot test failure in CI, is it a wrong test that verified a buggy behavior? |
Co-authored-by: kzu <169707+kzu@users.noreply.github.com>
Head branch was pushed to by a user without write access
Good catch — it exposed a regression from my first fix, not a buggy test. |
|
@copilot verify this fix, seems weird that we'd check for the setup not being a MethodCall? |
Co-authored-by: kzu <169707+kzu@users.noreply.github.com>
You were right to question that check. I verified behavior and replaced it with an explicit allowlist in a6bcec8: recursion now only applies to |
Mock.Verify()currently walks into any mock returned by a setup, so verifying one mock can fail on unmet verifiable setups configured on a different mock. This shows up when using explicit.Returns(otherMock.Object)and verifying mocks in separate phases.Behavioral fix: scope recursive verification
Mock.Verifyto recurse only throughInnerMockSetup(i.e., Moq-created object-graph links), instead of recursing through all setups.Regression coverage: issue scenario
Issue1699regression test inIssueReportsFixturethat reproduces:mockOne.Setup(...).Returns(mockTwo.Object).Verifiable();mockTwo.Setup(...).Verifiable();mockOne.Verify()should succeed beforemockTwointeractions occur.Example of the affected pattern
.Verify()on one mock complains over missing invocations on another mock #1699