Skip to content

feat: migrate NSubstitute Raise.Event/EventWith to Mock.Raise#46

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

feat: migrate NSubstitute Raise.Event/EventWith to Mock.Raise#46
vbreuss merged 2 commits into
mainfrom
topic/nsubstitute-6

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 1, 2026

This pull request adds support for migrating NSubstitute Raise.Event and Raise.EventWith event-raising patterns to the equivalent Mockolate event-raising syntax in the code fixer. It introduces logic to correctly translate various usages of event raising, handling different argument patterns, and adds comprehensive tests to ensure correctness.

NSubstitute event raising migration:

  • Added a new method FindAndBuildRaiseReplacements to identify and translate Raise.Event and Raise.EventWith usages on event subscriptions to the appropriate Mock.Raise.EventName(...) syntax, handling different argument scenarios (e.g., no arguments, only event args, or sender plus event args).
  • Integrated the new replacements into the main conversion pipeline by updating the list of nodes to replace and the node replacement logic in ConvertAssertionAsync.

Testing:

  • Added a new test class RaiseTests in NSubstituteCodeFixProviderTests.RaiseTests.cs with multiple test cases covering all supported event-raising patterns, ensuring correct translation for delegate-type events, no-argument events, events with only event args, and events with both sender and event args.

@vbreuss vbreuss self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 10:02
@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 4s ⏱️ ±0s
112 tests + 4  112 ✅ + 4  0 💤 ±0  0 ❌ ±0 
336 runs  +12  336 ✅ +12  0 💤 ±0  0 ❌ ±0 

Results for commit 34e6c95. ± Comparison against base commit ecc622f.

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 Raise.Event / Raise.EventWith migration support to the NSubstitute code fix provider, aligning event-raising patterns with Mockolate’s Mock.Raise API.

Changes:

  • Introduces new unit tests covering core Raise.Event and Raise.EventWith rewrite scenarios.
  • Extends NSubstituteCodeFixProvider to detect += Raise.*(...) patterns on tracked substitutes and rewrite them to sub.Mock.Raise.<EventName>(...).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
Tests/Mockolate.Migration.Tests/NSubstituteCodeFixProviderTests.RaiseTests.cs Adds test coverage for Raise-to-Mock.Raise migrations.
Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Implements Raise replacement detection and argument translation logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Source/Mockolate.Migration.Analyzers.CodeFixers/NSubstituteCodeFixProvider.cs Outdated
@vbreuss vbreuss enabled auto-merge (squash) May 1, 2026 10:18
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

@vbreuss vbreuss disabled auto-merge May 1, 2026 10:20
@vbreuss vbreuss merged commit a15aec3 into main May 1, 2026
7 checks passed
@vbreuss vbreuss deleted the topic/nsubstitute-6 branch May 1, 2026 10:20
@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