From 19417f05d878f42c06f75c4696675e7a97ac3daf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 09:14:37 +0000 Subject: [PATCH 1/4] Initial plan From 695436d1c0155c8b755a9a22e29c7687fd9078fa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 09:16:07 +0000 Subject: [PATCH 2/4] Add Advanced Mock Behavior documentation Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com> --- Docs/pages/01-create-mocks.md | 49 +++++++++++++++++++++++++++++++++++ README.md | 49 +++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/Docs/pages/01-create-mocks.md b/Docs/pages/01-create-mocks.md index 7af4a971..8c35bc62 100644 --- a/Docs/pages/01-create-mocks.md +++ b/Docs/pages/01-create-mocks.md @@ -58,6 +58,55 @@ var classMock = Mock.Create( - Tuples with recursively defaulted values - `null` for other reference types +### Advanced Mock Behavior + +#### Custom Default Value Factories + +Provide custom default values for specific types using `.WithDefaultValueFor()`: + +```csharp +var behavior = new MockBehavior() + .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). + +#### Initialize with Counter + +Initialize mocks with a counter to track creation order or assign unique identifiers: + +```csharp +var behavior = new MockBehavior() + .Initialize((count, mock) => + { + mock.Indexer(It.Is("Dark")).InitializeWith(count * 10); + }); + +var mock1 = Mock.Create(behavior); +var mock2 = Mock.Create(behavior); + +// mock1["Dark"] == 10 +// mock2["Dark"] == 20 +``` + +The counter starts at 1 and increments with each mock instance created. This is particularly useful when you need to create multiple mocks with slightly different configurations. + +#### Constructor Parameters Configuration + +Configure constructor parameters for specific types at the behavior level: + +```csharp +var behavior = new MockBehavior() + .UseConstructorParametersFor("Dark", 100); + +var sut = Mock.Create(behavior); +``` + +This allows you to define default constructor parameters in the behavior, which will be used when creating mocks unless explicit parameters are provided via `BaseClass.WithConstructorParameters()`. + ## Using a factory for shared behavior Use `Mock.Factory` to create multiple mocks with a shared behavior: diff --git a/README.md b/README.md index 38611181..11e416d5 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,55 @@ var classMock = Mock.Create( - Tuples with recursively defaulted values - `null` for other reference types +### Advanced Mock Behavior + +#### Custom Default Value Factories + +Provide custom default values for specific types using `.WithDefaultValueFor()`: + +```csharp +var behavior = new MockBehavior() + .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). + +#### Initialize with Counter + +Initialize mocks with a counter to track creation order or assign unique identifiers: + +```csharp +var behavior = new MockBehavior() + .Initialize((count, mock) => + { + mock.Indexer(It.Is("Dark")).InitializeWith(count * 10); + }); + +var mock1 = Mock.Create(behavior); +var mock2 = Mock.Create(behavior); + +// mock1["Dark"] == 10 +// mock2["Dark"] == 20 +``` + +The counter starts at 1 and increments with each mock instance created. This is particularly useful when you need to create multiple mocks with slightly different configurations. + +#### Constructor Parameters Configuration + +Configure constructor parameters for specific types at the behavior level: + +```csharp +var behavior = new MockBehavior() + .UseConstructorParametersFor("Dark", 100); + +var sut = Mock.Create(behavior); +``` + +This allows you to define default constructor parameters in the behavior, which will be used when creating mocks unless explicit parameters are provided via `BaseClass.WithConstructorParameters()`. + ### Using a factory for shared behavior Use `Mock.Factory` to create multiple mocks with a shared behavior: From 53e5f655488539c58ddf0e478209a8e7f3523fa8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 09:16:56 +0000 Subject: [PATCH 3/4] Fix Initialize with Counter documentation syntax Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com> --- Docs/pages/01-create-mocks.md | 8 ++++---- README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Docs/pages/01-create-mocks.md b/Docs/pages/01-create-mocks.md index 8c35bc62..bb443f9a 100644 --- a/Docs/pages/01-create-mocks.md +++ b/Docs/pages/01-create-mocks.md @@ -80,16 +80,16 @@ Initialize mocks with a counter to track creation order or assign unique identif ```csharp var behavior = new MockBehavior() - .Initialize((count, mock) => + .Initialize((count, setup) => { - mock.Indexer(It.Is("Dark")).InitializeWith(count * 10); + setup.Property.TotalDispensed.InitializeWith(count * 10); }); var mock1 = Mock.Create(behavior); var mock2 = Mock.Create(behavior); -// mock1["Dark"] == 10 -// mock2["Dark"] == 20 +// mock1.TotalDispensed == 10 +// mock2.TotalDispensed == 20 ``` The counter starts at 1 and increments with each mock instance created. This is particularly useful when you need to create multiple mocks with slightly different configurations. diff --git a/README.md b/README.md index 11e416d5..eb0632d1 100644 --- a/README.md +++ b/README.md @@ -157,16 +157,16 @@ Initialize mocks with a counter to track creation order or assign unique identif ```csharp var behavior = new MockBehavior() - .Initialize((count, mock) => + .Initialize((count, setup) => { - mock.Indexer(It.Is("Dark")).InitializeWith(count * 10); + setup.Property.TotalDispensed.InitializeWith(count * 10); }); var mock1 = Mock.Create(behavior); var mock2 = Mock.Create(behavior); -// mock1["Dark"] == 10 -// mock2["Dark"] == 20 +// mock1.TotalDispensed == 10 +// mock2.TotalDispensed == 20 ``` The counter starts at 1 and increments with each mock instance created. This is particularly useful when you need to create multiple mocks with slightly different configurations. From d14f1e3fb63922ff98d902677b6f6da4a6344476 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 31 Jan 2026 09:21:26 +0000 Subject: [PATCH 4/4] Use MockBehavior.Default instead of new MockBehavior() Co-authored-by: vbreuss <3438234+vbreuss@users.noreply.github.com> --- Docs/pages/01-create-mocks.md | 6 +++--- README.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Docs/pages/01-create-mocks.md b/Docs/pages/01-create-mocks.md index bb443f9a..f8ac3bca 100644 --- a/Docs/pages/01-create-mocks.md +++ b/Docs/pages/01-create-mocks.md @@ -65,7 +65,7 @@ var classMock = Mock.Create( Provide custom default values for specific types using `.WithDefaultValueFor()`: ```csharp -var behavior = new MockBehavior() +var behavior = MockBehavior.Default .WithDefaultValueFor(() => "default") .WithDefaultValueFor(() => 42); @@ -79,7 +79,7 @@ This is useful when you want mocks to return specific default values for certain Initialize mocks with a counter to track creation order or assign unique identifiers: ```csharp -var behavior = new MockBehavior() +var behavior = MockBehavior.Default .Initialize((count, setup) => { setup.Property.TotalDispensed.InitializeWith(count * 10); @@ -99,7 +99,7 @@ The counter starts at 1 and increments with each mock instance created. This is Configure constructor parameters for specific types at the behavior level: ```csharp -var behavior = new MockBehavior() +var behavior = MockBehavior.Default .UseConstructorParametersFor("Dark", 100); var sut = Mock.Create(behavior); diff --git a/README.md b/README.md index eb0632d1..e2a19955 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ var classMock = Mock.Create( Provide custom default values for specific types using `.WithDefaultValueFor()`: ```csharp -var behavior = new MockBehavior() +var behavior = MockBehavior.Default .WithDefaultValueFor(() => "default") .WithDefaultValueFor(() => 42); @@ -156,7 +156,7 @@ This is useful when you want mocks to return specific default values for certain Initialize mocks with a counter to track creation order or assign unique identifiers: ```csharp -var behavior = new MockBehavior() +var behavior = MockBehavior.Default .Initialize((count, setup) => { setup.Property.TotalDispensed.InitializeWith(count * 10); @@ -176,7 +176,7 @@ The counter starts at 1 and increments with each mock instance created. This is Configure constructor parameters for specific types at the behavior level: ```csharp -var behavior = new MockBehavior() +var behavior = MockBehavior.Default .UseConstructorParametersFor("Dark", 100); var sut = Mock.Create(behavior);