Skip to content

feat: migrate NSubstitute setup calls and Arg matchers#43

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

feat: migrate NSubstitute setup calls and Arg matchers#43
vbreuss merged 2 commits into
mainfrom
topic/nsubstitute-3

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 1, 2026

This pull request significantly enhances the NSubstitute-to-Mockolate migration code fix provider by adding support for rewriting NSubstitute setup/configuration calls and their argument matchers, along with comprehensive tests for these scenarios. The changes introduce logic to identify and transform NSubstitute's setup methods (like Returns, Throws, etc.) and argument matchers (like Arg.Any, Arg.Is) into their Mockolate equivalents.

The most important changes include:

Core migration logic improvements

  • Added logic to identify NSubstitute setup/configurator methods (e.g., Returns, Throws) and rewrite them to Mockolate's Mock.Setup pattern in NSubstituteCodeFixProvider. This includes handling both method and property setups.
  • Implemented transformation of NSubstitute argument matchers (Arg.Any, Arg.Is, etc.) to the corresponding Mockolate It matchers (It.IsAny, It.Is, It.Satisfies). This ensures argument matching semantics are preserved during migration.

Test coverage

  • Added a new test class SetupTests in NSubstituteCodeFixProviderTests to verify the correct rewriting of various NSubstitute setup patterns and argument matchers to Mockolate equivalents. These tests cover method setups, property setups, exception setups, and multiple argument matchers.
  • Refactored the test class structure to allow for partial class extension, enabling separation of creation and setup tests.

Code quality and maintainability

  • Disabled specific code analysis warnings to allow for higher cognitive complexity and string literal duplication in the analyzer code, acknowledging the complexity inherent in code transformation logic.
  • Added necessary using directives for collections to support new logic.

@vbreuss vbreuss self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 09:20
@vbreuss vbreuss added the enhancement New feature or request label 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 9s ⏱️ +12s
101 tests + 8  101 ✅ + 8  0 💤 ±0  0 ❌ ±0 
303 runs  +24  303 ✅ +24  0 💤 ±0  0 ❌ ±0 

Results for commit c72ae76. ± Comparison against base commit 5c98b8a.

♻️ 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

Adds NSubstitute setup/matcher migration behavior to the NSubstitute code fix, along with new tests verifying the rewritten setup calls and translated Arg.* matchers.

Changes:

  • Extend NSubstituteCodeFixProvider to also rewrite NSubstitute setup/configuration call receivers to .<mock>.Mock.Setup.<member>(...) and translate Arg.Any / Arg.Is to It.*.
  • Add a new SetupTests test suite covering method/property setup rewrites and matcher translations.
  • Convert NSubstituteCodeFixProviderTests to a partial class to split test suites across files.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
Tests/Mockolate.Migration.Tests/NSubstituteCodeFixProviderTests.SetupTests.cs New tests validating setup/matcher rewrites for NSubstitute migrations.
Tests/Mockolate.Migration.Tests/NSubstituteCodeFixProviderTests.CreationTests.cs Make test container class partial to share across new test file.
Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Implement setup receiver rewriting and Arg.* matcher translation during creation-call migration.

💡 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
Comment thread Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Outdated
Comment thread Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Outdated
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

@vbreuss vbreuss merged commit b8fbae0 into main May 1, 2026
9 checks passed
@vbreuss vbreuss deleted the topic/nsubstitute-3 branch May 1, 2026 09:36
@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