diff --git a/specs/add-a-new-product-to-gilded-rose/plan.md b/specs/add-a-new-product-to-gilded-rose/plan.md new file mode 100644 index 0000000..bd25a5c --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/plan.md @@ -0,0 +1,34 @@ +# Implementation plan: Add Mature Cheese to Gilded Rose + +## Technical context + +The proposed implementation is C# on .NET 8, with nullable reference types and the latest C# language version. Product rules use `ItemKind`, `ItemState`, and `Quality` value types, applied through `ItemMaturingPolicy` and `ItemMaturationService`. Tests use xUnit and FluentAssertions; CI runs `dotnet test`. + +## Approach + +Add a `MatureCheese` item kind and recognize only the exact name `Mature Cheese`. Route that kind to an isolated policy method that decides the quality increase from the starting `SellIn`, clamps quality using the existing `Quality` behavior, and decrements `SellIn` once. Preserve all existing policy branches and leave Original Code untouched. + +Extend the proposed-code tests for exact-name recognition, before/on/after sell-by behavior, quality boundaries and invalid imported values, countdown, input immutability, mixed items, and regression behavior. Proceed with the values specified in the feature requirements: increases of 1 and 2, maximum quality 50, and no maximum-age penalty. + +## Files + +- `src/Core/ProposedCode/Domain/ItemKind.cs` — add the Mature Cheese kind and exact-name mapping. +- `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` — add the isolated update rule without changing existing product rules. +- `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` — cover exact recognition and similar-but-not-exact names. +- `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` — cover quality increase based on pre-decrement sell-by value, decrement, and quality bounds. +- `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` — cover service-level normalization, unchanged input, multiple items, and existing-product behavior. + +## Risks + +`ItemKind` and `ItemMaturingPolicy` are shared by existing products; changes there could affect their behavior, so retain existing mappings and branches and run the full proposed-code test suite. `Quality` already clamps to 0–50 for ordinary items, while Sulfuras has special handling; use that existing policy rather than changing the shared quality type. No public interface changes or migrations are expected. Original Code must remain unchanged. + +## Test plan + +Run `dotnet test tests/Core.Tests/GildedRoseKata.Core.Tests.csproj`. + +- **FR-001, FR-007:** Item-kind tests verify exact `Mature Cheese` recognition and reject similar names. +- **FR-002–FR-005:** Policy tests verify decrement, +1 when starting `sellIn > 0`, +2 when starting `sellIn <= 0`, and the 50 ceiling. +- **FR-006:** Service tests verify qualities below 0 and above 50 are normalized and remain in range after update; boundary cases cover 0, 1, 49, and 50. +- **FR-008, FR-012, FR-013:** Existing product tests and mixed-item cases verify existing behavior remains unchanged; keep production edits confined to Proposed Code. +- **FR-009:** Service tests verify processing an item does not mutate the input item; no update operation means no value changes. +- **FR-010–FR-011:** Policy tests verify no added maximum-age behavior and deterministic results for repeated identical starting states. \ No newline at end of file diff --git a/specs/add-a-new-product-to-gilded-rose/spec.md b/specs/add-a-new-product-to-gilded-rose/spec.md new file mode 100644 index 0000000..a312ec1 --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/spec.md @@ -0,0 +1,101 @@ +# Feature specification: Add Mature Cheese to Gilded Rose +spec.md + +UI work: no + +## User scenarios + +**Daily inventory update:** As the inventory update process, I want Mature Cheese quality and sell-by values updated each day so that its quality improves according to its age. + +- Given a Mature Cheese item with `sellIn` above zero, when the inventory is updated, then quality increases by 1 and `sellIn` decreases by 1. +- Given a Mature Cheese item with `sellIn` equal to or below zero, when the inventory is updated, then quality increases by 2 and `sellIn` decreases by 1; the increase is based on `sellIn` before it is decremented. + +**Protect quality values:** As the inventory system, I want Mature Cheese quality kept within valid bounds so that invalid quality values are not stored after an update. + +- Given Mature Cheese at or near either quality boundary, when the inventory is updated, then its quality remains between 0 and 50 inclusive. + +**Preserve other inventory behavior:** As the inventory manager, I want the new product rule limited to the exact product name and proposed code so that existing product behavior is preserved. + +- Given a mixed inventory, when it is updated, then only the exact Mature Cheese product receives the new rule, and existing product behavior remains unchanged. + +## Requirements + +FR-001 The system shall recognize `Mature Cheese` as an aging food product with an initial quality in the range 0–50 and a sell-by value measured in days remaining. [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?] + +FR-002 At each daily inventory update, the system shall decrease Mature Cheese `sellIn` by 1. + +FR-003 When Mature Cheese `sellIn` is greater than 0 at the start of an update, the system shall increase its quality by 1. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?] + +FR-004 When Mature Cheese `sellIn` is 0 or less at the start of an update, the system shall increase its quality by 2. [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?] + +FR-005 The system shall cap Mature Cheese quality at 50 after an update. [NEEDS CLARIFICATION: Is 50 the correct maximum quality?] + +FR-006 The system shall keep Mature Cheese quality between 0 and 50 inclusive after an update, including when imported quality is outside that range; invalid imported values shall follow the existing policy of normalizing to the range. + +FR-007 The system shall apply the new behavior only to the exact product name `Mature Cheese`. [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?] + +FR-008 The system shall preserve existing behavior for other product types, including Aged Brie, Backstage passes, Sulfuras, and Conjured items. + +FR-009 Creating, reading, displaying, or searching for a Mature Cheese item shall not change its quality or `sellIn`; these values shall change only during the daily inventory update. + +FR-010 The system shall not add behavior that makes Mature Cheese unsafe or reduces its value after a maximum age unless that behavior is confirmed. [NEEDS CLARIFICATION: Should Mature Cheese have special behavior such as becoming unsafe or losing value after a maximum age?] + +FR-011 The system shall produce the same result for the same starting item and daily update operation. + +FR-012 The new rule shall be isolated and covered by automated unit tests, including the suggested cases `increases_quality_by_one_before_sell_by`, `increases_quality_by_two_on_sell_by_date`, `increases_quality_by_two_after_sell_by`, `does_not_increase_quality_above_fifty`, `keeps_quality_at_fifty`, `decreases_sell_in_by_one_each_day`, and `does_not_change_existing_product_behaviour`. + +FR-013 The change shall be limited to Proposed Code and shall not change Original Code. + +## Success criteria + +SC-001 A Mature Cheese item with `sellIn = 5` and `quality = 10` updates to `sellIn = 4` and `quality = 11`. + +SC-002 A Mature Cheese item with `sellIn = 1` and `quality = 10` updates to `sellIn = 0` and `quality = 11`; with `sellIn = 0` and `quality = 10`, it updates to `sellIn = -1` and `quality = 12`; with `sellIn = -1` and `quality = 10`, it updates to `sellIn = -2` and `quality = 12`. + +SC-003 Updates keep quality within 0–50 for starting qualities 0, 1, 49, and 50, including multiple consecutive updates and invalid imported values. + +SC-004 Multiple Mature Cheese items update correctly in the same inventory, and similar-but-not-exact product names and other product types retain their existing behavior. + +SC-005 Existing product behavior and outputs remain unchanged, and Original Code remains unchanged. + +## Acceptance criteria + +AC-001 When a Mature Cheese item is created and updated, the system shall recognize the specified product and valid initial quality and treat `sellIn` as days remaining (FR-001). + +AC-002 When a Mature Cheese item undergoes a daily update, the system shall decrease `sellIn` by exactly 1 (FR-002). + +AC-003 When an update starts with Mature Cheese `sellIn` greater than 0, the system shall increase quality by exactly 1 (FR-003). + +AC-004 When an update starts with Mature Cheese `sellIn` equal to or below 0, the system shall increase quality by exactly 2 using the pre-decrement `sellIn` value (FR-004). + +AC-005 When a quality increase would put Mature Cheese above 50, the system shall store quality as 50 (FR-005). + +AC-006 When an update processes Mature Cheese with quality below 0 or above 50, the system shall leave its updated quality within 0–50, applying the existing normalization policy to invalid imported values (FR-006). + +AC-007 When an item name is exactly `Mature Cheese`, the system shall apply the new rule, and when its name differs, the system shall not apply that rule (FR-007). + +AC-008 When an inventory containing existing product types is updated, the system shall preserve their previous behavior, including the named special products (FR-008). + +AC-009 When a Mature Cheese item is created, read, displayed, or searched without a daily update, the system shall leave its quality and `sellIn` unchanged (FR-009). + +AC-010 When Mature Cheese is updated at any age, the system shall apply no unconfirmed unsafe-product or maximum-age value-loss behavior (FR-010). + +AC-011 When the same starting item is processed by the same daily update operation, the system shall produce the same updated values (FR-011). + +AC-012 When the Mature Cheese behavior is covered by automated unit tests, the system shall include tests for the listed before-sell-by, on-sell-by, after-sell-by, quality-boundary, sell-by countdown, and existing-product behavior cases (FR-012). + +AC-013 When the Mature Cheese change is made, the system shall leave Original Code unchanged and limit the implementation change to Proposed Code (FR-013). + +## Out of scope + +- User-interface changes. +- Changes to existing product rules or unrelated refactoring. +- Changes to Original Code. +- Additional Mature Cheese behavior beyond the proposed rules, pending clarification about maximum-age behavior. + +## Open questions + +- [NEEDS CLARIFICATION: Is the official product name `Mature Cheese`, or should it be another exact name?] +- [NEEDS CLARIFICATION: Should quality increase by 1 before sell-by and 2 afterwards?] +- [NEEDS CLARIFICATION: Is 50 the correct maximum quality?] +- [NEEDS CLARIFICATION: Should Mature Cheese have special behavior such as becoming unsafe or losing value after a maximum age?] \ No newline at end of file diff --git a/specs/add-a-new-product-to-gilded-rose/tasks.md b/specs/add-a-new-product-to-gilded-rose/tasks.md new file mode 100644 index 0000000..b16a724 --- /dev/null +++ b/specs/add-a-new-product-to-gilded-rose/tasks.md @@ -0,0 +1,16 @@ +# Tasks: Add Mature Cheese to Gilded Rose +- [ ] T001 Add `AC001_RecognizesMatureCheeseWithValidQuality` in `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` (FR-001, AC-001) +- [ ] T002 Add `AC002_DecreasesSellInByOneEachDay` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-002, AC-002) +- [ ] T003 Add `AC003_IncreasesQualityByOneBeforeSellBy` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-003, AC-003) +- [ ] T004 Add `AC004_IncreasesQualityByTwoAtOrAfterSellByUsingStartingSellIn` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-004, AC-004) +- [ ] T005 Add `AC005_CapsQualityAtFifty` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-005, AC-005) +- [ ] T006 Add `AC006_NormalizesInvalidImportedQuality` in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-006, AC-006) +- [ ] T007 Add `AC007_RejectsSimilarButNotExactProductNames` in `tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs` (FR-007, AC-007) +- [ ] T008 Add `AC008_PreservesExistingProductBehaviorInMixedInventory` in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-008, AC-008) +- [ ] T009 Add `AC009_LeavesInputUnchangedOutsideDailyUpdate` in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-009, AC-009) +- [ ] T010 Add `AC010_AppliesNoMaximumAgePenalty` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-010, AC-010) +- [ ] T011 Add `AC011_ProducesDeterministicResults` in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-011, AC-011) +- [ ] T012 Add `AC012_CoversRequiredMatureCheeseScenarios` for the specified sell-by, quality-boundary, countdown, and existing-product cases in `tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs` (FR-012, AC-012) +- [ ] T013 Add `AC013_PreservesOriginalCodeBehavior` regression coverage in `tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs` (FR-013, AC-013) +- [ ] T014 [P] Add the Mature Cheese kind and exact-name mapping in `src/Core/ProposedCode/Domain/ItemKind.cs` after T013 (FR-001, FR-007, FR-013, AC-001, AC-007, AC-013) +- [ ] T015 [P] Add the isolated Mature Cheese update rule using starting `SellIn` and bounded quality in `src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs` after T014 (FR-002, FR-003, FR-004, FR-005, FR-006, FR-008, FR-010, FR-011, FR-013, AC-002, AC-003, AC-004, AC-005, AC-006, AC-008, AC-010, AC-011, AC-013) \ No newline at end of file diff --git a/src/Core/ProposedCode/Domain/ItemKind.cs b/src/Core/ProposedCode/Domain/ItemKind.cs index 199f351..cb7f8a6 100644 --- a/src/Core/ProposedCode/Domain/ItemKind.cs +++ b/src/Core/ProposedCode/Domain/ItemKind.cs @@ -18,6 +18,8 @@ public sealed record Conjured : ItemKind; public sealed record Sulfuras : ItemKind; + public sealed record MatureCheese : ItemKind; + public static ItemKind FromName(string itemName) { return itemName switch @@ -29,7 +31,8 @@ public static ItemKind FromName(string itemName) "Conjured Mana Cake" => new Conjured(), "Conjured" => new Conjured(), "Sulfuras, Hand of Ragnaros" => new Sulfuras(), + "Mature Cheese" => new MatureCheese(), _ => new Standard(), }; } -} \ No newline at end of file +} diff --git a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs index 0221621..96a2fb6 100644 --- a/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs +++ b/src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs @@ -16,6 +16,7 @@ public ItemState Mature(ItemKind kind, ItemState state) ItemKind.Backstage => this.MatureBackstage(state), ItemKind.Conjured => this.MatureConjured(state), ItemKind.Sulfuras => state, + ItemKind.MatureCheese => this.MatureCheese(state), _ => this.MatureStandard(state), }; } @@ -77,4 +78,13 @@ private ItemState MatureConjured(ItemState state) return new(newQuality, newSellIn); } -} \ No newline at end of file + + private ItemState MatureCheese(ItemState state) + { + var qualityIncrease = state.SellIn.Value > 0 ? 1 : 2; + var newQuality = state.Quality.Increase(qualityIncrease); + var newSellIn = state.SellIn.NextDay(); + + return new(newQuality, newSellIn); + } +} diff --git a/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs b/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs index 040e12d..e4260a0 100644 --- a/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs +++ b/tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs @@ -25,4 +25,23 @@ public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType result.Should().BeOfType(expectedType); } -} \ No newline at end of file + + [Fact] + public void AC001_RecognizesMatureCheeseWithValidQuality() + { + var result = ItemKind.FromName("Mature Cheese"); + + result.Should().BeOfType(); + } + + [Theory] + [InlineData("Mature cheese")] + [InlineData("Mature Cheeses")] + [InlineData("Mature Cheese ")] + public void AC007_RejectsSimilarButNotExactProductNames(string itemName) + { + var result = ItemKind.FromName(itemName); + + result.Should().BeOfType(); + } +} diff --git a/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs b/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs index 55d645c..4406a9c 100644 --- a/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs +++ b/tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs @@ -12,6 +12,136 @@ public class ItemMaturingPolicyTests { private readonly ItemMaturingPolicy policy = new(); + [Theory] + [InlineData(5, 4)] + [InlineData(0, -1)] + [InlineData(-1, -2)] + public void AC002_DecreasesSellInByOneEachDay(int sellIn, int expectedSellIn) + { + var state = new ItemState(new Quality(10), new SellIn(sellIn)); + + var result = this.policy.Mature(ItemKind.FromName("Mature Cheese"), state); + + result.SellIn.Value.Should().Be(expectedSellIn); + } + + [Theory] + [InlineData(0, 5)] + [InlineData(1, 5)] + [InlineData(49, 5)] + public void AC003_IncreasesQualityByOneBeforeSellBy(int quality, int sellIn) + { + var state = new ItemState(new Quality(quality), new SellIn(sellIn)); + + var result = this.policy.Mature(ItemKind.FromName("Mature Cheese"), state); + + result.Quality.Value.Should().Be(quality + 1); + result.SellIn.Value.Should().Be(sellIn - 1); + } + + [Theory] + [InlineData(10, 1, 11, 0)] + [InlineData(10, 0, 12, -1)] + [InlineData(10, -1, 12, -2)] + public void AC004_IncreasesQualityByTwoAtOrAfterSellByUsingStartingSellIn( + int quality, + int sellIn, + int expectedQuality, + int expectedSellIn) + { + var state = new ItemState(new Quality(quality), new SellIn(sellIn)); + + var result = this.policy.Mature(ItemKind.FromName("Mature Cheese"), state); + + result.Quality.Value.Should().Be(expectedQuality); + result.SellIn.Value.Should().Be(expectedSellIn); + } + + [Theory] + [InlineData(49, 5, 50)] + [InlineData(49, 0, 50)] + [InlineData(50, 5, 50)] + [InlineData(50, 0, 50)] + public void AC005_CapsQualityAtFifty(int quality, int sellIn, int expectedQuality) + { + var state = new ItemState(new Quality(quality), new SellIn(sellIn)); + + var result = this.policy.Mature(ItemKind.FromName("Mature Cheese"), state); + + result.Quality.Value.Should().Be(expectedQuality); + } + + [Fact] + public void AC010_AppliesNoMaximumAgePenalty() + { + var state = new ItemState(new Quality(10), new SellIn(-100)); + + var result = this.policy.Mature(ItemKind.FromName("Mature Cheese"), state); + + result.Quality.Value.Should().Be(12); + result.SellIn.Value.Should().Be(-101); + } + + [Fact] + public void AC011_ProducesDeterministicResults() + { + var initialState = new ItemState(new Quality(48), new SellIn(1)); + var kind = ItemKind.FromName("Mature Cheese"); + + var firstResult = this.policy.Mature(kind, initialState); + var secondResult = this.policy.Mature(kind, initialState); + + firstResult.Should().Be(secondResult); + firstResult.Quality.Value.Should().Be(49); + firstResult.SellIn.Value.Should().Be(0); + } + + [Fact] + public void AC012_CoversRequiredMatureCheeseScenarios() + { + var kind = ItemKind.FromName("Mature Cheese"); + var scenarios = new (int Quality, int SellIn, int ExpectedQuality, int ExpectedSellIn)[] + { + (0, 5, 1, 4), + (1, 5, 2, 4), + (49, 5, 50, 4), + (50, 5, 50, 4), + (0, 0, 2, -1), + (1, 0, 3, -1), + (49, 0, 50, -1), + (50, 0, 50, -1), + (10, -1, 12, -2), + }; + + foreach (var scenario in scenarios) + { + var state = new ItemState(new Quality(scenario.Quality), new SellIn(scenario.SellIn)); + var result = this.policy.Mature(kind, state); + + result.Quality.Value.Should().Be(scenario.ExpectedQuality); + result.SellIn.Value.Should().Be(scenario.ExpectedSellIn); + } + + var countdown = new ItemState(new Quality(0), new SellIn(2)); + var dayOne = this.policy.Mature(kind, countdown); + var dayTwo = this.policy.Mature(kind, dayOne); + var dayThree = this.policy.Mature(kind, dayTwo); + + dayOne.Should().Be(new ItemState(new Quality(1), new SellIn(1))); + dayTwo.Should().Be(new ItemState(new Quality(2), new SellIn(0))); + dayThree.Should().Be(new ItemState(new Quality(4), new SellIn(-1))); + + this.policy.Mature(new ItemKind.AgedBrie(), new ItemState(new Quality(20), new SellIn(4))) + .Should().Be(new ItemState(new Quality(21), new SellIn(3))); + this.policy.Mature(new ItemKind.Backstage(), new ItemState(new Quality(20), new SellIn(5))) + .Should().Be(new ItemState(new Quality(23), new SellIn(4))); + this.policy.Mature(new ItemKind.Conjured(), new ItemState(new Quality(5), new SellIn(5))) + .Should().Be(new ItemState(new Quality(3), new SellIn(4))); + + var sulfuras = ItemState.Create(new ItemKind.Sulfuras(), 80, 0); + this.policy.Mature(new ItemKind.Sulfuras(), sulfuras).Should().Be(sulfuras); + } + [Theory] [InlineData(0, 2, 0, 1)] [InlineData(10, 5, 9, 4)] @@ -89,4 +219,4 @@ public void Mature_WhenKindIsSulfuras_PreservesProvidedState() result.Should().Be(state); } -} \ No newline at end of file +} diff --git a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs index 4690ec6..3c88156 100644 --- a/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs +++ b/tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs @@ -35,4 +35,115 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit result.Quality.Should().Be(expectedQuality); result.SellIn.Should().Be(expectedSellIn); } -} \ No newline at end of file + + [Theory] + [InlineData(-10, 1)] + [InlineData(60, 50)] + public void AC006_NormalizesInvalidImportedQuality(int importedQuality, int expectedQuality) + { + var service = new ItemMaturationService(); + var item = new Item + { + Name = "Mature Cheese", + Quality = importedQuality, + SellIn = 5, + }; + + var result = service.Mature(item); + + result.Quality.Should().Be(expectedQuality); + result.Quality.Should().BeInRange(0, 50); + } + + [Fact] + public void AC008_PreservesExistingProductBehaviorInMixedInventory() + { + var service = new ItemMaturationService(); + var items = new[] + { + new Item { Name = "Mature Cheese", Quality = 10, SellIn = 5 }, + new Item { Name = "Elixir of the Mongoose", Quality = 10, SellIn = 5 }, + new Item { Name = "Aged Brie", Quality = 10, SellIn = 2 }, + new Item { Name = "Backstage passes to a TAFKAL80ETC concert", Quality = 20, SellIn = 10 }, + new Item { Name = "Conjured Mana Cake", Quality = 10, SellIn = 5 }, + new Item { Name = "Sulfuras, Hand of Ragnaros", Quality = 80, SellIn = 0 }, + }; + + var results = new[] + { + service.Mature(items[0]), + service.Mature(items[1]), + service.Mature(items[2]), + service.Mature(items[3]), + service.Mature(items[4]), + service.Mature(items[5]), + }; + + results[0].Quality.Should().Be(11); + results[0].SellIn.Should().Be(4); + results[1].Quality.Should().Be(9); + results[1].SellIn.Should().Be(4); + results[2].Quality.Should().Be(11); + results[2].SellIn.Should().Be(1); + results[3].Quality.Should().Be(22); + results[3].SellIn.Should().Be(9); + results[4].Quality.Should().Be(8); + results[4].SellIn.Should().Be(4); + results[5].Quality.Should().Be(80); + results[5].SellIn.Should().Be(0); + } + + [Fact] + public void AC009_LeavesInputUnchangedOutsideDailyUpdate() + { + var service = new ItemMaturationService(); + var item = new Item + { + Name = "Mature Cheese", + Quality = 10, + SellIn = 5, + }; + + var result = service.Mature(item); + + item.Name.Should().Be("Mature Cheese"); + item.Quality.Should().Be(10); + item.SellIn.Should().Be(5); + result.Should().NotBeSameAs(item); + } + + [Fact] + public void AC013_PreservesOriginalCodeBehavior() + { + var items = new[] + { + new Item { Name = "Elixir of the Mongoose", Quality = 10, SellIn = 0 }, + new Item { Name = "Aged Brie", Quality = 10, SellIn = 0 }, + new Item { Name = "Backstage passes to a TAFKAL80ETC concert", Quality = 20, SellIn = 5 }, + new Item { Name = "Sulfuras, Hand of Ragnaros", Quality = 80, SellIn = 0 }, + }; + var legacyItems = new[] + { + new Item { Name = items[0].Name, Quality = items[0].Quality, SellIn = items[0].SellIn }, + new Item { Name = items[1].Name, Quality = items[1].Quality, SellIn = items[1].SellIn }, + new Item { Name = items[2].Name, Quality = items[2].Quality, SellIn = items[2].SellIn }, + new Item { Name = items[3].Name, Quality = items[3].Quality, SellIn = items[3].SellIn }, + }; + + new UpdateQualityService(legacyItems).UpdateQuality(); + var service = new ItemMaturationService(); + var results = new[] + { + service.Mature(items[0]), + service.Mature(items[1]), + service.Mature(items[2]), + service.Mature(items[3]), + }; + + for (var index = 0; index < items.Length; index++) + { + results[index].Quality.Should().Be(legacyItems[index].Quality); + results[index].SellIn.Should().Be(legacyItems[index].SellIn); + } + } +}