From 70387f6b203163f05a6052482574c612229a1cee Mon Sep 17 00:00:00 2001 From: agentic-dev agent Date: Thu, 29 Oct 2026 09:49:42 +0000 Subject: [PATCH] docs: generate module documentation --- docs/README.md | 8 ++++ docs/src-Core.md | 96 ++++++++++++++++++++++++++++++++++++++++ docs/tests-Core.Tests.md | 65 +++++++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 docs/README.md create mode 100644 docs/src-Core.md create mode 100644 docs/tests-Core.Tests.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..6e2cf8f --- /dev/null +++ b/docs/README.md @@ -0,0 +1,8 @@ +# Documentation + +This repository holds the Gilded Rose kata in .NET (`net8.0`). It has a core library with the legacy implementation and a refactored, domain-modelled one. It also has an xUnit test project for the refactored code. + +## Index + +- [src/Core](src-Core.md): the `GildedRoseKata.Core` library. It holds the legacy `OriginalCode` and the refactored `ProposedCode` that update item quality at end of day. +- [tests/Core.Tests](tests-Core.Tests.md): the xUnit tests for `ProposedCode`. They cover the maturation service, item kinds, the maturing policy, `Quality` and `SellIn`. diff --git a/docs/src-Core.md b/docs/src-Core.md new file mode 100644 index 0000000..b5d64b7 --- /dev/null +++ b/docs/src-Core.md @@ -0,0 +1,96 @@ + +# GildedRoseKata.Core (`src/Core`) + +## Purpose + +`GildedRoseKata.Core` is the class library that holds the business logic of the Gilded Rose kata. It contains two implementations of the "update item quality at end of day" rule: + +- **`OriginalCode`** is the legacy implementation, a nested-`if` loop over a list of items. +- **`ProposedCode`** is a refactored, domain-modelled replacement. It uses value types, a kind hierarchy and a policy object. + +The project is listed in `GildedRoseKata.sln` as `GildedRoseKata.Core`. The test project `tests/Core.Tests` references it. The target framework (`net8.0`) comes from the repository-level `Directory.Build.props`. + +## Structure + +``` +src/Core/ +├── GildedRoseKata.Core.csproj +├── OriginalCode/ +│ ├── Item.cs +│ └── UpdateQualityService.cs +└── ProposedCode/ + ├── IMaturingPolicy.cs + ├── ItemMaturationService.cs + └── Domain/ + ├── ItemKind.cs + ├── ItemMaturingPolicy.cs + ├── ItemState.cs + ├── Quality.cs + └── SellIn.cs +``` + +The folder is `Domain/`, but all `ProposedCode` types are in the namespace `GildedRoseKata.ProposedCode`. The `OriginalCode` types are in `GildedRoseKata.OriginalCode`. + +## OriginalCode (legacy) + +- **`Item`** is a mutable class with `Name`, `SellIn` and `Quality`. The nullable warning on `Name` is suppressed. +- **`UpdateQualityService(IList items)`** has a single method, `UpdateQuality()`. It mutates every item in place with deeply nested conditionals that match on hard-coded item names. Warnings are suppressed around the method. + +## ProposedCode (refactored) + +### Public entry point + +**`ItemMaturationService`** has two constructors: +- The default constructor uses `ItemMaturingPolicy`. +- The second takes an `IMaturingPolicy`. + +`Item Mature(Item item)` does the following: +1. It maps `item.Name` to an `ItemKind`. +2. It builds an `ItemState` from the item's quality and sell-in. +3. It asks the policy to mature that state. +4. It returns a **new** `Item` with the same name and the updated values. The input item is not modified. + +It reuses the `Item` class from `OriginalCode`. + +### Policy + +- **`IMaturingPolicy`** defines `ItemState Mature(ItemKind kind, ItemState state)`. +- **`ItemMaturingPolicy`** is the default implementation. It switches on the kind: + +| Kind | Quality rule per day | +|---|---| +| Standard | Decreases by 1. Decreases by 1 more once sell-in is expired. | +| AgedBrie | Increases by 1. Increases by 1 more once expired. | +| Backstage | Uses the current sell-in: +3 if below 6, +2 if below 11, otherwise +1. Resets to 0 once the new sell-in is expired. | +| Conjured | Decreases by 2. Decreases by 2 more once expired. | +| Sulfuras | State returned unchanged. | + +### Domain types + +- **`ItemKind`** is an abstract record with nested sealed records `Standard`, `AgedBrie`, `Backstage`, `Conjured` and `Sulfuras`. `ItemKind.FromName(string)` maps these names: + - `"Aged Brie"` and `"AgedBrie"` map to `AgedBrie`. + - `"Backstage passes to a TAFKAL80ETC concert"` and `"Backstage"` map to `Backstage`. + - `"Conjured Mana Cake"` and `"Conjured"` map to `Conjured`. + - `"Sulfuras, Hand of Ragnaros"` maps to `Sulfuras`. + - Any other name maps to `Standard`. +- **`ItemState`** is a readonly record struct holding a `Quality` and a `SellIn`. `ItemState.Create(kind, quality, sellIn)` builds one from raw ints. +- **`Quality`** is a readonly record struct whose value is clamped to `Minimum = 0` and `Maximum = 50`. `Legendary = 80` is the constant for Sulfuras. It offers: + - `Increase(int amount = 1)` and `Decrease(int amount = 1)`, which throw `ArgumentOutOfRangeException` for negative amounts. + - `Reset()`, which returns a quality of 0. + - `FromItemKind(kind, value)`, which returns quality 80 for Sulfuras and a clamped value otherwise. +- **`SellIn`** is a readonly record struct with `Value`, `IsExpired` (value < 0), `IsBelow(int limit)` and `NextDay()`, which subtracts 1. + +## Building and testing + +The project is built as part of the solution: + +``` +dotnet build GildedRoseKata.sln +dotnet test tests/Core.Tests/GildedRoseKata.Core.Tests.csproj +``` + +The tests in `tests/Core.Tests` include `ProposedCode/ItemMaturationServiceTests.cs`. + +## Dependencies + +The csproj has no runtime package dependencies. It only sets `PackageReference Update` entries for the analyzers `Roslynator.Analyzers` (5.0.0) and `SonarAnalyzer.CSharp` (10.33.0.1635), and it clears `CodeAnalysisRuleSet` for Debug and Release. The source files carry a "KsiProgramming" copyright header. diff --git a/docs/tests-Core.Tests.md b/docs/tests-Core.Tests.md new file mode 100644 index 0000000..13966a0 --- /dev/null +++ b/docs/tests-Core.Tests.md @@ -0,0 +1,65 @@ + +# GildedRoseKata.Core.Tests + +This is the xUnit test project for `src/Core` (`GildedRoseKata.Core`), the Gilded Rose kata implementation. It tests the "proposed code" under `src/Core/ProposedCode`. That code is a domain model for aging items. The tests also feed it the `Item` class from `GildedRoseKata.OriginalCode`. + +## Layout + +``` +tests/Core.Tests/ +├── GildedRoseKata.Core.Tests.csproj +└── ProposedCode/ + ├── ItemMaturationServiceTests.cs + └── Domain/ + ├── ItemKindTests.cs + ├── ItemMaturingPolicyTests.cs + ├── QualityTests.cs + └── SellInTests.cs +``` + +All test classes use the namespace `GildedRoseKata.ProposedCode.Tests`. The folders mirror the source layout under `src/Core/ProposedCode`. + +## What is tested + +| Test class | Subject | Behaviour covered | +|---|---|---| +| `ItemMaturationServiceTests` | `ItemMaturationService.Mature(Item)` | An end-to-end theory over item names. It checks the resulting `Quality` and `SellIn` for standard, Aged Brie, Backstage, Conjured and Sulfuras items. Short names such as `"Backstage"`, `"Conjured"` and `"AgedBrie"` resolve to the same kinds as the full names. | +| `ItemKindTests` | `ItemKind.FromName` | Maps names to the `ItemKind.AgedBrie`, `Backstage`, `Conjured`, `Sulfuras` and `Standard` types. The default is `Standard`. | +| `ItemMaturingPolicyTests` | `ItemMaturingPolicy.Mature(kind, ItemState)` | Per-kind daily rules, including boundary cases: | +| | | • Standard items lose 1 quality, or 2 once expired. | +| | | • Aged Brie gains quality, capped at 50. | +| | | • Backstage passes gain 1, 2 or 3 depending on days left, and drop to 0 after the concert. | +| | | • Conjured items degrade at double speed. | +| | | • Sulfuras state is returned unchanged. | +| `QualityTests` | `Quality` | The constructor clamps values to the range 0–50. `Increase` and `Decrease` respect those bounds. `Reset` returns 0. `FromItemKind` returns `Quality.Legendary` for Sulfuras. | +| `SellInTests` | `SellIn` | `IsExpired` is true only for strictly negative values. `IsBelow(limit)` and `NextDay()` (decrement by one) are also covered. | + +The tests also use `ItemState` (constructed from `Quality` and `SellIn`, or through `ItemState.Create(kind, quality, sellIn)`). + +## Building and running + +The repository shows no custom scripts, so the standard .NET CLI applies: + +``` +dotnet test tests/Core.Tests/GildedRoseKata.Core.Tests.csproj +``` + +`coverlet.collector` is referenced, so coverage can be collected with `--collect:"XPlat Code Coverage"`. + +## Dependencies + +Defined in `GildedRoseKata.Core.Tests.csproj`: + +- Project reference: `..\..\src\Core\GildedRoseKata.Core.csproj` +- `xunit` 2.9.3, with `xunit.runner.visualstudio` 4.0.0 as the runner. `Xunit` is a global `using`. +- `Microsoft.NET.Test.Sdk` 18.9.0 +- `FluentAssertions` 8.10.0, used for assertions throughout +- `coverlet.collector` 10.0.1 for code coverage +- Analyzer version overrides for `Roslynator.Analyzers` (5.0.0) and `SonarAnalyzer.CSharp` (10.33.0.1635). `CodeAnalysisRuleSet` is cleared in both Debug and Release. + +The project is marked `IsTestProject=true` and `IsPackable=false`. + +## Conventions + +- Tests are mostly data-driven `[Theory]` / `[InlineData]` cases, named `Method_Condition_ExpectedBehaviour`. +- Each file starts with a copyright header (KsiProgramming).