From 731ee2b6acb3edaf8321d2d122b848127aa808f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sat, 31 Jan 2026 12:38:09 +0100 Subject: [PATCH 1/2] docs: document advanced MockBehavior configuration options --- Docs/pages/01-create-mocks.md | 16 +++++++++++++++ Docs/pages/special-types/02-delegates.md | 10 ++++----- README.md | 26 +++++++++++++++++++----- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Docs/pages/01-create-mocks.md b/Docs/pages/01-create-mocks.md index 7af4a971..76afa179 100644 --- a/Docs/pages/01-create-mocks.md +++ b/Docs/pages/01-create-mocks.md @@ -49,6 +49,9 @@ var classMock = Mock.Create( - If `true`, the mock will not call any base class implementations. - `Initialize(params Action>[] setups)`: - Automatically initialize all mocks of type T with the given setups when they are created. + - The callback can optionally receive an additional counter parameter which allows to differentiate between multiple + instances. This is useful when you want to ensure that you can distinguish between different automatically created + instances. - `DefaultValue` (IDefaultValueGenerator): - Customizes how default values are generated for methods/properties that are not set up. - The default implementation provides sensible defaults for the most common use cases: @@ -57,6 +60,19 @@ var classMock = Mock.Create( - Completed tasks for `Task`, `Task`, `ValueTask` and `ValueTask` - Tuples with recursively defaulted values - `null` for other reference types + - You can provide custom default values for specific types using `.WithDefaultValueFor()`: + ```csharp + var behavior = MockBehavior.Default + .WithDefaultValueFor(() => "default") + .WithDefaultValueFor(() => 42); + var sut = Mock.Create(behavior); + ``` + This is useful when you want mocks to return specific default values for certain types instead of the standard + defaults (e.g., `null`, `0`, empty strings). +- `.UseConstructorParametersFor(object?[])`: + - Configures constructor parameters to use when creating mocks of type `T`, unless explicit parameters are provided + during mock + creation via `BaseClass.WithConstructorParameters(…)`. ## Using a factory for shared behavior diff --git a/Docs/pages/special-types/02-delegates.md b/Docs/pages/special-types/02-delegates.md index 15a21087..85fac4e9 100644 --- a/Docs/pages/special-types/02-delegates.md +++ b/Docs/pages/special-types/02-delegates.md @@ -4,7 +4,7 @@ Mockolate supports mocking delegates including `Action`, `Func`, and custom d **Setup** -Use `SetupMock.Delegate(...)` to configure delegate behavior. +Use `SetupMock.Delegate(…)` to configure delegate behavior. ```csharp // Mock Action delegate @@ -39,10 +39,10 @@ ProcessData processor = Mock.Create(); processor.SetupMock.Delegate(It.IsAny(), It.IsRef(v => v + 1), It.IsOut(() => 100)); ``` -- Use `.Do(...)` to run code when the delegate is invoked. -- Use `.Returns(...)` to specify the return value for `Func` delegates. -- Use `.Throws(...)` to specify an exception to throw. -- Use `.Returns(...)` and `.Throws(...)` repeatedly to define a sequence of behaviors. +- Use `.Do(…)` to run code when the delegate is invoked. +- Use `.Returns(…)` to specify the return value for `Func` delegates. +- Use `.Throws(…)` to specify an exception to throw. +- Use `.Returns(…)` and `.Throws(…)` repeatedly to define a sequence of behaviors. - Full [parameter matching](https://awexpect.com/docs/mockolate/setup#parameter-matching) support for delegate parameters including `ref` and `out` parameters. diff --git a/README.md b/README.md index d19fe91e..35bdb3b1 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,9 @@ var classMock = Mock.Create( - If `true`, the mock will not call any base class implementations. - `Initialize(params Action>[] setups)`: - Automatically initialize all mocks of type T with the given setups when they are created. + - The callback can optionally receive an additional counter parameter which allows to differentiate between multiple + instances. This is useful when you want to ensure that you can distinguish between different automatically created + instances. - `DefaultValue` (IDefaultValueGenerator): - Customizes how default values are generated for methods/properties that are not set up. - The default implementation provides sensible defaults for the most common use cases: @@ -134,6 +137,19 @@ var classMock = Mock.Create( - Completed tasks for `Task`, `Task`, `ValueTask` and `ValueTask` - Tuples with recursively defaulted values - `null` for other reference types + - You can provide custom default values for specific types using `.WithDefaultValueFor()`: + ```csharp + var behavior = MockBehavior.Default + .WithDefaultValueFor(() => "default") + .WithDefaultValueFor(() => 42); + var sut = Mock.Create(behavior); + ``` + This is useful when you want mocks to return specific default values for certain types instead of the standard + defaults (e.g., `null`, `0`, empty strings). +- `.UseConstructorParametersFor(object?[])`: + - Configures constructor parameters to use when creating mocks of type `T`, unless explicit parameters are provided + during mock + creation via `BaseClass.WithConstructorParameters(…)`. ### Using a factory for shared behavior @@ -785,7 +801,7 @@ Mockolate supports mocking delegates including `Action`, `Func`, and custom d **Setup** -Use `SetupMock.Delegate(...)` to configure delegate behavior. +Use `SetupMock.Delegate(…)` to configure delegate behavior. ```csharp // Mock Action delegate @@ -820,10 +836,10 @@ ProcessData processor = Mock.Create(); processor.SetupMock.Delegate(It.IsAny(), It.IsRef(v => v + 1), It.IsOut(() => 100)); ``` -- Use `.Do(...)` to run code when the delegate is invoked. -- Use `.Returns(...)` to specify the return value for `Func` delegates. -- Use `.Throws(...)` to specify an exception to throw. -- Use `.Returns(...)` and `.Throws(...)` repeatedly to define a sequence of behaviors. +- Use `.Do(…)` to run code when the delegate is invoked. +- Use `.Returns(…)` to specify the return value for `Func` delegates. +- Use `.Throws(…)` to specify an exception to throw. +- Use `.Returns(…)` and `.Throws(…)` repeatedly to define a sequence of behaviors. - Full [parameter matching](#parameter-matching) support for delegate parameters including `ref` and `out` parameters. From 0f399be232847b7739ea7cb04457cb6f51b021ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sat, 31 Jan 2026 12:40:09 +0100 Subject: [PATCH 2/2] Fix line breaks --- Docs/pages/01-create-mocks.md | 3 +-- README.md | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Docs/pages/01-create-mocks.md b/Docs/pages/01-create-mocks.md index 76afa179..9484d29d 100644 --- a/Docs/pages/01-create-mocks.md +++ b/Docs/pages/01-create-mocks.md @@ -71,8 +71,7 @@ var classMock = Mock.Create( defaults (e.g., `null`, `0`, empty strings). - `.UseConstructorParametersFor(object?[])`: - Configures constructor parameters to use when creating mocks of type `T`, unless explicit parameters are provided - during mock - creation via `BaseClass.WithConstructorParameters(…)`. + during mock creation via `BaseClass.WithConstructorParameters(…)`. ## Using a factory for shared behavior diff --git a/README.md b/README.md index 35bdb3b1..013ccbe2 100644 --- a/README.md +++ b/README.md @@ -148,8 +148,7 @@ var classMock = Mock.Create( defaults (e.g., `null`, `0`, empty strings). - `.UseConstructorParametersFor(object?[])`: - Configures constructor parameters to use when creating mocks of type `T`, unless explicit parameters are provided - during mock - creation via `BaseClass.WithConstructorParameters(…)`. + during mock creation via `BaseClass.WithConstructorParameters(…)`. ### Using a factory for shared behavior