Skip to content

feat: migrate NSubstitute Received/DidNotReceive to Mock.Verify#44

Merged
vbreuss merged 1 commit into
mainfrom
topic/nsubstitute-4
May 1, 2026
Merged

feat: migrate NSubstitute Received/DidNotReceive to Mock.Verify#44
vbreuss merged 1 commit into
mainfrom
topic/nsubstitute-4

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 1, 2026

This pull request adds support for migrating NSubstitute "Received" and "DidNotReceive" verification calls to their Mockolate equivalents in the code fixer, and introduces comprehensive tests to verify this functionality. The main changes include implementing logic to identify and rewrite verification calls, updating the code fix provider to handle these rewrites, and ensuring the correct using directives are added. Additionally, new tests cover various verification scenarios to ensure correctness.

NSubstitute Verification Migration

  • Added FindAndBuildVerifyReplacements and related helper methods to identify and rewrite NSubstitute verification calls (Received, DidNotReceive) to the corresponding Mockolate verification calls (AtLeastOnce, Never, Exactly, Once) in NSubstituteCodeFixProvider.cs.
  • Updated the node replacement logic in ConvertAssertionAsync to apply these verification rewrites during code fix application.
  • Ensured that the necessary using Mockolate.Verify; directive is added when verification rewrites are present.

Testing

  • Added a new test suite VerifyTests in NSubstituteCodeFixProviderTests.VerifyTests.cs to verify that various forms of NSubstitute verification calls are correctly rewritten to the appropriate Mockolate calls, including argument matchers and count-based verifications.

@vbreuss vbreuss self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 09:42
@vbreuss vbreuss added the enhancement New feature or request label May 1, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Test Results

  3 files  ± 0    3 suites  ±0   2m 24s ⏱️ +20s
106 tests + 5  106 ✅ + 5  0 💤 ±0  0 ❌ ±0 
318 runs  +15  318 ✅ +15  0 💤 ±0  0 ❌ ±0 

Results for commit ecd1d36. ± Comparison against base commit b8fbae0.

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

Adds NSubstitute verification migration support to the analyzer/code-fix pipeline by rewriting Received/DidNotReceive assertions into Mockolate Mock.Verify calls, along with new tests to lock in the behavior.

Changes:

  • Extend NSubstituteCodeFixProvider to detect and rewrite sub.Received(...).X(...) / sub.DidNotReceive().X(...) into sub.Mock.Verify.X(...).<count>().
  • Conditionally add using Mockolate.Verify; when verification rewrites are applied.
  • Add new verification-focused code-fix tests covering Received, DidNotReceive, exact counts, and arg matcher translation.

Reviewed changes

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

File Description
Tests/Mockolate.Migration.Tests/NSubstituteCodeFixProviderTests.VerifyTests.cs Adds code-fix tests for migrating NSubstitute Received/DidNotReceive to Mockolate verification APIs.
Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Implements verification rewrite detection and transformation, plus conditional Mockolate.Verify using insertion.

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

@vbreuss vbreuss merged commit 61ab8ec into main May 1, 2026
13 checks passed
@vbreuss vbreuss deleted the topic/nsubstitute-4 branch May 1, 2026 09:49
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

This is addressed in release v0.5.0.

@github-actions github-actions Bot added the state: released The issue is released label May 1, 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