Skip to content

feat: migrate Substitute.For/ForPartsOf/ForTypeForwardingTo to CreateMock#42

Merged
vbreuss merged 2 commits into
mainfrom
topic/nsubstitute-2
May 1, 2026
Merged

feat: migrate Substitute.For/ForPartsOf/ForTypeForwardingTo to CreateMock#42
vbreuss merged 2 commits into
mainfrom
topic/nsubstitute-2

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 1, 2026

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

  • Added NSubstituteCodeFixProvider in NSubstituteCodeFixProvider.cs, which detects and rewrites Substitute.For, Substitute.ForPartsOf, and Substitute.ForTypeForwardingTo calls to the appropriate Mockolate mock creation syntax, including handling of multiple interfaces and constructor arguments.
  • Ensures that a using Mockolate; directive is added only if it does not already exist, preventing duplicate usings in the migrated code.

Test coverage for migration scenarios

  • Introduced NSubstituteCodeFixProviderTests.CreationTests.cs, providing tests that verify the code fix for various NSubstitute creation patterns, including:
    • Simple interface/class substitution
    • Substitution with constructor arguments
    • Substitution with multiple interfaces (chaining Implementing<T>())
    • ForPartsOf and ForTypeForwardingTo migration logic
    • Ensuring no duplicate using Mockolate; directives are added

@vbreuss vbreuss self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 08:54
@vbreuss vbreuss added the enhancement New feature or request label May 1, 2026
@vbreuss vbreuss enabled auto-merge (squash) May 1, 2026 08:54
@vbreuss vbreuss force-pushed the topic/nsubstitute-2 branch from 8136140 to b96c827 Compare May 1, 2026 08:57
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 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 NSubstituteCodeFixProvider to convert NSubstitute substitute creation calls into CreateMock() + 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.

Comment thread Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Outdated
Comment thread Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Test Results

  3 files  ± 0    3 suites  ±0   1m 51s ⏱️ - 1m 4s
 93 tests + 9   93 ✅ + 9  0 💤 ±0  0 ❌ ±0 
279 runs  +27  279 ✅ +27  0 💤 ±0  0 ❌ ±0 

Results for commit 26727c0. ± Comparison against base commit c716576.

♻️ This comment has been updated with latest results.

@vbreuss vbreuss disabled auto-merge May 1, 2026 09:12
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

@vbreuss vbreuss enabled auto-merge (squash) May 1, 2026 09:14
@vbreuss vbreuss merged commit 5c98b8a into main May 1, 2026
9 checks passed
@vbreuss vbreuss deleted the topic/nsubstitute-2 branch May 1, 2026 09:15
@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