feat: migrate NSubstitute Received/DidNotReceive to Mock.Verify#44
Merged
Conversation
|
There was a problem hiding this comment.
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
NSubstituteCodeFixProviderto detect and rewritesub.Received(...).X(...)/sub.DidNotReceive().X(...)intosub.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.
|
This is addressed in release v0.5.0. |
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.



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
FindAndBuildVerifyReplacementsand related helper methods to identify and rewrite NSubstitute verification calls (Received,DidNotReceive) to the corresponding Mockolate verification calls (AtLeastOnce,Never,Exactly,Once) inNSubstituteCodeFixProvider.cs.ConvertAssertionAsyncto apply these verification rewrites during code fix application.using Mockolate.Verify;directive is added when verification rewrites are present.Testing
VerifyTestsinNSubstituteCodeFixProviderTests.VerifyTests.csto verify that various forms of NSubstitute verification calls are correctly rewritten to the appropriate Mockolate calls, including argument matchers and count-based verifications.