Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1415257890 |
@@ -1 +0,0 @@
|
||||
website/
|
||||
@@ -1,210 +0,0 @@
|
||||
---
|
||||
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.
|
||||
@@ -0,0 +1,9 @@
|
||||
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.
|
||||
@@ -0,0 +1,3 @@
|
||||
# learning-hour-maker
|
||||
|
||||
a coding agent skill to make learning hours, and learning hours in development
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
#+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
|
||||
@@ -1,19 +0,0 @@
|
||||
## 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
|
||||
@@ -1,17 +0,0 @@
|
||||
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
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,151 +0,0 @@
|
||||
---
|
||||
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.
|
||||
|
||||
## Session Outline
|
||||
|
||||
* 5 min connect: Frustrating agent conversations
|
||||
* 5 min concept: LLMs are pattern matchers
|
||||
* 35 min concrete practice: Refactor tests using a custom matcher example
|
||||
* 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 — Refactor Tests with a Custom Matcher
|
||||
|
||||
### 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
|
||||
|
||||
## 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?
|
||||
|
||||
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.
|
||||
@@ -1,14 +0,0 @@
|
||||
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();
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,19 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
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)
|
||||
{
|
||||
return new OrderStateConstraint(expectedTotal, expectedLineValues);
|
||||
}
|
||||
}
|
||||
|
||||
public class OrderStateConstraint : Constraint
|
||||
{
|
||||
private readonly decimal _expectedTotal;
|
||||
private readonly decimal[] _expectedLineValues;
|
||||
|
||||
public OrderStateConstraint(decimal expectedTotal, decimal[] expectedLineValues)
|
||||
: base($"order with total {expectedTotal} and line values [{string.Join(", ", expectedLineValues)}]")
|
||||
{
|
||||
_expectedTotal = expectedTotal;
|
||||
_expectedLineValues = 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 totalMatch = actualTotal == _expectedTotal;
|
||||
var linesMatch = actualLineValues.SequenceEqual(_expectedLineValues);
|
||||
|
||||
var messages = new List<string>();
|
||||
if (!totalMatch)
|
||||
messages.Add($"Total: expected {_expectedTotal}, got {actualTotal}");
|
||||
if (!linesMatch)
|
||||
messages.Add($"Line values: expected [{string.Join(", ", _expectedLineValues)}], got [{string.Join(", ", actualLineValues)}]");
|
||||
|
||||
return new ConstraintResult(this, actual, totalMatch && linesMatch);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<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="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\OrderDomain\OrderDomain.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,92 +0,0 @@
|
||||
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: new[] { 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