Skip to content

feat: migrate ReturnsForAnyArgs/ThrowsForAnyArgs with AnyParameters chain#52

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

feat: migrate ReturnsForAnyArgs/ThrowsForAnyArgs with AnyParameters chain#52
vbreuss merged 2 commits into
mainfrom
topic/nsubstitute-12

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 1, 2026

This pull request updates the migration logic and tests for NSubstitute-to-Mockolate code fixes, specifically improving support for the .ReturnsForAnyArgs and .ThrowsForAnyArgs methods. The main changes include enhancing the code fix provider to handle these cases by appending .AnyParameters() and renaming the configurator methods, as well as adding comprehensive tests to verify these scenarios.

Migration logic improvements

  • Updated TryBuildSequentialOuter in NSubstituteCodeFixProvider.cs to handle .ReturnsForAnyArgs and .ThrowsForAnyArgs by appending .AnyParameters() to the setup receiver and renaming the configurator to its non-ForAnyArgs form, including support for multi-argument calls and preserving generic type arguments.
  • Added a helper method RenameConfiguratorIdentifier to correctly rename configurator methods while preserving type arguments.

Test coverage enhancements

  • Added tests to verify that .ReturnsForAnyArgs is migrated to .AnyParameters().Returns, including both single and multiple argument cases.
  • Added a test to verify that .ThrowsForAnyArgs<T> is migrated to .AnyParameters().Throws<T>, ensuring generic type arguments are preserved.

@vbreuss vbreuss self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 12:46
@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 ⏱️ -8s
131 tests + 5  131 ✅ + 5  0 💤 ±0  0 ❌ ±0 
393 runs  +15  393 ✅ +15  0 💤 ±0  0 ❌ ±0 

Results for commit e575de1. ± Comparison against base commit 9cdbeca.

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

Extends the NSubstitute-to-Mockolate migration code fix to correctly translate ReturnsForAnyArgs / ThrowsForAnyArgs configurators by injecting an .AnyParameters() call and renaming to the non-ForAnyArgs equivalent, with accompanying regression tests.

Changes:

  • Update NSubstituteCodeFixProvider to rewrite ReturnsForAnyArgs / ThrowsForAnyArgs into .AnyParameters().Returns(...) / .AnyParameters().Throws(...), including chaining behavior when multiple values are provided.
  • Add new code-fix tests covering ReturnsForAnyArgs (single + sequential) and generic parameterless ThrowsForAnyArgs<T>().

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.SetupTests.cs Adds regression tests for ReturnsForAnyArgs and ThrowsForAnyArgs migrations to ensure .AnyParameters() injection and renaming work.
Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Implements the setup-chain rewrite for *ForAnyArgs configurators (and preserves generic type args when renaming).

💡 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
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

@vbreuss vbreuss merged commit 226cc12 into main May 1, 2026
9 checks passed
@vbreuss vbreuss deleted the topic/nsubstitute-12 branch May 1, 2026 13:04
@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