Skip to content

Comments

refactor!: always use Do for callbacks#290

Merged
vbreuss merged 1 commit intomainfrom
topic/always-use-do
Dec 8, 2025
Merged

refactor!: always use Do for callbacks#290
vbreuss merged 1 commit intomainfrom
topic/always-use-do

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Dec 8, 2025

This PR refactors the callback API for properties and indexers by introducing a mandatory Do method, replacing the previous pattern where OnGet and OnSet directly accepted callbacks. This is a breaking change that improves API clarity and consistency.

Key Changes:

  • Changed OnGet and OnSet from methods accepting callbacks to properties returning setup interfaces
  • Introduced IPropertyGetterSetup/IPropertySetterSetup and IIndexerGetterSetup/IIndexerSetterSetup interfaces with Do methods
  • Updated all test files to use the new OnGet.Do(...) and OnSet.Do(...) syntax

@vbreuss vbreuss self-assigned this Dec 8, 2025
Copilot AI review requested due to automatic review settings December 8, 2025 15:05
@vbreuss vbreuss added the breaking change The changes require a new major version label Dec 8, 2025
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 callback API for properties and indexers by introducing a mandatory Do method, replacing the previous pattern where OnGet and OnSet directly accepted callbacks. This is a breaking change that improves API clarity and consistency.

Key Changes:

  • Changed OnGet and OnSet from methods accepting callbacks to properties returning setup interfaces
  • Introduced IPropertyGetterSetup/IPropertySetterSetup and IIndexerGetterSetup/IIndexerSetterSetup interfaces with Do methods
  • Updated all test files to use the new OnGet.Do(...) and OnSet.Do(...) syntax

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Tests/Mockolate.Tests/Protected/ProtectedMockTests.cs Updated protected indexer tests to use new .Do() callback API
Tests/Mockolate.Tests/MockProperties/SetupPropertyTests.OnSetTests.cs Updated property setter tests to use OnSet.Do(...) instead of OnSet(...)
Tests/Mockolate.Tests/MockProperties/SetupPropertyTests.OnGetTests.cs Updated property getter tests to use OnGet.Do(...) instead of OnGet(...)
Tests/Mockolate.Tests/MockIndexers/SetupIndexerTests.OnSetTests.cs Updated indexer setter tests to use new OnSet.Do(...) pattern across all parameter counts
Tests/Mockolate.Tests/MockIndexers/SetupIndexerTests.OnGetTests.cs Updated indexer getter tests to use new OnGet.Do(...) pattern across all parameter counts
Tests/Mockolate.Api.Tests/Expected/Mockolate_netstandard2.0.txt Updated API baseline to reflect new property/indexer setup interfaces
Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt Updated API baseline for .NET 8 target
Tests/Mockolate.Api.Tests/Expected/Mockolate_net10.0.txt Updated API baseline for .NET 10 target
Source/Mockolate/Setup/PropertySetup.cs Implemented new OnGet/OnSet properties and explicit interface implementations for Do methods
Source/Mockolate/Setup/Interfaces.PropertySetup.cs Introduced IPropertyGetterSetup and IPropertySetterSetup interfaces, refactored IPropertySetup
Source/Mockolate/Setup/Interfaces.IndexerSetup.cs Introduced IIndexerGetterSetup and IIndexerSetterSetup interfaces for all parameter counts
Source/Mockolate/Setup/IndexerSetup.cs Implemented new indexer setup pattern with OnGet/OnSet properties and explicit interface implementations
Source/Mockolate.SourceGenerators/Sources/Sources.IndexerSetups.cs Updated source generator to produce new interface definitions and implementations

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 8, 2025

@vbreuss vbreuss enabled auto-merge (squash) December 8, 2025 15:09
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

Test Results

    14 files  ±0      14 suites  ±0   3m 53s ⏱️ -24s
 1 505 tests ±0   1 504 ✅ ±0  1 💤 ±0  0 ❌ ±0 
10 024 runs  ±0  10 023 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 86ceb19. ± Comparison against base commit c12edb5.

@vbreuss vbreuss merged commit 1820d7a into main Dec 8, 2025
12 checks passed
@vbreuss vbreuss deleted the topic/always-use-do branch December 8, 2025 15:09
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.88GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), 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.500 μs 0.0346 μs 0.0323 μs 0.2213 - 3.62 KB
Simple_Moq 177.844 μs 1.3821 μs 1.2252 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.834 μs 0.0592 μs 0.0553 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.470 μs 0.0805 μs 0.0753 μs 0.4959 - 8.11 KB

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

This is addressed in release v0.42.0.

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

Labels

breaking change The changes require a new major version state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Always use Do for callbacks

1 participant