mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Adding Unittests to ensure logic of the code is correct
This commit is contained in:
parent
1d71dbc460
commit
137b503798
@ -6,12 +6,142 @@ namespace csharpcore
|
|||||||
public class GildedRoseTest
|
public class GildedRoseTest
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void foo()
|
public void UpdateQuality_NoItems_YieldNoException()
|
||||||
{
|
{
|
||||||
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
|
IList<Item> items = new List<Item> { };
|
||||||
GildedRose app = new GildedRose(Items);
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
app.UpdateQuality();
|
app.UpdateQuality();
|
||||||
Assert.Equal("fixme", Items[0].Name);
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void UpdateQuality_SulfuraItem_Unchanged()
|
||||||
|
{
|
||||||
|
IList<Item> items = new List<Item> { new Item { Name = "Sulfuras, Hand of Ragnaros", SellIn = 10, Quality = 80 } };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.UpdateQuality();
|
||||||
|
|
||||||
|
Assert.Equal(80, items[0].Quality);
|
||||||
|
Assert.Equal(10, items[0].SellIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(7, 7, 8)]
|
||||||
|
[InlineData(0, 7, 8)] // Issue with Aged Brie that increase Quality twice as fast after SellIn, correct ?
|
||||||
|
public void UpdateQuality_AgedBrie_QualityIncreases(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
|
{
|
||||||
|
IList<Item> items = new List<Item> { new Item { Name = "Aged Brie", SellIn = beforeSellIn, Quality = beforeQuality } };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.UpdateQuality();
|
||||||
|
|
||||||
|
Assert.Equal(afterQuality, items[0].Quality);
|
||||||
|
Assert.Equal(beforeSellIn - 1, items[0].SellIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(7, 50, 50)]
|
||||||
|
[InlineData(0, 50, 50)]
|
||||||
|
public void UpdateQuality_AgedBrieMaxQuality_QualityToppedAtFifty(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
|
{
|
||||||
|
IList<Item> items = new List<Item> { new Item { Name = "Aged Brie", SellIn = beforeSellIn, Quality = beforeQuality } };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.UpdateQuality();
|
||||||
|
|
||||||
|
Assert.Equal(afterQuality, items[0].Quality);
|
||||||
|
Assert.Equal(beforeSellIn - 1, items[0].SellIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(11, 7, 8)]
|
||||||
|
[InlineData(10, 7, 9)]
|
||||||
|
[InlineData(5, 7, 10)]
|
||||||
|
public void UpdateQuality_BackStagePass_QualityIncreases(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
|
{
|
||||||
|
IList<Item> items = new List<Item> {
|
||||||
|
new Item {
|
||||||
|
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||||
|
SellIn = beforeSellIn,
|
||||||
|
Quality = beforeQuality
|
||||||
|
}
|
||||||
|
};
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.UpdateQuality();
|
||||||
|
|
||||||
|
Assert.Equal(afterQuality, items[0].Quality);
|
||||||
|
Assert.Equal(beforeSellIn-1, items[0].SellIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0, 7, 0)]
|
||||||
|
[InlineData(0, 50, 0)]
|
||||||
|
public void UpdateQuality_BackStagePassAfterConcert_QualityZeroed(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
|
{
|
||||||
|
IList<Item> items = new List<Item> {
|
||||||
|
new Item {
|
||||||
|
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||||
|
SellIn = beforeSellIn,
|
||||||
|
Quality = beforeQuality
|
||||||
|
}
|
||||||
|
};
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.UpdateQuality();
|
||||||
|
|
||||||
|
Assert.Equal(afterQuality, items[0].Quality);
|
||||||
|
Assert.Equal(beforeSellIn - 1, items[0].SellIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(11, 50, 50)]
|
||||||
|
[InlineData(10, 50, 50)]
|
||||||
|
[InlineData(5, 50, 50)]
|
||||||
|
public void UpdateQuality_BackStagePassMaxQuality_QualityToppedAtFifty(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
|
{
|
||||||
|
IList<Item> items = new List<Item> {
|
||||||
|
new Item {
|
||||||
|
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||||
|
SellIn = beforeSellIn,
|
||||||
|
Quality = beforeQuality
|
||||||
|
}
|
||||||
|
};
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.UpdateQuality();
|
||||||
|
|
||||||
|
Assert.Equal(afterQuality, items[0].Quality);
|
||||||
|
Assert.Equal(beforeSellIn - 1, items[0].SellIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(7, 10, 9)]
|
||||||
|
[InlineData(0, 10, 8)]
|
||||||
|
public void UpdateQuality_MiscelaniousItem_QualityDecreases(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
|
{
|
||||||
|
IList<Item> items = new List<Item> { new Item { Name = "Wooden Sword", SellIn = beforeSellIn, Quality = beforeQuality } };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.UpdateQuality();
|
||||||
|
|
||||||
|
Assert.Equal(afterQuality, items[0].Quality);
|
||||||
|
Assert.Equal(beforeSellIn - 1, items[0].SellIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(7, 0, 0)]
|
||||||
|
[InlineData(0, 0, 0)]
|
||||||
|
public void UpdateQuality_MiscelaniousItemMinQuality_QualityCannotGoNegative(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
|
{
|
||||||
|
IList<Item> items = new List<Item> { new Item { Name = "Leeroy Jenkins Trinket", SellIn = beforeSellIn, Quality = beforeQuality } };
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
|
app.UpdateQuality();
|
||||||
|
|
||||||
|
Assert.Equal(afterQuality, items[0].Quality);
|
||||||
|
Assert.Equal(beforeSellIn - 1, items[0].SellIn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user