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 @@ -16,6 +16,8 @@ public sealed record Backstage : ItemKind;

public sealed record Conjured : ItemKind;

public sealed record PhoenixFeather : ItemKind;

public sealed record Sulfuras : ItemKind;

public static ItemKind FromName(string itemName)
Expand All @@ -28,8 +30,9 @@ public static ItemKind FromName(string itemName)
"Backstage" => new Backstage(),
"Conjured Mana Cake" => new Conjured(),
"Conjured" => new Conjured(),
"Phoenix Feather" => new PhoenixFeather(),
"Sulfuras, Hand of Ragnaros" => new Sulfuras(),
_ => new Standard(),
};
}
}
}
16 changes: 15 additions & 1 deletion src/Core/ProposedCode/Domain/ItemMaturingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public ItemState Mature(ItemKind kind, ItemState state)
ItemKind.AgedBrie => this.MatureAgedBrie(state),
ItemKind.Backstage => this.MatureBackstage(state),
ItemKind.Conjured => this.MatureConjured(state),
ItemKind.PhoenixFeather => this.MaturePhoenixFeather(state),
ItemKind.Sulfuras => state,
_ => this.MatureStandard(state),
};
Expand Down Expand Up @@ -77,4 +78,17 @@ private ItemState MatureConjured(ItemState state)

return new(newQuality, newSellIn);
}
}

private ItemState MaturePhoenixFeather(ItemState state)
{
var newQuality = state.Quality.Increase(2);
var newSellIn = state.SellIn.NextDay();

if (newSellIn.IsExpired)
{
newQuality = newQuality.Increase(2);
}

return new(newQuality, newSellIn);
}
}
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 @@ -17,6 +17,7 @@ public class ItemKindTests
[InlineData("Backstage", typeof(ItemKind.Backstage))]
[InlineData("Conjured Mana Cake", typeof(ItemKind.Conjured))]
[InlineData("Conjured", typeof(ItemKind.Conjured))]
[InlineData("Phoenix Feather", typeof(ItemKind.PhoenixFeather))]
[InlineData("Sulfuras, Hand of Ragnaros", typeof(ItemKind.Sulfuras))]
[InlineData("Elixir of the Mongoose", typeof(ItemKind.Standard))]
public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType)
Expand All @@ -25,4 +26,4 @@ public void FromName_MapsNamesToExpectedKinds(string itemName, Type expectedType

result.Should().BeOfType(expectedType);
}
}
}
16 changes: 15 additions & 1 deletion tests/Core.Tests/ProposedCode/Domain/ItemMaturingPolicyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ public void Mature_WhenKindIsConjured_FollowsExpectedRules(int quality, int sell
result.SellIn.Value.Should().Be(expectedSellIn);
}

[Theory]
[InlineData(10, 5, 12, 4)]
[InlineData(10, 0, 14, -1)]
[InlineData(49, 0, 50, -1)]
public void Mature_WhenKindIsPhoenixFeather_FollowsExpectedRules(int quality, int sellIn, int expectedQuality, int expectedSellIn)
{
var state = new ItemState(new Quality(quality), new SellIn(sellIn));

var result = this.policy.Mature(new ItemKind.PhoenixFeather(), state);

result.Quality.Value.Should().Be(expectedQuality);
result.SellIn.Value.Should().Be(expectedSellIn);
}

[Fact]
public void Mature_WhenKindIsSulfuras_PreservesProvidedState()
{
Expand All @@ -89,4 +103,4 @@ public void Mature_WhenKindIsSulfuras_PreservesProvidedState()

result.Should().Be(state);
}
}
}
4 changes: 3 additions & 1 deletion tests/Core.Tests/ProposedCode/ItemMaturationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ItemMaturationServiceTests
[InlineData("Conjured Mana Cake", 10, 5, 8, 4)]
[InlineData("Conjured", 10, 0, 6, -1)]
[InlineData("Sulfuras, Hand of Ragnaros", 80, 0, 80, 0)]
[InlineData("Phoenix Feather", 10, 5, 12, 4)]
public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int quality, int sellIn, int expectedQuality, int expectedSellIn)
{
var service = new ItemMaturationService();
Expand All @@ -32,7 +33,8 @@ public void Mature_UsesExpectedRulesForResolvedItemKinds(string name, int qualit

var result = service.Mature(item);

result.Name.Should().Be(name);
result.Quality.Should().Be(expectedQuality);
result.SellIn.Should().Be(expectedSellIn);
}
}
}
Loading