GildedRose-Refactoring-Kata/csharpcore/GildedRose/ItemBuilder.cs
Sarah Ashri d076fc9ba4 Add ItemBuilders hierarchy to enforce building valid items
Also updated unit tests:
- Added unit tests for the new ItemBuilders classes
- Refactored existing tests to use the new builders
2024-03-15 11:46:55 +10:00

24 lines
582 B
C#

using System;
namespace GildedRoseKata;
public class ItemBuilder(string name, int sellIn, int quality) : AbstractItemBuilder(name, sellIn, quality)
{
public override Item Build()
{
if (Quality < ItemQuality.MinQuality || Quality > ItemQuality.MaxQuality)
{
throw new ArgumentException("An item's quality must be >=0 and <=50");
}
if (ItemType.IsLegendaryItem(Name))
{
throw new ArgumentException("Legendary Items cannot be constructed using this builder");
}
return base.Build();
}
}