public List <Item> ParseLinesToItems(List <string> lines) { List <Item> items = new List <Item>(); foreach (string line in lines) { // Use regular expressions to extract the data Match itemNameMatch = Regex.Match(line, @"([a-zA-Z ])+"); if (!itemNameMatch.Success) { throw new InvalidOperationException(); } Item item; // Need to remove trailing space switch (itemNameMatch.Value.Trim()) { case "Normal Item": item = new Item(); break; case "Aged Brie": item = new AgedBrie(); break; case "Sulfuras": item = new Sulfuras(); break; case "Backstage passes": item = new BackstagePasses(); break; case "Conjured": item = new ConjuredItem(); break; default: item = new UnknownItem(); break; } // Match positive or negative digits Match sellInAndQualityMatch = Regex.Match(line, @"(-?\d+)"); if (!itemNameMatch.Success) { throw new InvalidOperationException(); } // SellIn value comes first item.SellIn = Int32.Parse(sellInAndQualityMatch.Value); sellInAndQualityMatch = sellInAndQualityMatch.NextMatch(); item.Quality = Int32.Parse(sellInAndQualityMatch.Value); items.Add(item); } return(items); }
public void UpdateQuality() { foreach (Item item in _items) { ShelveItem shelveItem; switch (item.Name) { case "Aged Brie": shelveItem = new AgingItem(item); break; case "Sulfuras, Hand of Ragnaros": shelveItem = new LegendaryItem(item); break; case "Backstage passes to a TAFKAL80ETC concert": shelveItem = new TicketItem(item); break; case "Conjured Mana Cake": shelveItem = new ConjuredItem(item); break; default: shelveItem = new ShelveItem(item); break; } shelveItem.UpdateItemQuality(); } }
public void Conjured_man_Cake_outdated() { var Items = new ConjuredItem("Conjured Mana Cake", -2, 10); Items.Update(); Assert.AreEqual("Conjured Mana Cake", Items.Name); Assert.AreEqual(-3, Items.SellIn); Assert.AreEqual(6, Items.Quality); }
public void Conjured_man_Cake() { var Items = new ConjuredItem("Conjured Mana Cake", 5, 3); Items.Update(); Assert.AreEqual("Conjured Mana Cake", Items.Name); Assert.AreEqual(4, Items.SellIn); Assert.AreEqual(1, Items.Quality); }