diff --git a/Docs/pages/01-create-mocks.md b/Docs/pages/01-create-mocks.md index 7af4a971..9484d29d 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,18 @@ 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..013ccbe2 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,18 @@ 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 +800,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 +835,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.