feat: add UseConstructorParametersFor to mock behavior#340
Conversation
There was a problem hiding this comment.
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 toMockBehaviorsupporting both explicit parameters and factory functions - Integrated constructor parameter resolution into the source generator's mock registration logic
- Added special handling for
HttpClientto automatically inject a mockedHttpClientHandlerdependency
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 |
Source/Mockolate.SourceGenerators/Sources/Sources.MockBehaviorExtensions.cs
Outdated
Show resolved
Hide resolved
🚀 Benchmark ResultsDetails
|
Source/Mockolate.SourceGenerators/Sources/Sources.MockBehaviorExtensions.cs
Show resolved
Hide resolved
Tests/Mockolate.Tests/MockBehaviorTests.UseConstructorParametersForTests.cs
Show resolved
Hide resolved
Tests/Mockolate.Tests/MockBehaviorTests.UseConstructorParametersForTests.cs
Show resolved
Hide resolved
|
|
This is addressed in release v0.49.0. |



This PR adds a new
UseConstructorParametersForfeature toMockBehavior, 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 eachMock.Createcall.Key changes:
UseConstructorParametersFor<T>methods toMockBehaviorsupporting both explicit parameters and factory functions