Skip to content

Comments

Document advanced MockBehavior configuration options#437

Closed
Copilot wants to merge 4 commits intomainfrom
copilot/document-advanced-mock-options
Closed

Document advanced MockBehavior configuration options#437
Copilot wants to merge 4 commits intomainfrom
copilot/document-advanced-mock-options

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Three MockBehavior configuration methods were implemented but undocumented: custom default value factories, counter-based initialization, and behavior-level constructor parameters.

Changes

  • Added "Advanced Mock Behavior" section to README.md and Docs/pages/01-create-mocks.md with:
    • .WithDefaultValueFor<T>() - Override default values for specific types
    • .Initialize<T>((count, setup) => {...}) - Initialize mocks with incrementing counter
    • .UseConstructorParametersFor<T>() - Set default constructor parameters per type

Example

var behavior = MockBehavior.Default
    .WithDefaultValueFor<string>(() => "default")
    .Initialize<IChocolateDispenser>((count, setup) => 
    {
        setup.Property.TotalDispensed.InitializeWith(count * 10);
    })
    .UseConstructorParametersFor<MyChocolateDispenser>("Dark", 100);

var mock1 = Mock.Create<IChocolateDispenser>(behavior);  // TotalDispensed == 10
var mock2 = Mock.Create<IChocolateDispenser>(behavior);  // TotalDispensed == 20
Original prompt

This section details on the original issue you should resolve

<issue_title>Document advanced mock behavior options</issue_title>
<issue_description>## Description

Several advanced mock behavior configuration options are missing from the documentation.

Missing Documentation

  • .WithDefaultValueFor<T>() - Custom default value factories
  • .Initialize<T>(Action<int, IMockSetup<T>>) - Initialize with counter
  • .UseConstructorParametersFor<T>() - Constructor parameter configuration

Suggested Documentation

Expand the "Customizing mock behavior" section with subsection "Advanced Mock Behavior":

Custom Default Value Factories

Provide custom default values for specific types:

var behavior = new MockBehavior()
    .WithDefaultValueFor<string>(() => "default")
    .WithDefaultValueFor<int>(() => 42);

var sut = Mock.Create<IChocolateDispenser>(behavior);

Initialize with Counter

Initialize mocks with a counter to track creation:

var behavior = new MockBehavior()
    .Initialize<IChocolateDispenser>((count, mock) => 
    {
        mock.SetupMock.Property.TotalDispensed.InitializeWith(count * 10);
    });

Constructor Parameters Configuration

Configure constructor parameters for specific types:

var behavior = new MockBehavior()
    .UseConstructorParametersFor<MyChocolateDispenser>("Dark", 100);

var sut = Mock.Create<MyChocolateDispenser>(behavior);
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 31, 2026 09:16
Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com>
Copilot AI changed the title [WIP] Document advanced mock behavior configuration options Document advanced MockBehavior configuration options Jan 31, 2026
Copilot AI requested a review from vbreuss January 31, 2026 09:23
@vbreuss
Copy link
Contributor

vbreuss commented Jan 31, 2026

Obsolete by #439

@vbreuss vbreuss closed this Jan 31, 2026
@vbreuss vbreuss deleted the copilot/document-advanced-mock-options branch February 5, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document advanced mock behavior options

2 participants