Skip to content

feat: add WithDefaultValueFor to mock behavior#377

Merged
vbreuss merged 5 commits into
mainfrom
topic/add-defaultvaluefactory
Jan 18, 2026
Merged

feat: add WithDefaultValueFor to mock behavior#377
vbreuss merged 5 commits into
mainfrom
topic/add-defaultvaluefactory

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Jan 18, 2026

This PR adds a new WithDefaultValueFor method to the MockBehavior class, allowing users to configure custom default value factories for specific types when creating mocks.

Key Changes:

  • Introduces a new DefaultValueFactory class for generating default values based on type predicates
  • Adds WithDefaultValueFor methods to MockBehavior for configuring type-specific default values

@vbreuss vbreuss self-assigned this Jan 18, 2026
@vbreuss vbreuss added the enhancement New feature or request label Jan 18, 2026
Copilot AI review requested due to automatic review settings January 18, 2026 06:51
Copy link
Copy Markdown

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 WithDefaultValueFor method to the MockBehavior class, allowing users to configure custom default value factories for specific types when creating mocks.

Changes:

  • Introduces a new DefaultValueFactory class for generating default values based on type predicates
  • Adds WithDefaultValueFor methods to MockBehavior for configuring type-specific default values
  • Reorganizes test methods in UseConstructorParametersForTests for better logical ordering

Reviewed changes

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

Show a summary per file
File Description
Source/Mockolate/DefaultValueFactory.cs New class providing extensible mechanism for type-based default value generation
Source/Mockolate/MockBehavior.cs Adds WithDefaultValueFor methods and internal generator wrapper to support custom default value factories
Tests/Mockolate.Tests/MockBehaviorTests.WithDefaultValueForTests.cs Comprehensive test coverage for the new default value factory functionality
Tests/Mockolate.Tests/MockBehaviorTests.UseConstructorParametersForTests.cs Reorders test methods without changing functionality
Tests/Mockolate.Api.Tests/Expected/Mockolate_netstandard2.0.txt Updates API surface for .NET Standard 2.0
Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt Updates API surface for .NET 8.0
Tests/Mockolate.Api.Tests/Expected/Mockolate_net10.0.txt Updates API surface for .NET 10.0

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 18, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.59GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.102
[Host] : .NET 10.0.2 (10.0.2, 10.0.225.61305), 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.582 μs 0.0149 μs 0.0125 μs 0.2270 - 3.73 KB
Simple_Moq 174.017 μs 1.1516 μs 1.0772 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.836 μs 0.0439 μs 0.0411 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.291 μs 0.0528 μs 0.0494 μs 0.4959 - 8.11 KB

Copilot AI review requested due to automatic review settings January 18, 2026 06:57
Copy link
Copy Markdown

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 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread Source/Mockolate/DefaultValueFactory.cs
Comment thread Source/Mockolate/MockBehavior.cs Outdated
@vbreuss vbreuss enabled auto-merge (squash) January 18, 2026 07:00
@vbreuss vbreuss disabled auto-merge January 18, 2026 07:03
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 18, 2026

Test Results

    14 files  ± 0      14 suites  ±0   5m 59s ⏱️ + 1m 7s
 2 301 tests + 6   2 300 ✅ + 6  1 💤 ±0  0 ❌ ±0 
15 412 runs  +42  15 411 ✅ +42  1 💤 ±0  0 ❌ ±0 

Results for commit 3f16858. ± Comparison against base commit 58154b2.

This pull request removes 2 and adds 8 tests. Note that renamed tests count towards both.
Mockolate.Tests.MockBehaviorTests+UseConstructorParametersForTests ‑ UseConstructorParametersFor_WithExplicitParameters_ShouldUseConstructorParametersFromBehavior
Mockolate.Tests.MockBehaviorTests+UseConstructorParametersForTests ‑ UseConstructorParametersFor_WithPredicate_ShouldUseConstructorParametersFromBehavior
Mockolate.Tests.DefaultValueFactoryTests ‑ CanGenerateValue_ShouldFallbackToFalse
Mockolate.Tests.DefaultValueFactoryTests ‑ GenerateValue_ShouldFallbackToAlwaysReturnNull
Mockolate.Tests.MockBehaviorTests+UseConstructorParametersForTests ‑ WithExplicitParameters_ShouldUseConstructorParametersFromBehavior
Mockolate.Tests.MockBehaviorTests+UseConstructorParametersForTests ‑ WithPredicate_ShouldUseConstructorParametersFromBehavior
Mockolate.Tests.MockBehaviorTests+WithDefaultValueForTests ‑ MultipleTypedFactories_ShouldSupportAll
Mockolate.Tests.MockBehaviorTests+WithDefaultValueForTests ‑ WithExplicitDefaultValueFactory_ShouldApplyThisFactory
Mockolate.Tests.MockBehaviorTests+WithDefaultValueForTests ‑ WithTypedFactory_ShouldRequireExactTypeMatch
Mockolate.Tests.MockBehaviorTests+WithDefaultValueForTests ‑ WithTypedFactory_ShouldUseDefaultValueFactoryFromBehavior

♻️ This comment has been updated with latest results.

Copilot AI review requested due to automatic review settings January 18, 2026 07:07
@vbreuss vbreuss enabled auto-merge (squash) January 18, 2026 07:07
Copy link
Copy Markdown

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 9 out of 9 changed files in this pull request and generated no new comments.

@sonarqubecloud
Copy link
Copy Markdown

@vbreuss vbreuss merged commit 15f048c into main Jan 18, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/add-defaultvaluefactory branch January 18, 2026 07:12
@github-actions
Copy link
Copy Markdown

This is addressed in release v0.53.0.

@github-actions github-actions Bot added the state: released The issue is released label Jan 18, 2026
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.

Support adding custom default value factories

2 participants