Compare commits
12
Commits
1415257890
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06a91a582e | ||
|
|
e8748ee697 | ||
|
|
3b7e880717 | ||
|
|
4c0f1dd541 | ||
|
|
c6c5829748 | ||
|
|
1736cd1abd | ||
|
|
5965ed8998 | ||
|
|
cfde583649 | ||
|
|
d8eaf03a68 | ||
|
|
d92c8a79d3 | ||
|
|
afa9dcd3d6 | ||
|
|
7c226d27d0 |
@@ -0,0 +1 @@
|
||||
website/
|
||||
@@ -0,0 +1,210 @@
|
||||
---
|
||||
name: learning-hour-design
|
||||
description: Design a 60-minute Samman-style Learning Hour. Use when creating, reviewing, or refining learning hours with the 4 C's (Connect, Concepts, Concrete Practice, Conclusions). Guides the user through learning goals, timing, and all four C's.
|
||||
---
|
||||
|
||||
# Learning Hour Design Skill
|
||||
|
||||
This skill helps Willem design learning hours following the Samman coaching format and the "4 C's" from *Training from the Back of the Room*.
|
||||
|
||||
## References
|
||||
|
||||
- Samman Learning Hour definition: https://sammancoaching.org/reference/learning_hour_definition.html
|
||||
- Samman 4C model page: https://sammancoaching.org/activities/4C_model.html
|
||||
- Samman Connect activities: https://sammancoaching.org/activities/connect.html
|
||||
- Samman Concept activities: https://sammancoaching.org/activities/concept.html
|
||||
- Samman Concrete Practice activities: https://sammancoaching.org/activities/concrete.html
|
||||
- Samman Conclusions activities: https://sammancoaching.org/activities/conclusions.html
|
||||
- Example learning hour (Testable Design – Naming): https://sammancoaching.org/learning_hours/testable_design/naming.html
|
||||
- All learning hours: https://sammancoaching.org/learning_hours/
|
||||
- 4 C's quick guide: https://bowperson.com/images/resources/quick-guide-to-four-c-map.pdf
|
||||
|
||||
## Process
|
||||
|
||||
Follow these steps in order. Be conversational — grill Willem with pointed questions, don't just lecture.
|
||||
|
||||
### Phase 1: Learning Goals
|
||||
|
||||
Start by helping Willem identify 1–3 clear learning goals. For each goal:
|
||||
|
||||
1. Ask: "What should participants be able to DO differently after this hour?"
|
||||
2. Push for observable, testable outcomes — not vague intentions.
|
||||
3. Challenge scope: "Can someone realistically achieve this in 60 minutes?"
|
||||
4. Help narrow broad topics into specific, actionable goals.
|
||||
|
||||
**Techniques for grilling:**
|
||||
- "How would you know someone learned this?"
|
||||
- "What's the smallest version of this that still matters?"
|
||||
- "If they could only walk away with one thing, what should it be?"
|
||||
|
||||
### Phase 2: Timetable
|
||||
|
||||
Between the learning goals and the 4 C's, design a timing plan. Analyze of 124 Samman learning hours shows these patterns.
|
||||
|
||||
#### Average times per block type (from the library)
|
||||
|
||||
| Block | Average | Range |
|
||||
|-------|---------|-------|
|
||||
| Connect | **6.6 min** | 2–15 min |
|
||||
| Concept | **9.2 min** | 2–25 min |
|
||||
| Concrete/Do | **25.3 min** | 5–45 min (per block) |
|
||||
| Conclusion/Reflect | **6.2 min** | 2–15 min |
|
||||
| Demo (optional) | **10.6 min** | 2–45 min |
|
||||
|
||||
#### Most common structure: 4 blocks (65% of hours)
|
||||
|
||||
| Block | Time | Description |
|
||||
|-------|------|-------------|
|
||||
| Connect | 5-10 min | Hook attention, connect to prior knowledge |
|
||||
| Concept | 10-15 min | Introduce key ideas |
|
||||
| Concrete Practice | 30-35 min | Single extended practice block |
|
||||
| Conclusion | 5-10 min | Wrap-up, key takeaways |
|
||||
|
||||
#### Two-practice-round structure (23% of hours)
|
||||
|
||||
| Block | Time | Description |
|
||||
|-------|------|-------------|
|
||||
| Connect | 5-10 min | Hook attention, connect to prior knowledge |
|
||||
| Concept | 5-10 min | Introduce key ideas before first practice |
|
||||
| Concrete Practice 1 | 15-20 min | First practice round |
|
||||
| Concept (deepening) | 5-10 min | Additional concepts after practice |
|
||||
| Concrete Practice 2 | 15-20 min | Second practice round |
|
||||
| Conclusion | 5-10 min | Wrap-up, key takeaways |
|
||||
|
||||
#### With a demo block (28% of hours)
|
||||
|
||||
| Block | Time | Description |
|
||||
|-------|------|-------------|
|
||||
| Connect | 5-10 min | Hook attention, connect to prior knowledge |
|
||||
| Concept | 5-10 min | Introduce key ideas |
|
||||
| Demo | 10-15 min | Demonstrate the technique |
|
||||
| Concrete Practice | 25-30 min | Participants practice |
|
||||
| Conclusion | 5-10 min | Wrap-up, key takeaways |
|
||||
|
||||
**Rules for the timetable:**
|
||||
- Total is usually 50-55 min of explicit blocks, leaving 5-10 min buffer for transitions.
|
||||
- **Single 35-min practice is more common** than two 15-min rounds — ask Willem which fits.
|
||||
- Connect is almost always first (99%). Conclusion is always last (99%).
|
||||
- Concept can come after practice (21% of hours) — used for deepening or explaining what they just experienced.
|
||||
- Demo is a distinct block from concept when present.
|
||||
- If Willem has more concepts than fit, help cut scope — 60 minutes is tight.
|
||||
|
||||
Present the timetable and ask Willem if it feels right before moving on.
|
||||
|
||||
### Phase 3: The 4 C's
|
||||
|
||||
Work through each C. For each one, ask questions and co-create content.
|
||||
|
||||
#### C1: Connect
|
||||
|
||||
"Connect it to what they already know." Connect activities get learners into a state of mind ready to learn — connecting to what they know, what they'll learn, what they want to learn, and to each other.
|
||||
|
||||
- What prior experience or knowledge can you hook into?
|
||||
- What analogy, story, or provocative question grabs attention?
|
||||
- How does this relate to the participants' real work?
|
||||
- Reference the Samman Connect page for activity ideas: https://sammancoaching.org/activities/connect.html
|
||||
|
||||
#### C2: Concepts
|
||||
|
||||
What are the key ideas, frameworks, or principles?
|
||||
|
||||
- List 2–4 concepts maximum. More than that won't fit in ~9 min average.
|
||||
- For each concept: what's the simplest way to explain it?
|
||||
- What visual, diagram, or example makes it click?
|
||||
- Consider: do some concepts go before practice and some after? (21% of hours interleave concept after practice)
|
||||
- Reference the Samman Concept page for activity ideas: https://sammancoaching.org/activities/concept.html
|
||||
|
||||
#### C3: Concrete Practice
|
||||
|
||||
This is where participants actively apply the new concept. Usually a coding exercise, but can be other active tasks (sorting, evaluating, puzzles).
|
||||
|
||||
- Willem often has a practice idea that's too big. **Actively help descope:**
|
||||
- "What's the minimum viable version of this exercise?"
|
||||
- "What can you cut and still hit the learning goal?"
|
||||
- "Can this be done in pairs in 15-35 minutes?"
|
||||
- "What tools do they need? Keep it simple — a screenshot on paper works, don't need editors."
|
||||
- Structure each practice round:
|
||||
- Clear instructions (what to do, with whom, for how long)
|
||||
- A specific task or prompt
|
||||
- A share-back or debrief question
|
||||
- List of tools/materials needed
|
||||
- Ensure the practice directly tests the learning goal.
|
||||
- Reference the Samman Concrete Practice page for activity ideas: https://sammancoaching.org/activities/concrete.html
|
||||
|
||||
#### C4: Conclusions
|
||||
|
||||
How do participants consolidate what they learned? Conclusions help learners summarize, evaluate, celebrate, and create action plans.
|
||||
|
||||
- What's the one-sentence takeaway?
|
||||
- How do participants share back from practice?
|
||||
- What commitment or next step do they leave with?
|
||||
- Reference the Samman Conclusions page for activity ideas: https://sammancoaching.org/activities/conclusions.html
|
||||
|
||||
### Phase 4: Review and Output
|
||||
|
||||
Once all phases are done:
|
||||
|
||||
1. Present the complete learning hour as a Markdown file matching the Samman format.
|
||||
2. Verify: does every C map back to a learning goal?
|
||||
3. Check the math: does the timetable add to ~55 min (leaving buffer)?
|
||||
4. Flag any gaps or scope creep.
|
||||
|
||||
## Output Format
|
||||
|
||||
When producing the final learning hour, use this Markdown structure matching the Samman convention:
|
||||
|
||||
```markdown
|
||||
---
|
||||
theme: [topic]
|
||||
title: [Learning Hour Title]
|
||||
name: [slug-name]
|
||||
kata: [kata-name if applicable]
|
||||
difficulty: [1-5]
|
||||
author: [author]
|
||||
affiliation: [affiliation]
|
||||
tags: [tag1 tag2]
|
||||
---
|
||||
|
||||
# [Learning Hour Title]
|
||||
|
||||
[Opening paragraph: why this matters, what problem it solves]
|
||||
|
||||
## Learning Goals
|
||||
|
||||
* [Goal 1 – observable outcome]
|
||||
* [Goal 2 – if applicable]
|
||||
|
||||
## Session Outline
|
||||
|
||||
* [X] min connect: [brief description]
|
||||
* [X] min concept: [brief description]
|
||||
* [X] min concrete: [brief description]
|
||||
* [X] min conclusion: [brief description]
|
||||
|
||||
## Connect - [Connect Activity Name]
|
||||
|
||||
[Content, instructions, examples]
|
||||
|
||||
## Concept - [Concept Name]
|
||||
|
||||
[Content, explanations, examples]
|
||||
|
||||
## Concrete Practice - [Practice Name]
|
||||
|
||||
[Instructions, task, tools, debrief]
|
||||
|
||||
## Conclusions - [Conclusion Activity Name]
|
||||
|
||||
[Wrap-up, takeaways, next steps]
|
||||
```
|
||||
|
||||
## Tips
|
||||
|
||||
- Always push back on scope creep — 60 minutes is tight; explicit blocks usually total 50-55 min.
|
||||
- If Willem has multiple learning goals, suggest splitting into separate hours.
|
||||
- Pair practice is the default format; suggest alternatives only if justified.
|
||||
- A single 35-min practice block is the most common pattern — two rounds is less common but valid.
|
||||
- Demo is a distinct block from concept; suggest it when the technique benefits from seeing it first.
|
||||
- When in doubt, reference the Samman example: https://sammancoaching.org/learning_hours/testable_design/naming.html
|
||||
- Browse the full library for inspiration: https://sammancoaching.org/learning_hours/
|
||||
- Check `website/_learning_hours/` in this repo for local copies of all learning hours.
|
||||
@@ -1,9 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 learning-hours
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,3 +0,0 @@
|
||||
# learning-hour-maker
|
||||
|
||||
a coding agent skill to make learning hours, and learning hours in development
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#+title: Learning Hour Maker
|
||||
|
||||
This is a project to help me (Willem) create Learning Hours.
|
||||
|
||||
A learning hour is a short training session (~60 minutes) for software developers,
|
||||
led by a technical coach. It follows the [[https://sammancoaching.org/activities/4C_model.html][4 C's]] model from
|
||||
Sharon Bowman's "Training from the BACK of the Room".
|
||||
|
||||
See the [[https://sammancoaching.org/reference/learning_hour_definition.html][Samman Learning Hour definition]] for the official description.
|
||||
|
||||
* 4 C's
|
||||
|
||||
The 4 C's from [[https://bowperson.com/][Sharon Bowman]]'s "Training from the BACK of the Room":
|
||||
see the [[https://bowperson.com/images/resources/quick-guide-to-four-c-map.pdf][quick guide to the 4 C map]].
|
||||
|
||||
Samman has dedicated pages for each:
|
||||
|
||||
- [[https://sammancoaching.org/activities/connect.html][Connect]] — get learners warmed up and thinking about the topic
|
||||
- [[https://sammancoaching.org/activities/concept.html][Concept]] — explain new ideas with words, pictures, examples, stories
|
||||
- [[https://sammancoaching.org/activities/concrete.html][Concrete Practice]] — hands-on exercise where learners actively apply the new skill
|
||||
- [[https://sammancoaching.org/activities/conclusions.html][Conclusions]] — summarize, evaluate, celebrate, and plan next steps
|
||||
|
||||
* Samman Resources
|
||||
|
||||
- [[https://sammancoaching.org/learning_hours/][All Learning Hours]] — browse the full library
|
||||
- [[https://sammancoaching.org/learning_hours/testable_design/naming.html][Example: Reading by Renaming]] — a complete learning hour on testable design naming
|
||||
- [[https://sammancoaching.org/activities/][Activities]] — activity catalog by category
|
||||
- [[https://sammancoaching.org/kata_descriptions/][Katas]] — code kata descriptions used in learning hours
|
||||
|
||||
* Typical Timetable
|
||||
|
||||
Analysis of 124 Samman learning hours shows these average times:
|
||||
|
||||
| Block | Average | Range |
|
||||
|-------+---------+-------|
|
||||
| Connect | 6.6 min | 2–15 min |
|
||||
| Concept | 9.2 min | 2–25 min |
|
||||
| Concrete/Do | 25.3 min | 5–45 min |
|
||||
| Conclusion/Reflect | 6.2 min | 2–15 min |
|
||||
| Demo (optional) | 10.6 min | 2–45 min |
|
||||
|
||||
Most common structure (65%): 4 blocks — Connect, Concept, Concrete Practice, Conclusion.
|
||||
Two-practice-round structure (23%): Connect, Concept, Practice 1, Concept, Practice 2, Conclusion.
|
||||
With demo (28%): Connect, Concept, Demo, Practice, Conclusion.
|
||||
|
||||
Total explicit time is usually 50-55 min, leaving buffer for transitions.
|
||||
|
||||
* How to Use This Project
|
||||
|
||||
Use the ~learning-hour-design~ skill to walk through creating a learning hour:
|
||||
|
||||
- The agent will grill you on learning goals (finding 1-3 clear, testable outcomes)
|
||||
- Help design a timetable to pace the 60 minutes
|
||||
- Work through each of the 4 C's with pointed questions
|
||||
- Help descope concrete practice ideas that are too big
|
||||
- Produce a complete org-mode outline
|
||||
@@ -0,0 +1,20 @@
|
||||
## NuGet
|
||||
*.nupkg
|
||||
**/packages/
|
||||
|
||||
## Build
|
||||
bin/
|
||||
obj/
|
||||
|
||||
## IDE
|
||||
*.user
|
||||
*.suo
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
.idea/
|
||||
*.slnx
|
||||
*.slnx launches
|
||||
|
||||
## NuGet local config (workaround for locked ~/.nuget)
|
||||
nuget.config
|
||||
*.log
|
||||
@@ -0,0 +1,45 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrderDomain", "src/OrderDomain/OrderDomain.csproj", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrderTests", "tests/OrderTests/OrderTests.csproj", "{B2C3D4E5-F6A7-8901-BCDE-F12345678901}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrderBookDomain", "src/OrderBookDomain/OrderBookDomain.csproj", "{C3D4E5F6-A7B8-9012-CDEF-123456789012}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrderBookTests", "tests/OrderBookTests/OrderBookTests.csproj", "{D4E5F6A7-B8C9-0123-DEFA-234567890123}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Integration", "Integration", "{83A6B86A-4CD0-44BE-9FE0-408AC31E69F8}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Warmup", "Warmup", "{55470487-3CE4-4FD7-BADF-35F7D1473CA5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{C3D4E5F6-A7B8-9012-CDEF-123456789012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3D4E5F6-A7B8-9012-CDEF-123456789012}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C3D4E5F6-A7B8-9012-CDEF-123456789012}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{D4E5F6A7-B8C9-0123-DEFA-234567890123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D4E5F6A7-B8C9-0123-DEFA-234567890123}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D4E5F6A7-B8C9-0123-DEFA-234567890123}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{C3D4E5F6-A7B8-9012-CDEF-123456789012} = {83A6B86A-4CD0-44BE-9FE0-408AC31E69F8}
|
||||
{D4E5F6A7-B8C9-0123-DEFA-234567890123} = {83A6B86A-4CD0-44BE-9FE0-408AC31E69F8}
|
||||
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890} = {55470487-3CE4-4FD7-BADF-35F7D1473CA5}
|
||||
{B2C3D4E5-F6A7-8901-BCDE-F12345678901} = {55470487-3CE4-4FD7-BADF-35F7D1473CA5}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "10.0.400",
|
||||
"rollForward": "latestFeature"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
---
|
||||
theme: agentic_engineering
|
||||
title: Show, Don't Tell — Using Examples with Coding Agents
|
||||
name: show_dont_tell
|
||||
difficulty: 2
|
||||
author: willem
|
||||
affiliation:
|
||||
tags: agentic copilot refactoring tests examples
|
||||
---
|
||||
|
||||
# Show, Don't Tell — Using Examples with Coding Agents
|
||||
|
||||
You've described what you want to a coding agent, and it didn't get it right. Or it took so many rounds of corrections that you'd have just done it yourself. This learning hour explores a simpler approach: instead of telling the agent what style you want, show it.
|
||||
|
||||
## Learning Goals
|
||||
|
||||
* Use a concrete code example (show, don't tell) to guide a coding agent in propagating a refactoring pattern across a test suite.
|
||||
* Produce your own example before delegating: refactor a multi-step test into focused tests yourself, then show the result to the agent as the pattern.
|
||||
|
||||
## Session Outline
|
||||
|
||||
* 5 min connect: Frustrating agent conversations
|
||||
* 5 min concept: LLMs are pattern matchers
|
||||
* 20 min concrete practice: Round 1 — refactor tests using a custom matcher example
|
||||
* 15 min concrete practice: Round 2 — split multi-step tests using an example you create
|
||||
* 5 min conclusion: Share back and recognize the pattern in your own code
|
||||
|
||||
## Connect — Frustrating Agent Conversations
|
||||
|
||||
Pair up and share a time when you had to iterate multiple times with a coding agent just to get it to match the style you wanted. What did you try? How many rounds did it take?
|
||||
|
||||
This is a [Pair Share]({% link _activities/connect/pair_share.md %}) connect.
|
||||
|
||||
## Concept — LLMs Are Pattern Matchers
|
||||
|
||||
LLMs are pattern matchers and translation machines. They are better at recognizing a pattern in concrete code than interpreting abstract instructions.
|
||||
|
||||
### The "Tell" Approach (doesn't work well)
|
||||
|
||||
> Refactor these tests to encapsulate the total price check. Instead of asserting on `order.Total`, create a method `IsFullyPaid()` and test for that.
|
||||
|
||||
The agent might:
|
||||
- Create the method but not use it consistently
|
||||
- Misinterpret "encapsulate" and change production code instead of test code
|
||||
- Apply the pattern incorrectly or only partially
|
||||
|
||||
### The "Show" Approach (works better)
|
||||
|
||||
Refactor one test yourself — encapsulate the attribute check behind a behavior method:
|
||||
|
||||
```csharp
|
||||
// Before — checking an attribute
|
||||
[Test]
|
||||
public void CompletedOrder_TotalIsCorrect()
|
||||
{
|
||||
var order = new Order();
|
||||
order.AddLine(100m, 1);
|
||||
order.Complete();
|
||||
|
||||
Assert.That(order.Total, Is.EqualTo(100m));
|
||||
}
|
||||
|
||||
// After — encapsulating behavior
|
||||
[Test]
|
||||
public void CompletedOrder_TotalIsCorrect()
|
||||
{
|
||||
var order = new Order();
|
||||
order.AddLine(100m, 1);
|
||||
order.Complete();
|
||||
|
||||
Assert.That(order.IsFullyPaid(100m), Is.True);
|
||||
}
|
||||
```
|
||||
|
||||
Then ask the agent:
|
||||
|
||||
> The first test was refactored to use `order.IsFullyPaid(expected)` instead of asserting on `order.Total`. Apply the same pattern to the remaining tests.
|
||||
|
||||
The agent sees the concrete pattern and replicates it. No description needed.
|
||||
|
||||
### Key Insight
|
||||
|
||||
**Examples beat descriptions.** One concrete example is worth a paragraph of instructions. This works for any refactoring pattern — splitting tests, introducing custom matchers, extracting methods, renaming for clarity. Show the agent what "done" looks like.
|
||||
|
||||
## Concrete Practice — Round 1 — Refactor Tests with a Custom Matcher (20 min)
|
||||
|
||||
### Setup
|
||||
|
||||
Open the project in `exercises/show-dont-tell/` in Rider with GitHub Copilot Agent mode.
|
||||
|
||||
The project contains an `Order` domain and a test file `OrderTotalTests.cs` with 6 tests.
|
||||
|
||||
### Step 1 — Identify the Smell (5 min)
|
||||
|
||||
Open `OrderTotalTests.cs`. Look at the tests. What's the pattern you see?
|
||||
|
||||
- The first test (`DiscountOnFirstLine_TotalAndLineValues`) was already refactored — notice how it uses `Has.OrderState()` with a single assertion.
|
||||
- The remaining 5 tests each have multiple `Assert.That()` calls checking `order.Total`, `order.Lines[0].Value`, `order.Lines[1].Value`, etc.
|
||||
|
||||
These multiple asserts are checking attributes (state) rather than expressing intention. They're also hard to read and fragile — if the order structure changes, every test needs updating.
|
||||
|
||||
### Step 2 — Examine the Example (5 min)
|
||||
|
||||
Look at the first test and the custom matcher file `OrderStateConstraint.cs`. You don't need to understand how the matcher is implemented — just recognize the pattern:
|
||||
|
||||
```csharp
|
||||
// One assertion that bundles all checks
|
||||
Assert.That(order, Has.OrderState(
|
||||
expectedTotal: 210m,
|
||||
expectedLineValues: new[] { 160m, 50m }));
|
||||
```
|
||||
|
||||
vs.
|
||||
|
||||
```csharp
|
||||
// Three separate assertions
|
||||
Assert.That(order.Total, Is.EqualTo(240m));
|
||||
Assert.That(order.Lines[0].Value, Is.EqualTo(200m));
|
||||
Assert.That(order.Lines[1].Value, Is.EqualTo(40m));
|
||||
```
|
||||
|
||||
### Step 3 — Use the Agent (20-25 min)
|
||||
|
||||
Use GitHub Copilot Agent mode to refactor the remaining 5 tests. Prompt:
|
||||
|
||||
> The first test uses a custom matcher `Has.OrderState()`. Refactor the remaining tests to use the same pattern — one assertion with `Has.OrderState()` instead of multiple individual asserts.
|
||||
|
||||
Run the tests after the agent makes changes to verify nothing broke.
|
||||
|
||||
**If the agent doesn't get it right on the first try:**
|
||||
- Check that the example test is visible in the same file
|
||||
- Be more specific: "Look at `DiscountOnFirstLine_TotalAndLineValues` as the example"
|
||||
- Point out what went wrong and ask it to retry
|
||||
|
||||
### Tools Needed
|
||||
|
||||
- Rider with GitHub Copilot Agent mode
|
||||
- The `exercises/show-dont-tell/` project (included in this repo)
|
||||
- .NET 10 SDK
|
||||
|
||||
## Concrete Practice — Round 2 — Split Multi-Step Tests (15 min)
|
||||
|
||||
This round has a twist: **no refactored example is provided.** Creating the example is the exercise.
|
||||
|
||||
### Setup
|
||||
|
||||
In the same solution, open the `OrderBookTests` project. The domain is an `OrderBook` with a small state machine:
|
||||
|
||||
* `OpenOrder(customer)` creates a `Pending` order
|
||||
* `FinalizeOrder(id, at)` → `WaitingForPayment` (the timestamp is passed in — no global clock)
|
||||
* `PayOrder(id, paidAt)` → `Fulfilling`, unless payment arrives more than 14 days after finalization: the order is `Cancelled` and the payment is rejected
|
||||
* `ShipOrder(id)` → `Delivered`
|
||||
* `CancelOrder(id)` works from `Pending` and `WaitingForPayment` only; invalid transitions throw
|
||||
|
||||
`OrderBookLifecycleTests.cs` contains 7 integration tests in an anti-pattern style: **given/when/then/when/then**. Each test walks through several transitions with assertions in between, e.g. `PayThenShip_DeliversTheOrder` finalizes, asserts, pays, ships, and asserts again. The tests pass — they're just testing three behaviors each under a name that describes one.
|
||||
|
||||
### Step 1 — Identify the Smell (3 min)
|
||||
|
||||
Look at the tests. What makes them hard to work with?
|
||||
|
||||
* Multiple act/assert pairs: when one assertion fails, you don't know which transition misbehaved
|
||||
* Test names describe one behavior while the test body verifies three
|
||||
* Setup for a later transition is entangled with assertions for an earlier one
|
||||
|
||||
### Step 2 — Create the Example Yourself (7 min)
|
||||
|
||||
Pick **one** multi-step test and refactor it by hand into focused tests: one transition per test, each test setting up only the state it needs. Keep the exception paths (`Assert.Throws`) in their own tests. Run the tests — the split versions must cover the same behavior as the original.
|
||||
|
||||
You cannot show the agent what "done" looks like until you have built it. Notice what decisions you had to make: how to name the split tests, what setup helper to extract, where a transition deserves its own test.
|
||||
|
||||
### Step 3 — Use Your Example with the Agent (5 min)
|
||||
|
||||
Now show your refactored test to the agent and ask it to apply the same pattern to the remaining tests. Verify with the test run afterward.
|
||||
|
||||
**If the agent doesn't get it right:**
|
||||
|
||||
* Check whether your example is unambiguous — could it be read another way?
|
||||
* Compare with round 1: what did the provided example communicate that yours doesn't?
|
||||
|
||||
### Why No Example Was Provided
|
||||
|
||||
Round 1 showed that examples guide agents better than descriptions. Round 2 practices the harder half of that skill: producing the example. In real work, the pattern you want to propagate usually doesn't exist yet — someone has to write it first, and that someone is you.
|
||||
|
||||
## Conclusions — Share Back
|
||||
|
||||
Go around and ask:
|
||||
|
||||
1. **Did the agent get it right on the first try? What happened if it didn't?**
|
||||
2. **What made the example work — what would have made it fail?**
|
||||
3. **Do you recognize this pattern in your own tests?** Where could you use "show, don't tell" in your real work?
|
||||
4. **What was different in round 2, when you had to create the example yourself?** What made that harder — and what did you learn about writing a good example?
|
||||
|
||||
This is an [Explain the Main Idea]({% link _activities/conclusions/explain_main_idea.md %}) conclusion.
|
||||
|
||||
### One-Sentence Takeaway
|
||||
|
||||
When working with coding agents, show them what you want with a concrete example instead of describing it in words — LLMs are pattern matchers, and examples are patterns.
|
||||
@@ -0,0 +1,2 @@
|
||||
[tools]
|
||||
dotnet = "10"
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace OrderBookDomain;
|
||||
|
||||
public enum OrderStatus
|
||||
{
|
||||
Pending,
|
||||
WaitingForPayment,
|
||||
Fulfilling,
|
||||
Delivered,
|
||||
Cancelled
|
||||
}
|
||||
|
||||
public class Order
|
||||
{
|
||||
public int Id { get; }
|
||||
public string Customer { get; }
|
||||
public OrderStatus Status { get; internal set; }
|
||||
public DateTimeOffset? FinalizedAt { get; internal set; }
|
||||
|
||||
internal Order(int id, string customer)
|
||||
{
|
||||
Id = id;
|
||||
Customer = customer;
|
||||
Status = OrderStatus.Pending;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
namespace OrderBookDomain;
|
||||
|
||||
public class OrderBook
|
||||
{
|
||||
private readonly TimeSpan _paymentWindow;
|
||||
private readonly Dictionary<int, Order> _ordersById = new();
|
||||
private int _nextId = 1;
|
||||
|
||||
public OrderBook(TimeSpan? paymentWindow = null)
|
||||
=> _paymentWindow = paymentWindow ?? TimeSpan.FromDays(14);
|
||||
|
||||
public IReadOnlyList<Order> Orders => _ordersById.Values.ToList();
|
||||
|
||||
public Order OpenOrder(string customer)
|
||||
{
|
||||
var order = new Order(_nextId++, customer);
|
||||
_ordersById[order.Id] = order;
|
||||
return order;
|
||||
}
|
||||
|
||||
public Order GetOrder(int orderId)
|
||||
=> _ordersById.TryGetValue(orderId, out var order)
|
||||
? order
|
||||
: throw new InvalidOperationException($"Unknown order id {orderId}.");
|
||||
|
||||
public void FinalizeOrder(int orderId, DateTimeOffset finalizedAt)
|
||||
{
|
||||
var order = GetOrder(orderId);
|
||||
RequireStatus(order, OrderStatus.Pending, "finalize");
|
||||
order.Status = OrderStatus.WaitingForPayment;
|
||||
order.FinalizedAt = finalizedAt;
|
||||
}
|
||||
|
||||
public void PayOrder(int orderId, DateTimeOffset paidAt)
|
||||
{
|
||||
var order = GetOrder(orderId);
|
||||
RequireStatus(order, OrderStatus.WaitingForPayment, "pay");
|
||||
if (paidAt - order.FinalizedAt > _paymentWindow)
|
||||
{
|
||||
order.Status = OrderStatus.Cancelled;
|
||||
throw new InvalidOperationException(
|
||||
$"Payment for order {orderId} arrived after the payment window; the order was cancelled.");
|
||||
}
|
||||
order.Status = OrderStatus.Fulfilling;
|
||||
}
|
||||
|
||||
public void ShipOrder(int orderId)
|
||||
{
|
||||
var order = GetOrder(orderId);
|
||||
RequireStatus(order, OrderStatus.Fulfilling, "ship");
|
||||
order.Status = OrderStatus.Delivered;
|
||||
}
|
||||
|
||||
public void CancelOrder(int orderId)
|
||||
{
|
||||
var order = GetOrder(orderId);
|
||||
if (order.Status is not (OrderStatus.Pending or OrderStatus.WaitingForPayment))
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot cancel order {orderId} in status {order.Status}.");
|
||||
order.Status = OrderStatus.Cancelled;
|
||||
}
|
||||
|
||||
private static void RequireStatus(Order order, OrderStatus expected, string action)
|
||||
{
|
||||
if (order.Status != expected)
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot {action} order {order.Id} in status {order.Status} (expected {expected}).");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace OrderDomain;
|
||||
|
||||
public class Order
|
||||
{
|
||||
public List<OrderLine> Lines { get; } = new();
|
||||
|
||||
public decimal Total => Lines.Sum(l => l.Value);
|
||||
|
||||
public void AddLine(decimal unitPrice, int quantity)
|
||||
=> Lines.Add(new OrderLine(unitPrice, quantity));
|
||||
|
||||
public void ApplyDiscount(int lineIndex)
|
||||
=> Lines[lineIndex].ApplyDiscount();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace OrderDomain;
|
||||
|
||||
public class OrderLine
|
||||
{
|
||||
public decimal UnitPrice { get; }
|
||||
public int Quantity { get; }
|
||||
public bool HasDiscount { get; private set; }
|
||||
|
||||
public decimal Value =>
|
||||
HasDiscount ? UnitPrice * Quantity * 0.8m : UnitPrice * Quantity;
|
||||
|
||||
public OrderLine(decimal unitPrice, int quantity)
|
||||
{
|
||||
UnitPrice = unitPrice;
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public void ApplyDiscount() => HasDiscount = true;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using NUnit.Framework;
|
||||
using OrderBookDomain;
|
||||
|
||||
namespace OrderBookTests;
|
||||
|
||||
public class OrderBookLifecycleTests
|
||||
{
|
||||
private static readonly DateTimeOffset Day0 = new(2025, 6, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
|
||||
private static DateTimeOffset At(int day) => Day0.AddDays(day);
|
||||
|
||||
[Test]
|
||||
public void FinalizeThenPay_MovesOrderThroughTwoStates()
|
||||
{
|
||||
var book = new OrderBook();
|
||||
var order = book.OpenOrder("anna");
|
||||
|
||||
book.FinalizeOrder(order.Id, At(1));
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.WaitingForPayment));
|
||||
|
||||
book.PayOrder(order.Id, At(2));
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.Fulfilling));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PayThenShip_DeliversTheOrder()
|
||||
{
|
||||
var book = new OrderBook();
|
||||
var order = book.OpenOrder("anna");
|
||||
|
||||
book.FinalizeOrder(order.Id, At(1));
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.WaitingForPayment));
|
||||
|
||||
book.PayOrder(order.Id, At(2));
|
||||
book.ShipOrder(order.Id);
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.Delivered));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PayWithinWindow_ThenLatePayOnSecondOrder_CancelsOnlyThatOrder()
|
||||
{
|
||||
var book = new OrderBook();
|
||||
var first = book.OpenOrder("anna");
|
||||
var second = book.OpenOrder("bram");
|
||||
|
||||
book.FinalizeOrder(first.Id, At(1));
|
||||
book.FinalizeOrder(second.Id, At(1));
|
||||
Assert.That(book.Orders, Has.Count.EqualTo(2));
|
||||
|
||||
book.PayOrder(first.Id, At(5));
|
||||
Assert.That(book.GetOrder(first.Id).Status, Is.EqualTo(OrderStatus.Fulfilling));
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => book.PayOrder(second.Id, At(30)));
|
||||
Assert.That(book.GetOrder(second.Id).Status, Is.EqualTo(OrderStatus.Cancelled));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PayBeforeFinalize_Throws_ThenFinalizeStillWorks()
|
||||
{
|
||||
var book = new OrderBook();
|
||||
var order = book.OpenOrder("anna");
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => book.PayOrder(order.Id, At(1)));
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.Pending));
|
||||
|
||||
book.FinalizeOrder(order.Id, At(2));
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.WaitingForPayment));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CancelPendingOrder_ThenPayAfterCancel_ThrowsAgain()
|
||||
{
|
||||
var book = new OrderBook();
|
||||
var order = book.OpenOrder("anna");
|
||||
|
||||
book.CancelOrder(order.Id);
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.Cancelled));
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => book.PayOrder(order.Id, At(1)));
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.Cancelled));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShippedOrder_CannotBeCancelled()
|
||||
{
|
||||
var book = new OrderBook();
|
||||
var order = book.OpenOrder("anna");
|
||||
|
||||
book.FinalizeOrder(order.Id, At(1));
|
||||
book.PayOrder(order.Id, At(2));
|
||||
book.ShipOrder(order.Id);
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.Delivered));
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => book.CancelOrder(order.Id));
|
||||
Assert.That(book.GetOrder(order.Id).Status, Is.EqualTo(OrderStatus.Delivered));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TwoCustomers_InterleaveTransitions_Independently()
|
||||
{
|
||||
var book = new OrderBook();
|
||||
var annas = book.OpenOrder("anna");
|
||||
var brams = book.OpenOrder("bram");
|
||||
|
||||
book.FinalizeOrder(brams.Id, At(1));
|
||||
Assert.That(book.GetOrder(annas.Id).Status, Is.EqualTo(OrderStatus.Pending));
|
||||
Assert.That(book.GetOrder(brams.Id).Status, Is.EqualTo(OrderStatus.WaitingForPayment));
|
||||
|
||||
book.PayOrder(brams.Id, At(2));
|
||||
book.CancelOrder(annas.Id);
|
||||
Assert.That(book.GetOrder(annas.Id).Status, Is.EqualTo(OrderStatus.Cancelled));
|
||||
Assert.That(book.GetOrder(brams.Id).Status, Is.EqualTo(OrderStatus.Fulfilling));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="NUnit" Version="4.6.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="6.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OrderBookDomain\OrderBookDomain.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,74 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework.Constraints;
|
||||
using OrderDomain;
|
||||
|
||||
namespace OrderTests;
|
||||
|
||||
/// <summary>
|
||||
/// Custom NUnit matcher that bundles multiple order assertions into one.
|
||||
/// Participants: you do not need to understand how this works —
|
||||
/// just recognize the pattern and use it as an example for the agent.
|
||||
/// </summary>
|
||||
public static class Has
|
||||
{
|
||||
public static IResolveConstraint OrderState(decimal expectedTotal, decimal[] expectedLineValues)
|
||||
=> new OrderStateConstraint(expectedTotal, expectedLineValues);
|
||||
}
|
||||
|
||||
public class OrderStateConstraint : Constraint
|
||||
{
|
||||
private readonly decimal _expectedTotal;
|
||||
private readonly decimal[] _expectedLineValues;
|
||||
|
||||
public OrderStateConstraint(decimal expectedTotal, decimal[] expectedLineValues)
|
||||
{
|
||||
_expectedTotal = expectedTotal;
|
||||
_expectedLineValues = expectedLineValues;
|
||||
}
|
||||
|
||||
public override string Description =>
|
||||
$"order with total {_expectedTotal} and line values [{string.Join(", ", _expectedLineValues)}]";
|
||||
|
||||
public override ConstraintResult ApplyTo<TActual>(TActual actual)
|
||||
{
|
||||
var order = (Order)(object)actual!;
|
||||
var actualTotal = order.Total;
|
||||
var actualLineValues = order.Lines.Select(l => l.Value).ToArray();
|
||||
|
||||
var details = new List<string>();
|
||||
if (actualTotal != _expectedTotal)
|
||||
details.Add($"Total: expected {_expectedTotal}, but was {actualTotal}");
|
||||
if (!actualLineValues.SequenceEqual(_expectedLineValues))
|
||||
details.Add(
|
||||
$"Line values: expected [{string.Join(", ", _expectedLineValues)}], " +
|
||||
$"but was [{string.Join(", ", actualLineValues)}]");
|
||||
|
||||
return new OrderStateResult(this, actual!, details.Count == 0, details);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A ConstraintResult that carries the per-field mismatch details and
|
||||
/// writes them as additional lines in the failure message, e.g.
|
||||
///
|
||||
/// Expected: order with total 210 and line values [160, 50]
|
||||
/// But was: <Order>
|
||||
/// Total: expected 210, but was 250
|
||||
/// Line values: expected [160, 50], but was [200, 50]
|
||||
/// </summary>
|
||||
private sealed class OrderStateResult : ConstraintResult
|
||||
{
|
||||
private readonly IReadOnlyList<string> _details;
|
||||
|
||||
public OrderStateResult(Constraint constraint, object? actual, bool isSuccess, IReadOnlyList<string> details)
|
||||
: base(constraint, actual, isSuccess)
|
||||
{
|
||||
_details = details;
|
||||
}
|
||||
|
||||
public override void WriteAdditionalLinesTo(MessageWriter writer)
|
||||
{
|
||||
foreach (var detail in _details)
|
||||
writer.WriteMessageLine(detail);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="NUnit" Version="4.6.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="6.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OrderDomain\OrderDomain.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,92 @@
|
||||
using NUnit.Framework;
|
||||
using OrderDomain;
|
||||
|
||||
namespace OrderTests;
|
||||
|
||||
public class OrderTotalTests
|
||||
{
|
||||
// This test was refactored — notice the custom matcher.
|
||||
// The other tests still need the same treatment.
|
||||
[Test]
|
||||
public void DiscountOnFirstLine_TotalAndLineValues()
|
||||
{
|
||||
var order = new Order();
|
||||
order.AddLine(100m, 2); // line 0: 200 → 160 with discount
|
||||
order.AddLine(50m, 1); // line 1: 50
|
||||
|
||||
order.ApplyDiscount(0);
|
||||
|
||||
Assert.That(order, Has.OrderState(
|
||||
expectedTotal: 210m,
|
||||
expectedLineValues: [160m, 50m]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DiscountOnSecondLine_TotalAndLineValues()
|
||||
{
|
||||
var order = new Order();
|
||||
order.AddLine(100m, 2); // line 0: 200
|
||||
order.AddLine(50m, 1); // line 1: 50 → 40 with discount
|
||||
|
||||
order.ApplyDiscount(1);
|
||||
|
||||
Assert.That(order.Total, Is.EqualTo(240m));
|
||||
Assert.That(order.Lines[0].Value, Is.EqualTo(200m));
|
||||
Assert.That(order.Lines[1].Value, Is.EqualTo(40m));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DiscountOnBothLines_TotalAndLineValues()
|
||||
{
|
||||
var order = new Order();
|
||||
order.AddLine(100m, 2); // line 0: 200 → 160
|
||||
order.AddLine(50m, 1); // line 1: 50 → 40
|
||||
|
||||
order.ApplyDiscount(0);
|
||||
order.ApplyDiscount(1);
|
||||
|
||||
Assert.That(order.Total, Is.EqualTo(200m));
|
||||
Assert.That(order.Lines[0].Value, Is.EqualTo(160m));
|
||||
Assert.That(order.Lines[1].Value, Is.EqualTo(40m));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoDiscount_TotalAndLineValues()
|
||||
{
|
||||
var order = new Order();
|
||||
order.AddLine(100m, 2); // line 0: 200
|
||||
order.AddLine(50m, 1); // line 1: 50
|
||||
|
||||
Assert.That(order.Total, Is.EqualTo(250m));
|
||||
Assert.That(order.Lines[0].Value, Is.EqualTo(200m));
|
||||
Assert.That(order.Lines[1].Value, Is.EqualTo(50m));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SingleLineWithDiscount_TotalAndValue()
|
||||
{
|
||||
var order = new Order();
|
||||
order.AddLine(75m, 4); // line 0: 300 → 240
|
||||
|
||||
order.ApplyDiscount(0);
|
||||
|
||||
Assert.That(order.Total, Is.EqualTo(240m));
|
||||
Assert.That(order.Lines[0].Value, Is.EqualTo(240m));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThreeLinesOneDiscount_TotalAndLineValues()
|
||||
{
|
||||
var order = new Order();
|
||||
order.AddLine(20m, 1); // line 0: 20
|
||||
order.AddLine(30m, 2); // line 1: 60 → 48
|
||||
order.AddLine(10m, 3); // line 2: 30
|
||||
|
||||
order.ApplyDiscount(1);
|
||||
|
||||
Assert.That(order.Total, Is.EqualTo(98m));
|
||||
Assert.That(order.Lines[0].Value, Is.EqualTo(20m));
|
||||
Assert.That(order.Lines[1].Value, Is.EqualTo(48m));
|
||||
Assert.That(order.Lines[2].Value, Is.EqualTo(30m));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user