Skip to content

feat: add UseConstructorParametersFor to mock behavior#340

Merged
vbreuss merged 4 commits intomainfrom
topic/add-useconstructorparametersfor
Jan 3, 2026
Merged

feat: add UseConstructorParametersFor to mock behavior#340
vbreuss merged 4 commits intomainfrom
topic/add-useconstructorparametersfor

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Jan 3, 2026

This PR adds a new UseConstructorParametersFor feature to MockBehavior, allowing users to configure default constructor parameters for specific mock types at the behavior level. This enables shared constructor parameter configuration across multiple mock instances without requiring explicit parameters for each Mock.Create call.

Key changes:

  • Added UseConstructorParametersFor<T> methods to MockBehavior supporting both explicit parameters and factory functions
  • Integrated constructor parameter resolution into the source generator's mock registration logic

@vbreuss vbreuss self-assigned this Jan 3, 2026
Copilot AI review requested due to automatic review settings January 3, 2026 16:58
@vbreuss vbreuss added the enhancement New feature or request label Jan 3, 2026
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 a new UseConstructorParametersFor feature to MockBehavior, allowing users to configure default constructor parameters for specific mock types at the behavior level. This enables shared constructor parameter configuration across multiple mock instances without requiring explicit parameters for each Mock.Create call.

Key changes:

  • Added UseConstructorParametersFor<T> methods to MockBehavior supporting both explicit parameters and factory functions
  • Integrated constructor parameter resolution into the source generator's mock registration logic
  • Added special handling for HttpClient to automatically inject a mocked HttpClientHandler dependency

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Source/Mockolate/MockBehavior.cs Implements UseConstructorParametersFor methods and TryGetConstructorParameters for storing and retrieving type-specific constructor parameters
Source/Mockolate.SourceGenerators/Sources/Sources.MockRegistration.cs Integrates behavior-based constructor parameter resolution into mock creation logic
Source/Mockolate.SourceGenerators/Sources/Sources.MockBehaviorExtensions.cs Conditionally initializes default MockBehavior with HttpClient constructor parameters when needed
Source/Mockolate.SourceGenerators/MockGenerator.cs Moves MockBehaviorExtensions generation to execution phase to support conditional HttpClient handling
Tests/Mockolate.Tests/MockBehaviorTests.UseConstructorParametersForTests.cs Validates that constructor parameters from behavior are used correctly and can be overridden
Tests/Mockolate.Api.Tests/Expected/*.txt Updates API surface baseline files with new public methods

@github-actions
Copy link

github-actions bot commented Jan 3, 2026

Test Results

    14 files  ± 0      14 suites  ±0   5m 6s ⏱️ +10s
 1 800 tests + 3   1 799 ✅ + 3  1 💤 ±0  0 ❌ ±0 
12 017 runs  +21  12 016 ✅ +21  1 💤 ±0  0 ❌ ±0 

Results for commit 0507b33. ± Comparison against base commit e8e30d7.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 3, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.64GHz, 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.518 μs 0.0174 μs 0.0154 μs 0.2270 - 3.71 KB
Simple_Moq 174.632 μs 0.4543 μs 0.3794 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.589 μs 0.0270 μs 0.0239 μs 0.5493 0.0076 9.09 KB
Simple_FakeItEasy 6.254 μs 0.0191 μs 0.0169 μs 0.4959 - 8.11 KB

Copilot AI review requested due to automatic review settings January 3, 2026 19:15
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 3, 2026

@vbreuss vbreuss enabled auto-merge (squash) January 3, 2026 19:21
@vbreuss vbreuss merged commit 69f3ac2 into main Jan 3, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/add-useconstructorparametersfor branch January 3, 2026 19:22
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

This is addressed in release v0.49.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.

2 participants