Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Core/ProposedCode/Domain/ItemKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public sealed record Conjured : ItemKind;

public sealed record Sulfuras : ItemKind;

public sealed record CustomItem : ItemKind;

public static ItemKind FromName(string itemName)
{
return itemName switch
Expand All @@ -29,7 +31,8 @@ public static ItemKind FromName(string itemName)
"Conjured Mana Cake" => new Conjured(),
"Conjured" => new Conjured(),
"Sulfuras, Hand of Ragnaros" => new Sulfuras(),
"Custom item" => new CustomItem(),
_ => new Standard(),
};
}
}
}
3 changes: 2 additions & 1 deletion tests/Core.Tests/ProposedCode/Domain/ItemKindTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ public class ItemKindTests
[InlineData("Conjured Mana Cake", typeof(ItemKind.Conjured))]
[InlineData("Conjured", typeof(ItemKind.Conjured))]
[InlineData("Sulfuras, Hand of Ragnaros", typeof(ItemKind.Sulfuras))]
[InlineData("Custom item", typeof(ItemKind.CustomItem))]
[InlineData("Elixir of the Mongoose", typeof(ItemKind.Standard))]
public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType)
{
var result = ItemKind.FromName(itemName);

result.Should().BeOfType(expectedType);
}
}
}
33 changes: 32 additions & 1 deletion tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,35 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit
result.Quality.Should().Be(expectedQuality);
result.SellIn.Should().Be(expectedSellIn);
}
}

[Fact]
public void Mature_UsesInjectedPolicyForCustomItemAndPreservesItemName()
{
const string itemName = "Custom item";
var service = new ItemMaturationService(new CustomItemMaturingPolicy());
var item = new Item
{
Name = itemName,
Quality = 10,
SellIn = 5,
};

var result = service.Mature(item);

result.Name.Should().Be(itemName);
result.Quality.Should().Be(17);
result.SellIn.Should().Be(3);
}

private sealed class CustomItemMaturingPolicy : IMaturingPolicy
{
public ItemState Mature(ItemKind kind, ItemState state)
{
return kind switch
{
ItemKind.CustomItem => new ItemState(new Quality(17), new SellIn(3)),
_ => state,
};
}
}
}
Loading