Skip to content

Comments

refactor: make HasReturnCalls virtual#327

Merged
vbreuss merged 1 commit intomainfrom
topic/make-hasreturncalls-virtual
Dec 16, 2025
Merged

refactor: make HasReturnCalls virtual#327
vbreuss merged 1 commit intomainfrom
topic/make-hasreturncalls-virtual

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Dec 16, 2025

This PR refactors the HasReturnCalls method in the MethodSetup base class by changing it from an abstract method to a virtual method with a default implementation that returns false. This simplifies derived classes by eliminating the need to override this method in VoidMethodSetup classes, where it consistently returned whether return callbacks exist. The change maintains the same behavior while reducing code duplication across the inheritance hierarchy.

Key Changes

  • Changed HasReturnCalls() from abstract to virtual with a default false return value in MethodSetup
  • Removed redundant HasReturnCalls() overrides from all VoidMethodSetup variations
  • Removed unnecessary null checks in ReturnMethodSetup implementations

@vbreuss vbreuss self-assigned this Dec 16, 2025
Copilot AI review requested due to automatic review settings December 16, 2025 07:44
Copy link

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

This PR refactors the HasReturnCalls method in the MethodSetup base class by changing it from an abstract method to a virtual method with a default implementation that returns false. This simplifies derived classes by eliminating the need to override this method in VoidMethodSetup classes, where it consistently returned whether return callbacks exist. The change maintains the same behavior while reducing code duplication across the inheritance hierarchy.

Key Changes

  • Changed HasReturnCalls() from abstract to virtual with a default false return value in MethodSetup
  • Removed redundant HasReturnCalls() overrides from all VoidMethodSetup variations
  • Removed unnecessary null checks in ReturnMethodSetup implementations

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Source/Mockolate/Setup/MethodSetup.cs Changed HasReturnCalls() from abstract to virtual with default implementation
Source/Mockolate/Setup/VoidMethodSetup.cs Removed redundant HasReturnCalls() overrides from all void method setup classes
Source/Mockolate/Setup/ReturnMethodSetup.cs Removed unnecessary null checks before type casting in return value handling
Tests/Mockolate.Tests/MockMethods/SetupMethodTests.cs Added test to verify default behavior and helper method to access protected member
Tests/Mockolate.Api.Tests/Expected/Mockolate_netstandard2.0.txt Updated API surface to reflect the method signature change
Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt Updated API surface to reflect the method signature change
Tests/Mockolate.Api.Tests/Expected/Mockolate_net10.0.txt Updated API surface to reflect the method signature change

@vbreuss vbreuss enabled auto-merge (squash) December 16, 2025 07:46
@sonarqubecloud
Copy link

@github-actions
Copy link

Test Results

    14 files  ±0      14 suites  ±0   5m 24s ⏱️ -23s
 1 781 tests +1   1 780 ✅ +1  1 💤 ±0  0 ❌ ±0 
11 924 runs  +7  11 923 ✅ +7  1 💤 ±0  0 ❌ ±0 

Results for commit 1648cd5. ± Comparison against base commit 9e357f5.

@vbreuss vbreuss merged commit 8e21298 into main Dec 16, 2025
12 checks passed
@vbreuss vbreuss deleted the topic/make-hasreturncalls-virtual branch December 16, 2025 07:49
@github-actions
Copy link

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
[Host] : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.526 μs 0.0154 μs 0.0137 μs 0.2232 - 3.66 KB
Simple_Moq 177.586 μs 1.0829 μs 0.8455 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.944 μs 0.0245 μs 0.0218 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.468 μs 0.0978 μs 0.0914 μs 0.4959 - 8.11 KB

@github-actions
Copy link

This is addressed in release v0.46.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant