Repository navigation
feat(mocks): add ClearCalls, PassThrough toggle and string/type/reference matchers - #7018
Conversation
…ference matchers - ClearInvocations() on Mock<T> and MockRepository clears recorded calls while keeping setups, state and auto-tracked properties (Reset() clears everything). - CallBase (default true) on class and wrap mocks: when false, unconfigured virtual members return smart defaults / auto-mocks (loose) or throw (strict) instead of running the base implementation. - New matchers: StartsWith, EndsWith, Contains(string), IsOfType<T>, IsSameAs. - Typed TryHandleCallWithReturn overloads now carry the auto-mock factory. - Docs, migration pages and generator snapshots updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gx2TDcnLThUsu4UCQW77eJ
…-callbase-string-matchers Add CallBase, ClearInvocations, and string/type matchers to mocks
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
|
Description
Adds three small TUnit.Mocks features:
ClearCalls()onMock<T>andMockRepository. It clears recorded calls but keeps setups, state, auto-tracked properties and event subscriptions (Reset()still clears everything).PassThrough(defaulttrue, so existing behaviour is unchanged). Whenfalse, unconfigured virtual members of class and wrap mocks no longer run the base implementation. Loose mocks return smart defaults, auto-mocks andDefaultValueProvidervalues; strict mocks throwMockStrictBehaviorException.StartsWith,EndsWith,Contains(string)(optionalStringComparison),IsOfType<TDerived>()andIsSameAs(reference).Also: the typed
TryHandleCallWithReturnoverloads now pass the auto-mock factory through (they previously dropped it), whichPassThrough = falseneeds. Docs and the Moq/NSubstitute/FakeItEasy migration pages are updated.Related Issue
None.
Type of Change
Note (release notes): nothing is source-breaking.
ClearCalls()andPassThroughlive on new opt-in interfaces (IMockCallHistory,IMockPassThrough) thatMock<T>implements, soIMockandIMockControl<T>are unchanged.Reset()keepsPassThrough, likeBehaviorandDefaultValueProvider.Checklist
Required
TUnit-Specific Requirements
TUnit.Mocks.SourceGenerator.Tests, reviewed every diff (purely additive: the newClearCalls/PassThroughpolyfills) and committed the updated.verified.txtfilesType.IsInstanceOfTypeonly)Testing
Run on net10.0: TUnit.Mocks.Tests 1376 passed (40 new), generator snapshots 170, Analyzers 64, Http 58, Logging 31, InternalsAccess 34. net8.0/net9.0 compile but were not executed locally (runtimes unavailable). New doc snippets were compiled in a scratch test;
Verify-DocSnippets.ps1was not run.Summary by CodeRabbit
ClearCalls()to clear recorded mock calls while preserving setups and mock state, with support for clearing calls across a repository.PassThroughcontrols for class and wrapped mocks, allowing unconfigured virtual calls to skip base implementations.