Skip to content

Comments

feat: support wrapping concrete instances#293

Merged
vbreuss merged 2 commits intomainfrom
topic/support-wrapping-concrete-instances
Dec 11, 2025
Merged

feat: support wrapping concrete instances#293
vbreuss merged 2 commits intomainfrom
topic/support-wrapping-concrete-instances

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Dec 10, 2025

This PR adds support for wrapping concrete instances with mocks, allowing users to create mock proxies around existing objects that delegate calls to the wrapped instance while still supporting setup and verification.

Key Changes:

  • Added new Mock.Wrap<T>() API methods that accept a concrete instance to wrap
  • Modified source generator to support wrapped instances with conditional delegation logic
  • Generated mocks now check for wrapped instances and delegate calls when no setup is configured

@vbreuss vbreuss self-assigned this Dec 10, 2025
Copilot AI review requested due to automatic review settings December 10, 2025 21:12
@vbreuss vbreuss added the enhancement New feature or request label Dec 10, 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 adds support for wrapping concrete instances with mocks, allowing users to create mock proxies around existing objects that delegate calls to the wrapped instance while still supporting setup and verification.

Key Changes:

  • Added new Mock.Wrap<T>() API methods that accept a concrete instance to wrap
  • Modified source generator to support wrapped instances with conditional delegation logic
  • Generated mocks now check for wrapped instances and delegate calls when no setup is configured

Reviewed changes

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

Show a summary per file
File Description
Tests/Mockolate.Tests/MockTests.WrapTests.cs New test file validating wrap functionality for methods, properties, indexers, and setup overrides
Source/Mockolate.SourceGenerators/Sources/Sources.cs Adds Mock.Wrap<T>() public API methods and supporting infrastructure
Source/Mockolate.SourceGenerators/Sources/Sources.MockRegistration.cs Implements GenerateWrapped<T>() partial method for wrapped mock generation
Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.cs Updates mock implementation generation to include wrapped instance field and delegation logic
Tests/Mockolate.SourceGenerators.Tests/Sources/ForMockTests.ImplementClassTests.cs Updates test assertions to reflect new wrapped instance delegation patterns
Tests/Mockolate.SourceGenerators.Tests/GeneralTests.cs Updates test assertions for wrapped instance support in properties and methods
Comments suppressed due to low confidence (1)

Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.cs:829

  • Extra blank line inside braces. Remove the empty line after the closing brace on line 812 to maintain consistent formatting.

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

Test Results

    14 files  ± 0      14 suites  ±0   4m 49s ⏱️ +4s
 1 534 tests + 7   1 533 ✅ + 7  1 💤 ±0  0 ❌ ±0 
10 227 runs  +49  10 226 ✅ +49  1 💤 ±0  0 ❌ ±0 

Results for commit 0d6eed6. ± Comparison against base commit 2aa8611.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

🚀 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.499 μs 0.0061 μs 0.0054 μs 0.2232 - 3.66 KB
Simple_Moq 180.099 μs 0.6914 μs 0.5774 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.728 μs 0.0282 μs 0.0264 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.399 μs 0.0259 μs 0.0230 μs 0.4959 - 8.11 KB

@sonarqubecloud
Copy link

@vbreuss vbreuss merged commit 436f685 into main Dec 11, 2025
12 checks passed
@vbreuss vbreuss deleted the topic/support-wrapping-concrete-instances branch December 11, 2025 10:07
@github-actions
Copy link

This is addressed in release v0.43.0.

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.

1 participant