Last active
July 11, 2018 13:42
-
-
Save mjtordesillas/1f328c7d62d2a8ad5dc451dd19fe4092 to your computer and use it in GitHub Desktop.
Possible GildedRose C# Test Solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Xunit; | |
namespace KataGildedRose.Tests | |
{ | |
public class GildedRoseTest | |
{ | |
private const string BackstageName = "Backstage passes to a TAFKAL80ETC concert"; | |
private const string NormalItemName = "foo"; | |
private const string AgedBrieName = "Aged Brie"; | |
private const string SulfurasName = "Sulfuras, Hand of Ragnaros"; | |
private const int QualityChange = 1; | |
private const int NormalItemQuality = 5; | |
private const int MinimumQuality = 0; | |
private const int MaximumQuality = 50; | |
private const int SellInChange = 1; | |
private const int ExpiredSellIn = 0; | |
private const int NormalItemSellIn = 15; | |
private const int SellInIn5Days = 5; | |
private const int SellInIn10Days = 10; | |
[Fact] | |
public void SellIn_DecreasesEveryDay() { | |
VerifySellIn(NormalItemSellIn - SellInChange, NormalItem()); | |
} | |
[Fact] | |
public void Quality_DecreasesEveryDay() { | |
VerifyQuality(NormalItemQuality - QualityChange, NormalItem()); | |
} | |
[Fact] | |
public void Quality_DecreasesTwiceAsFast_OnceSellInHasPassed() { | |
VerifyQuality(NormalItemQuality - 2 * QualityChange, ExpiredItem()); | |
} | |
[Fact] | |
public void Quality_IsNeverNegative() { | |
VerifyQuality(MinimumQuality, ItemWithoutQuality()); | |
} | |
[Fact] | |
public void AgedBrie_IncreasesQuality() { | |
VerifyQuality(NormalItemQuality + QualityChange, AgedBrie()); | |
} | |
[Fact] | |
public void Item_NeverIncreaseQuality_WhenHasReachedTheMaximum() { | |
VerifyQuality(MaximumQuality, AgedBrieWithMaximumQuality()); | |
} | |
[Fact] | |
public void Sulfuras_NeverChanges_TheQuality() { | |
VerifyQuality(NormalItemQuality, Sulfuras()); | |
} | |
[Fact] | |
public void Sulfuras_NeverChanges_TheSellIn() { | |
VerifySellIn(NormalItemSellIn, Sulfuras()); | |
} | |
[Fact] | |
public void Backstage_IncreaseQuality() { | |
VerifyQuality(NormalItemQuality + QualityChange, Backstage()); | |
} | |
[Fact] | |
public void Backstage_IncreaseQualityBy2_WhenSellInIs10OrLess() { | |
VerifyQuality(NormalItemQuality + 2 * QualityChange, BackstageIn10Days()); | |
} | |
[Fact] | |
public void Backstage_IncreaseQualityBy3_WhenSellInIs5OrLess() { | |
VerifyQuality(NormalItemQuality + 3 * QualityChange, BackstageIn5Days()); | |
} | |
[Fact] | |
public void Backstage_DropsTo0Quality_AfterTheConcert() { | |
VerifyQuality(MinimumQuality, BackstageAfterTheConcert()); | |
} | |
[Fact] | |
public void AgedBrie_ExpiredGetsTheMaximumQuality_WhenHasOneLessThanMaximumQuality() { | |
Item item = new Item | |
{ | |
Name = AgedBrieName, | |
SellIn = ExpiredSellIn, | |
Quality = MaximumQuality - 1 | |
}; | |
VerifyQuality(MaximumQuality, item); | |
} | |
private void VerifySellIn(int expectedSellIn, Item item) { | |
GildedRose gildedRose = GildedRose(item); | |
gildedRose.UpdateQuality(); | |
AssertSellIn(expectedSellIn, gildedRose); | |
} | |
private void VerifyQuality(int expectedQuality, Item normalItem) { | |
GildedRose gildedRose = GildedRose(normalItem); | |
gildedRose.UpdateQuality(); | |
assertQuality(expectedQuality, gildedRose); | |
} | |
private GildedRose GildedRose(Item item) { | |
Item[] items = new Item[] { item }; | |
GildedRose app = new GildedRose(items); | |
return app; | |
} | |
private Item NormalItem() { | |
return ItemWithNormalSellInAndQuality(NormalItemName); | |
} | |
private Item ExpiredItem() { | |
return ItemWithNormalQuality(NormalItemName, ExpiredSellIn); | |
} | |
private Item ItemWithoutQuality() { | |
return new Item | |
{ | |
Name = NormalItemName, | |
SellIn = NormalItemSellIn, | |
Quality = MinimumQuality | |
}; | |
} | |
private Item AgedBrie() { | |
return ItemWithNormalSellInAndQuality(AgedBrieName); | |
} | |
private Item AgedBrieWithMaximumQuality() { | |
return new Item | |
{ | |
Name = AgedBrieName, | |
SellIn = NormalItemSellIn, | |
Quality = MaximumQuality | |
}; | |
} | |
private Item Sulfuras() { | |
return ItemWithNormalSellInAndQuality(SulfurasName); | |
} | |
private Item Backstage() { | |
return ItemWithNormalSellInAndQuality(BackstageName); | |
} | |
private Item BackstageIn10Days() { | |
return ItemWithNormalQuality(BackstageName, SellInIn10Days); | |
} | |
private Item BackstageIn5Days() { | |
return ItemWithNormalQuality(BackstageName, SellInIn5Days); | |
} | |
private Item BackstageAfterTheConcert() { | |
return ItemWithNormalQuality(BackstageName, ExpiredSellIn); | |
} | |
private Item ItemWithNormalSellInAndQuality(string name) { | |
return ItemWithNormalQuality(name, NormalItemSellIn); | |
} | |
private Item ItemWithNormalQuality(string name, int sellIn) { | |
return new Item { | |
Name = name, | |
SellIn = sellIn, | |
Quality = NormalItemQuality | |
}; | |
} | |
private void AssertSellIn(int expectedSellIn, GildedRose gildedRose) { | |
Assert.Equal(expectedSellIn, gildedRose.Items[0].SellIn); | |
} | |
private void assertQuality(int expectedQuality, GildedRose gildedRose) { | |
Assert.Equal(expectedQuality, gildedRose.Items[0].Quality); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment