feat: migrate Substitute.For/ForPartsOf/ForTypeForwardingTo to CreateMock#42
Merged
Conversation
8136140 to
b96c827
Compare
There was a problem hiding this comment.
Pull request overview
Adds NSubstitute creation-call migration support to the analyzer/code-fix suite by translating Substitute.For(...), Substitute.ForPartsOf(...), and Substitute.ForTypeForwardingTo(...) into the Mockolate CreateMock() creation pattern and validating it with new tests.
Changes:
- Introduces
NSubstituteCodeFixProviderto convert NSubstitute substitute creation calls intoCreateMock()+Implementing<...>()/Wrapping(...)chains. - Adds a new test suite covering the supported creation APIs and constructor-argument preservation.
- Ensures
using Mockolate;is added when required (and not duplicated when already present).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Tests/Mockolate.Migration.Tests/NSubstituteCodeFixProviderTests.CreationTests.cs | Adds code-fix tests for migrating NSubstitute substitute creation patterns to Mockolate CreateMock(). |
| Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs | Implements the NSubstitute-to-Mockolate creation-call code fix and adds using Mockolate; when needed. |
💡 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 introduces a new Roslyn code fix provider to automate migration from NSubstitute to Mockolate, along with a comprehensive suite of tests to verify the migration logic. The main focus is on transforming NSubstitute mock creation patterns into their Mockolate equivalents, handling multiple scenarios and ensuring correct namespace usage.
New code fix provider for NSubstitute-to-Mockolate migration
NSubstituteCodeFixProviderinNSubstituteCodeFixProvider.cs, which detects and rewritesSubstitute.For,Substitute.ForPartsOf, andSubstitute.ForTypeForwardingTocalls to the appropriate Mockolate mock creation syntax, including handling of multiple interfaces and constructor arguments.using Mockolate;directive is added only if it does not already exist, preventing duplicate usings in the migrated code.Test coverage for migration scenarios
NSubstituteCodeFixProviderTests.CreationTests.cs, providing tests that verify the code fix for various NSubstitute creation patterns, including:Implementing<T>())ForPartsOfandForTypeForwardingTomigration logicusing Mockolate;directives are added