gilded-rose-dotnet-core/test/BasicItemTest.cs

55 lines
1.8 KiB
C#
Raw Permalink Normal View History

2020-08-31 19:36:58 +00:00
using Xunit;
using System.Collections.Generic;
namespace csharpcore
{
public class BasicItemTest
{
[Fact]
public void ShouldUpdateQuality()
{
const int startSellIn = 31;
const int startQuality = 20;
var item = new Item {Name = "+5 Dexterity Vest", SellIn = startSellIn, Quality = startQuality};
var app = new GildedRose(new List<Item> {item});
app.UpdateQuality();
Assert.Equal("+5 Dexterity Vest", item.Name);
Assert.Equal(startSellIn - 1, item.SellIn);
Assert.Equal(startQuality - 1, item.Quality);
}
[Theory]
[InlineData(1, 1)]
[InlineData(0, 2)] /* Once the sell by date has passed, Quality degrades twice as fast. */
[InlineData(-1, 2)] /* Once the sell by date has passed, Quality degrades twice as fast. */
public void ShouldDecrementQualityAccordingToSellInValue(int sellIn, int expectedDecrement)
{
const int startQuality = 20;
var item = new Item {Name = "+5 Dexterity Vest", SellIn = sellIn, Quality = startQuality};
var app = new GildedRose(new List<Item> {item});
app.UpdateQuality();
Assert.Equal(startQuality - expectedDecrement, item.Quality);
}
[Fact]
public void ShouldNotSetDecrementQualityToNegativeValue()
{
const int startQuality = 0;
var item = new Item {Name = "+5 Dexterity Vest", SellIn = 1, Quality = startQuality};
var app = new GildedRose(new List<Item> {item});
app.UpdateQuality();
app.UpdateQuality();
app.UpdateQuality();
app.UpdateQuality();
Assert.Equal(0, item.Quality);
}
}
}