Skip to content

Document advanced mock behavior options #424

@vbreuss

Description

@vbreuss

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);

Metadata

Metadata

Labels

documentationImprovements or additions to documentationstate: releasedThe issue is released

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions