feat: migrate ReturnsForAnyArgs/ThrowsForAnyArgs with AnyParameters chain#52
Merged
Conversation
There was a problem hiding this comment.
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
NSubstituteCodeFixProviderto rewriteReturnsForAnyArgs/ThrowsForAnyArgsinto.AnyParameters().Returns(...)/.AnyParameters().Throws(...), including chaining behavior when multiple values are provided. - Add new code-fix tests covering
ReturnsForAnyArgs(single + sequential) and generic parameterlessThrowsForAnyArgs<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.
|
|
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 updates the migration logic and tests for NSubstitute-to-Mockolate code fixes, specifically improving support for the
.ReturnsForAnyArgsand.ThrowsForAnyArgsmethods. 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
TryBuildSequentialOuterinNSubstituteCodeFixProvider.csto handle.ReturnsForAnyArgsand.ThrowsForAnyArgsby appending.AnyParameters()to the setup receiver and renaming the configurator to its non-ForAnyArgsform, including support for multi-argument calls and preserving generic type arguments.RenameConfiguratorIdentifierto correctly rename configurator methods while preserving type arguments.Test coverage enhancements
.ReturnsForAnyArgsis migrated to.AnyParameters().Returns, including both single and multiple argument cases..ThrowsForAnyArgs<T>is migrated to.AnyParameters().Throws<T>, ensuring generic type arguments are preserved.