From 08944171e2fc631dcd56c61215b361586cf8f294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sun, 10 May 2026 14:23:23 +0200 Subject: [PATCH 1/2] docs: re-theme scenarios examples to chocolate dispenser Switch the connection/Ping/Send walkthrough to an "empty" / "loaded" chocolate dispenser flow with Refill and Dispense, matching the chocolate theme used elsewhere in the docs. --- Docs/pages/advanced-features/06-scenarios.md | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Docs/pages/advanced-features/06-scenarios.md b/Docs/pages/advanced-features/06-scenarios.md index e596db1b..32fb8497 100644 --- a/Docs/pages/advanced-features/06-scenarios.md +++ b/Docs/pages/advanced-features/06-scenarios.md @@ -1,8 +1,8 @@ # Scenarios Scenarios let you define multiple sets of setups on a single mock and switch between them at runtime. This is useful -when the collaborator behaves differently depending on its internal state — for example a connection that starts -disconnected, becomes connected after `Connect()`, and times out after a failure. +when the collaborator behaves differently depending on its internal state — for example a chocolate dispenser +that starts empty, becomes loaded after `Refill(...)`, and runs out of stock after dispensing. A mock always has an *active scenario* (the empty string `""` by default). When a member is accessed, Mockolate looks for a matching setup in the active scenario first, then falls back to the default scope. @@ -13,17 +13,19 @@ Use `InScenario(name)` to scope setups to a named scenario. It returns a scope w `sut.Mock.Setup` but targets the scenario's bucket: ```csharp -sut.Mock.InScenario("disconnected").Setup.Ping().Throws(); -sut.Mock.InScenario("connected").Setup.Ping().Returns(true); +sut.Mock.InScenario("empty").Setup.Dispense(It.IsAny(), It.IsAny()) + .Throws(); +sut.Mock.InScenario("loaded").Setup.Dispense(It.IsAny(), It.IsAny()) + .Returns(true); ``` A callback overload batches multiple setups into the same scenario: ```csharp -sut.Mock.InScenario("connected", scope => +sut.Mock.InScenario("loaded", scope => { - scope.Setup.Ping().Returns(true); - scope.Setup.Send(It.IsAny()).Returns(true); + scope.Setup.Dispense(It.IsAny(), It.IsAny()).Returns(true); + scope.Setup.Refill(It.IsAny()).Returns(true); }); ``` @@ -36,18 +38,18 @@ the active scenario when the setup fires. The transition runs as a parallel side the return value or throw behaviour. ```csharp -sut.Mock.InScenario("disconnected") - .Setup.Connect() +sut.Mock.InScenario("empty") + .Setup.Refill(It.IsAny()) .Returns(true) - .TransitionTo("connected"); + .TransitionTo("loaded"); -sut.Mock.InScenario("connected") - .Setup.Ping() - .Throws() - .TransitionTo("disconnected"); +sut.Mock.InScenario("loaded") + .Setup.Dispense(It.IsAny(), It.IsAny()) + .Throws() + .TransitionTo("empty"); ``` -You can also change the active scenario manually via `sut.Mock.TransitionTo("connected");`, which is useful for +You can also change the active scenario manually via `sut.Mock.TransitionTo("loaded");`, which is useful for arranging the starting state. ### Resolution rules From f06126e100e75be8e1d8e4c5f5654e008bd080f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sun, 10 May 2026 15:05:10 +0200 Subject: [PATCH 2/2] docs: align loaded scenario transition with success path In the switching example, Dispense in the "loaded" scenario now returns true (matching the earlier setup snippet) while still transitioning to "empty", so the documented state and behavior stay consistent. --- Docs/pages/advanced-features/06-scenarios.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/pages/advanced-features/06-scenarios.md b/Docs/pages/advanced-features/06-scenarios.md index 32fb8497..a5613bb1 100644 --- a/Docs/pages/advanced-features/06-scenarios.md +++ b/Docs/pages/advanced-features/06-scenarios.md @@ -45,7 +45,7 @@ sut.Mock.InScenario("empty") sut.Mock.InScenario("loaded") .Setup.Dispense(It.IsAny(), It.IsAny()) - .Throws() + .Returns(true) .TransitionTo("empty"); ```