static void Main(string[] args) { Console.WriteLine("****************************"); Console.WriteLine("Inventory Management System"); Console.WriteLine("****************************"); InventoryManagement inventoryManagement = new InventoryManagement(); Console.WriteLine("Inventory List"); EmptyLine(); Columns(); //Console.WriteLine(string.Format("{0,-20}{1,5}{2,10}", "Item", "SellIn", "Quality")); foreach (var inventory in inventoryManagement.Inventories.Value) { Console.WriteLine(string.Format("{0,-20}{1,5}{2,10}", inventory.Item.Name, inventory.SellIn, inventory.Quality)); } EndListLine(); bool valid = false; string value = ""; string exit = ""; do { Console.WriteLine(@"Enter 'DayEnd' to view end of the day results"); value = Console.ReadLine()?.ToLower(); valid = value == "dayend"; while (valid && exit != "exit") { inventoryManagement.Adjust(); EmptyLine(); Console.WriteLine("Updated Inventory List"); EmptyLine(); Columns();//Console.WriteLine(string.Format("{0,-20}{1,5}{2,10}", "Item", "SellIn", "Value")); foreach (var inventory in inventoryManagement.Inventories.Value) { Console.WriteLine(string.Format("{0,-20}{1,5}{2,10}", (!string.IsNullOrEmpty(inventory.Item.Error) && !string.IsNullOrWhiteSpace(inventory.Item.Error)) ? inventory.Item.Error : inventory.Item.Name, inventory.SellIn, inventory.Quality)); } EndListLine(); Console.WriteLine(@"Enter 'Exit' to close application"); exit = Console.ReadLine()?.ToLower(); } } while (!valid); }
public void BackStagePass_Item_Before_SellIn_Date_Greater_10() { InventoryManagement inventoryManagement = new InventoryManagement(); inventoryManagement.Inventories = new Lazy <IEnumerable <IInventory> >(() => { return(new List <IInventory>() { new Inventory() { Item = Repos.Items.FirstOrDefault(i => i.GetType() == typeof(BackstagePass)), SellIn = 12, Quality = 5 } }); }); inventoryManagement.Adjust(); var inventory = inventoryManagement.Inventories.Value.ElementAt(0); Assert.AreEqual(inventory.Quality, 6); Assert.AreEqual(inventory.SellIn, 11); }
public void Normal_Item_After_SellIn_Date_While_Negative_Quality() { InventoryManagement inventoryManagement = new InventoryManagement(); inventoryManagement.Inventories = new Lazy <IEnumerable <IInventory> >(() => { return(new List <IInventory>() { new Inventory() { Item = Repos.Items.FirstOrDefault(i => i.GetType() == typeof(Normal)), SellIn = -1, Quality = -4 } }); }); inventoryManagement.Adjust(); var inventory = inventoryManagement.Inventories.Value.ElementAt(0); Assert.AreEqual(inventory.Quality, 0); Assert.AreEqual(inventory.SellIn, -2); }
public void Sulfuras_Item_After_SellIn_Date_Over_50() { InventoryManagement inventoryManagement = new InventoryManagement(); inventoryManagement.Inventories = new Lazy <IEnumerable <IInventory> >(() => { return(new List <IInventory>() { new Inventory() { Item = Repos.Items.FirstOrDefault(i => i.GetType() == typeof(Sulfuras)), SellIn = -4, Quality = 55 } }); }); inventoryManagement.Adjust(); var inventory = inventoryManagement.Inventories.Value.ElementAt(0); Assert.AreEqual(inventory.Quality, 50); Assert.AreEqual(inventory.SellIn, -4); }
public void Legendary_Item_Before_SellIn_Date() { InventoryManagement inventoryManagement = new InventoryManagement(); inventoryManagement.Inventories = new Lazy <IEnumerable <IInventory> >(() => { return(new List <IInventory>() { new Inventory() { Item = Repos.Items.FirstOrDefault(i => i.GetType() == typeof(Sulfuras)), SellIn = 2, Quality = 5 } }); }); inventoryManagement.Adjust(); var inventory = inventoryManagement.Inventories.Value.ElementAt(0); Assert.AreEqual(inventory.Quality, 5); Assert.AreEqual(inventory.SellIn, 2); }