Skip to content

feat: emit nested-mock TODO across all migration rewrite sites#69

Merged
vbreuss merged 3 commits into
mainfrom
feat/nested-mock-todo-comments
May 15, 2026
Merged

feat: emit nested-mock TODO across all migration rewrite sites#69
vbreuss merged 3 commits into
mainfrom
feat/nested-mock-todo-comments

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 15, 2026

NSubstitute and Moq fixers silently rewrite nested receivers like sub.Child.Foo() into sub.Child.Mock.Setup/Verify/Raise.Foo() chains, which NRE at runtime if the nested child isn't explicitly registered (Mockolate doesn't auto-mock recursively). The setup path already emitted a TODO comment warning the user; this extends the same warning to every other rewrite site that builds a nested chain:

  • NSubstitute: method verify, property verify (Got/Set), event raise.
  • Moq: Setup call, Setup property access, SetupProperty, Verify call, VerifyAdd/VerifyRemove event, VerifyGet/VerifySet property.

Also fixes a trivia-clobbering bug in the Moq Callback rewrite: WithTriviaFrom(invocation) on the wrapping Do() expression was overwriting the leading trivia of the embedded migrated setup, dropping any TODO attached to it. Switched to WithTrailingTrivia only so the leading trivia (with the TODO) is preserved.

NSubstitute and Moq fixers silently rewrite nested receivers like
sub.Child.Foo() into sub.Child.Mock.Setup/Verify/Raise.Foo() chains,
which NRE at runtime if the nested child isn't explicitly registered
(Mockolate doesn't auto-mock recursively). The setup path already
emitted a TODO comment warning the user; this extends the same warning
to every other rewrite site that builds a nested chain:

- NSubstitute: method verify, property verify (Got/Set), event raise.
- Moq: Setup call, Setup property access, SetupProperty, Verify call,
  VerifyAdd/VerifyRemove event, VerifyGet/VerifySet property.

Also fixes a trivia-clobbering bug in the Moq Callback rewrite:
WithTriviaFrom(invocation) on the wrapping Do() expression was
overwriting the leading trivia of the embedded migrated setup,
dropping any TODO attached to it. Switched to WithTrailingTrivia
only so the leading trivia (with the TODO) is preserved.
@vbreuss vbreuss self-assigned this May 15, 2026
Copilot AI review requested due to automatic review settings May 15, 2026 07:05
@vbreuss vbreuss added the enhancement New feature or request label May 15, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 15, 2026

Test Results

  9 files  ± 0    9 suites  ±0   3m 2s ⏱️ +13s
284 tests + 4  284 ✅ + 4  0 💤 ±0  0 ❌ ±0 
852 runs  +12  852 ✅ +12  0 💤 ±0  0 ❌ ±0 

Results for commit a459f84. ± Comparison against base commit cc02a2f.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown

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

This PR extends the existing “nested mock chain” warning behavior so that when migrations produce nested .Mock.* chains (which can NRE unless the nested mocks are explicitly registered), the code fix emits a TODO comment at all relevant rewrite sites (Moq + NSubstitute). It also fixes a Moq callback-trivia issue that could drop that TODO during .Callback(...).Do(...) rewrites.

Changes:

  • Emit a nested-mock TODO comment for additional nested-chain rewrite sites across both NSubstitute and Moq fixers (verify/get/set/raise/etc.).
  • Fix Moq .Callback(...).Do(...) rewrite trivia handling to preserve leading trivia on embedded migrated setups (including the TODO).
  • Expand/adjust test expectations and add coverage for the new TODO emission behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Tests/Mockolate.Migration.Tests/NSubstituteCodeFixProviderTests.NestedTests.cs Adds test coverage for TODO emission on nested Received property got/set and nested event raise rewrites.
Tests/Mockolate.Migration.Tests/MoqCodeFixProviderTests.VerifyTests.cs Updates expected output to include nested-mock TODO for nested verify rewrite.
Tests/Mockolate.Migration.Tests/MoqCodeFixProviderTests.VerifyEventTests.cs Updates expected output to include nested-mock TODO for nested VerifyAdd/VerifyRemove rewrite.
Tests/Mockolate.Migration.Tests/MoqCodeFixProviderTests.SetupTests.cs Updates expected output to include nested-mock TODO for nested Setup/SetupProperty-related rewrites.
Tests/Mockolate.Migration.Tests/MoqCodeFixProviderTests.PropertyTests.cs Updates expected output to include nested-mock TODO for nested VerifyGet/VerifySet rewrite.
Tests/Mockolate.Migration.Tests/MoqCodeFixProviderTests.NewMockTests.cs Updates expected output to include nested-mock TODO for nested mock navigation migrations.
Tests/Mockolate.Migration.Tests/MoqCodeFixProviderTests.CallbackTests.cs Adds a test ensuring nested-mock TODO trivia is preserved through the .Callback.Do rewrite.
Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Extends TODO emission to nested verify/property/event-raise rewrite sites using the existing trivia/TODO infrastructure.
Source/Mockolate.Migration.Analyzers.CodeFixers/MoqCodeFixProvider.cs Adds nested-mock TODO trivia builder and wires it into all nested rewrite sites; adjusts callback rewrite to preserve leading trivia on embedded migrated setups.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

vbreuss added 2 commits May 15, 2026 09:13
Generated TODO comments now include the rule ID of the analyzer that
triggered the codefix in brackets, so users can grep for or filter
unresolved migration hints by source:

  // TODO(MockolateM001): register the nested 'mock.Child' chain ...
  // TODO(MockolateM002): review CallInfo usage manually ...

Applies to every TODO emitted by NSubstituteCodeFixProvider
(MockolateM002 — both the nested-mock and CallInfo TODOs) and
MoqCodeFixProvider (MockolateM001 — nested-mock TODO).
- Rename ApplySetupTrivia → ApplyTodoTrivia and update its summary
  comment: the helper is no longer setup-specific, it is invoked from
  setup-call, setup-property, method verify, property verify, and
  event raise rewrite paths.
- Simplify Moq DetectLineEnding to a LINQ Where/Select/FirstOrDefault
  expression (Sonar S3267).
Copilot AI review requested due to automatic review settings May 15, 2026 07:19
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

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

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

@vbreuss vbreuss merged commit a05594a into main May 15, 2026
13 checks passed
@vbreuss vbreuss deleted the feat/nested-mock-todo-comments branch May 15, 2026 07:23
@github-actions
Copy link
Copy Markdown

This is addressed in release v0.6.0.

@github-actions github-actions Bot added the state: released The issue is released label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants