From 5545bb076b73ed3a1f50aa5e57ea5b3d9477346e Mon Sep 17 00:00:00 2001 From: agentic-dev agent Date: Fri, 13 Nov 2026 10:42:21 +0000 Subject: [PATCH] docs: generate module documentation --- docs/README.md | 8 +++ docs/src-Core.md | 125 +++++++++++++++++++++++++++++++++++++++ docs/tests-Core.Tests.md | 78 ++++++++++++++++++++++++ 3 files changed, 211 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..731de6a --- /dev/null +++ b/docs/README.md @@ -0,0 +1,8 @@ +# Documentation + +This repository is a C# (.NET) solution for the Gilded Rose kata. The task is to update the `SellIn` and `Quality` of inn items each day. The solution has a core library with a legacy and a refactored implementation of the rules, and an xUnit test project for the refactored code. + +## Modules + +- [src/Core](src-Core.md): the production library. It holds the legacy `OriginalCode` and the refactored, non-mutating `ProposedCode`. +- [tests/Core.Tests](tests-Core.Tests.md): the xUnit and FluentAssertions tests for `ProposedCode`: value types, item kinds, maturing policy and service. diff --git a/docs/src-Core.md b/docs/src-Core.md new file mode 100644 index 0000000..9b76b9a --- /dev/null +++ b/docs/src-Core.md @@ -0,0 +1,125 @@ + +# GildedRoseKata.Core (`src/Core`) + +## Purpose + +`src/Core` is the class library (`GildedRoseKata.Core.csproj`) that holds all production code for the Gilded Rose kata. The kata is about updating the `SellIn` and `Quality` values of inn items at the end of each day. The rules are in the repository `README.md`. + +The module holds two implementations of those rules side by side: + +- **`OriginalCode`** is the legacy starting point of the kata. It is a nested-`if` `UpdateQuality` method that mutates items in place. +- **`ProposedCode`** is a refactored design. It splits the rules into small value types, an item-kind hierarchy and a replaceable policy. It does not mutate its input. + +## Place in the repository + +- The solution is `GildedRoseKata.sln`. This module is the only project under `src/`. +- The test project `tests/Core.Tests` (`GildedRoseKata.Core.Tests.csproj`) references this project. Its tests cover `ProposedCode`: `ItemKindTests`, `ItemMaturingPolicyTests`, `QualityTests`, `SellInTests` and `ItemMaturationServiceTests`. No tests for `OriginalCode` appear in the test folder. +- `ProposedCode` depends on `OriginalCode.Item` as its input and output type. `OriginalCode` does not depend on `ProposedCode`. + +## 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 `Domain` folder only groups files. Every type is in the namespace `GildedRoseKata.ProposedCode`, and the original types are in `GildedRoseKata.OriginalCode`. + +## OriginalCode + +- **`Item`** is a mutable class with `Name` (string), `SellIn` (int) and `Quality` (int). It is the shared data type, and the kata says it must not be altered. +- **`UpdateQualityService(IList items)`** takes the list in its primary constructor. `UpdateQuality()` walks the list and changes each item in place. It hard-codes the item names "Aged Brie", "Backstage passes to a TAFKAL80ETC concert" and "Sulfuras, Hand of Ragnaros". Warnings are suppressed around the method with `#pragma warning disable`. It has no handling for "Conjured" items. + +## ProposedCode + +### Public API + +| Type | Role | +|---|---| +| `ItemMaturationService` | Entry point. `Item Mature(Item item)` returns a **new** `Item` with the same `Name` and the updated `Quality` and `SellIn`. It has a default constructor, which uses `ItemMaturingPolicy`, and a constructor that takes an `IMaturingPolicy`. | +| `IMaturingPolicy` | `ItemState Mature(ItemKind kind, ItemState state)`. This is the extension point for the rules. | +| `ItemMaturingPolicy` | The default `IMaturingPolicy`. It chooses a rule by `ItemKind`. | +| `ItemKind` | Abstract record with sealed nested records `Standard`, `AgedBrie`, `Backstage`, `Conjured` and `Sulfuras`. `ItemKind.FromName(string)` maps item names to kinds. | +| `ItemState` | Readonly record struct of `Quality` and `SellIn`. `ItemState.Create(kind, quality, sellIn)` builds one. | +| `Quality` | Readonly record struct for a quality value. | +| `SellIn` | Readonly record struct for days left to sell. | + +### Flow + +`ItemMaturationService.Mature` runs these steps: + +1. It calls `ItemKind.FromName(item.Name)`. +2. It calls `ItemState.Create(kind, item.Quality, item.SellIn)`. +3. It calls `IMaturingPolicy.Mature(kind, state)`. +4. It copies the result into a new `Item`. + +### Name mapping (`ItemKind.FromName`) + +- `"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`. The match is exact and case-sensitive. + +### Value types + +- **`Quality`** + - Constants are `Minimum = 0`, `Maximum = 50` and `Legendary = 80`. + - The public constructor clamps the value to 0–50. + - `FromItemKind(kind, value)` returns the legendary value 80 for `Sulfuras` and a clamped value for any other kind. + - `Increase(amount = 1)` and `Decrease(amount = 1)` return new, clamped values. A negative `amount` throws `ArgumentOutOfRangeException`. + - `Reset()` returns 0. +- **`SellIn`** + - `Value` holds the day count. + - `IsExpired` is true when the value is below 0. + - `IsBelow(limit)` tests whether the value is below `limit`. + - `NextDay()` returns a copy with the value decreased by 1. + +### Rules in `ItemMaturingPolicy` + +Each rule moves `SellIn` forward one day. "Expired" means the new `SellIn` is below 0. + +| Kind | Quality change | +|---|---| +| Standard | −1, and −1 more once expired. | +| AgedBrie | +1, and +1 more once expired. | +| Backstage | Uses the `SellIn` before the day passes: +3 if below 6, +2 if below 11, otherwise +1. Resets to 0 once expired. | +| Conjured | −2, and −2 more once expired. | +| Sulfuras | The state is returned unchanged, so `SellIn` does not change. | + +Quality is always kept between 0 and 50 by `Quality`. The exception is Sulfuras, which is created with quality 80. + +## Build and test + +The repository does not document local commands beyond the CI workflow. `.github/workflows/build.yml` runs these commands from the repository root: + +``` +dotnet restore +dotnet build --no-restore +dotnet test --no-build --verbosity normal +``` + +`dotnet.yml` triggers the workflow on pushes and pull requests to `master`, using .NET `9.0.x`. + +## Dependencies and build configuration + +- This project has no runtime package dependencies and no project references. +- `Directory.Build.props` at the repository root supplies the shared settings: + - Target framework `net8.0`, `LangVersion` `latest`, implicit usings enabled and nullable reference types enabled. + - `TreatWarningsAsErrors` is `false`. + - Analyzers are disabled in the Release configuration. + - The analyzer packages `Roslynator.Analyzers` and `SonarAnalyzer.CSharp` are referenced for every project. +- `GildedRoseKata.Core.csproj` only updates the versions of those two analyzer packages (Roslynator 5.0.0, Sonar 10.33.0.1635) and clears `CodeAnalysisRuleSet`. +- The test project uses xUnit, FluentAssertions and coverlet. diff --git a/docs/tests-Core.Tests.md b/docs/tests-Core.Tests.md new file mode 100644 index 0000000..df7329d --- /dev/null +++ b/docs/tests-Core.Tests.md @@ -0,0 +1,78 @@ + +# GildedRoseKata.Core.Tests + +The `tests/Core.Tests` project holds the xUnit test suite for `src/Core` (`GildedRoseKata.Core`). That library contains two implementations of the Gilded Rose Kata inventory update logic. These are the legacy `OriginalCode` and the refactored `ProposedCode`. The tests here cover the `ProposedCode` side: the domain value types, the item-kind resolution, the maturing policy and the service that ties them together. + +## Role in the repository + +- It is the only test project in `GildedRoseKata.sln`. It sits under `tests/` and mirrors the `src/Core` layout. +- It references `..\..\src\Core\GildedRoseKata.Core.csproj`. +- Its test files are in the `GildedRoseKata.ProposedCode.Tests` namespace. They exercise the `ProposedCode` types directly. +- `ItemMaturationServiceTests` also imports `GildedRoseKata.OriginalCode` to build the `Item` objects (`Name`, `Quality`, `SellIn`) that the service accepts. + +## Layout + +``` +tests/Core.Tests/ +├── GildedRoseKata.Core.Tests.csproj +└── ProposedCode/ + ├── ItemMaturationServiceTests.cs + └── Domain/ + ├── ItemKindTests.cs + ├── ItemMaturingPolicyTests.cs + ├── QualityTests.cs + └── SellInTests.cs +``` + +## What is tested + +All tests are xUnit `[Theory]` (with `[InlineData]`) or `[Fact]` cases. Assertions use FluentAssertions. + +| Test class | Subject | Behaviour covered | +|---|---|---| +| `ItemMaturationServiceTests` | `ItemMaturationService.Mature(Item)` | End-to-end check from item name to resulting `Quality` and `SellIn`. Cases include a standard item, "Aged Brie"/"AgedBrie", the full Backstage name and "Backstage", "Conjured Mana Cake"/"Conjured", and Sulfuras (quality 80, unchanged). | +| `ItemKindTests` | `ItemKind.FromName` | Maps names to the kinds `AgedBrie`, `Backstage`, `Conjured`, `Sulfuras` and `Standard`. It accepts both full and short names. Unknown names fall back to `Standard`. | +| `ItemMaturingPolicyTests` | `ItemMaturingPolicy.Mature(ItemKind, ItemState)` | Per-kind rules, using `ItemState`, `Quality` and `SellIn`. See the list below. | +| `QualityTests` | `Quality` | The constructor clamps values to 0–50. `Increase` and `Decrease` respect the bounds. `Reset` returns 0. `FromItemKind` gives `Quality.Legendary` for Sulfuras. | +| `SellInTests` | `SellIn` | `IsExpired` is true only for strictly negative values. `IsBelow(limit)` is a strict comparison. `NextDay()` decrements by one. | + +The `ItemMaturingPolicyTests` cases cover these rules: +- **Standard:** quality drops by 1 per day and by 2 once the sell-in date has passed. It never goes below 0. +- **Aged Brie:** quality rises by 1, or by 2 once expired, and is capped at 50. +- **Backstage:** quality rises by 1 above 10 days, by 2 at 10 days or fewer, and by 3 at 5 days or fewer. It drops to 0 after the concert and is capped at 50. +- **Conjured:** quality degrades by 2 per day and by 4 once expired. It never goes below 0. +- **Sulfuras:** the state is returned unchanged. + +These rules match the kata description in the root `README.md`. + +## Running the tests + +The repository's CI workflow (`.github/workflows/build.yml`, called from `dotnet.yml`) runs the following from the repository root: + +``` +dotnet restore +dotnet build --no-restore +dotnet test --no-build --verbosity normal +``` + +To run only this project: + +``` +dotnet test tests/Core.Tests/GildedRoseKata.Core.Tests.csproj +``` + +`dotnet.yml` sets up .NET `9.0.x` in CI. `Directory.Build.props` sets `TargetFramework` to `net8.0`, so both runtimes are relevant to a local setup. + +## Build configuration and dependencies + +The project file sets `IsTestProject=true` and `IsPackable=false`, and adds a global `using Xunit`. The shared `Directory.Build.props` supplies `net8.0`, `LangVersion latest`, implicit usings, nullable reference types, and `TreatWarningsAsErrors=false`. It also supplies the Roslynator and Sonar analyzers, which are disabled in Release builds. + +Package references: +- `xunit` 2.9.3 +- `xunit.runner.visualstudio` 4.0.0 +- `Microsoft.NET.Test.Sdk` 18.9.0 +- `FluentAssertions` 8.10.0 +- `coverlet.collector` 10.0.1, for code coverage +- Version updates for `Roslynator.Analyzers` (5.0.0) and `SonarAnalyzer.CSharp` (10.33.0.1635) + +Project reference: `GildedRoseKata.Core`.