Beispiel #1
0
        public void conjuredItemsdegradeInQualityTwiceAsFastAsNormalItems()
        {
            // Arrange
            var timer = new MeasureTime();

            var currentStock = new List <IStockable>();

            currentStock.Add(new ConjuredItem {
                Name = "Conjured", Sellin = 5, Quality = 50, Timer = timer
            });


            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new ConjuredItem {
                Name = "Conjured", Sellin = 4, Quality = 48
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);

            // Act
            timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #2
0
        public void backStagePassesIncreaseBy3With5DaysOrLess()
        {
            // Arrange
            var timer = new MeasureTime();

            var currentStock = new List <IStockable>();

            currentStock.Add(new BackStagePass {
                Name = "Backstage Passes", Sellin = 6, Quality = 40, Timer = timer
            });


            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new BackStagePass {
                Name = "Backstage Passes", Sellin = 5, Quality = 43
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);

            // Act
            timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #3
0
        public void backStagePassesDropToZeroAfterConcert()
        {
            // Arrange
            var timer = new MeasureTime();

            var currentStock = new List <IStockable>();

            currentStock.Add(new BackStagePass {
                Name = "Backstage Passes", Sellin = 1, Quality = 50, Timer = timer
            });


            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new BackStagePass {
                Name = "Backstage Passes", Sellin = 0, Quality = 0
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);

            // Act
            timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #4
0
        public void qualityOfStandardItemNeverMoreThan50WhenSetFirstTime()
        {
            // Arrange
            var timer = new MeasureTime();

            var currentStock = new List <IStockable>();

            currentStock.Add(new StandardItem {
                Name = "Normal Item", Sellin = 2, Quality = 51, Timer = timer
            });

            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new StandardItem {
                Name = "Normal Item", Sellin = 1, Quality = 50
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);

            // Act
            timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #5
0
        public void sulfurasNeverDecreasesInQuality()
        {
            // Arrange
            var timer = new MeasureTime();

            var currentStock = new List <IStockable>();

            currentStock.Add(new LegendaryItem {
                Name = "Sulfuras", Sellin = 2, Quality = 50, Timer = timer
            });


            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new LegendaryItem {
                Name = "Sulfuras", Sellin = 2, Quality = 50
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);

            // Act
            timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #6
0
        public void agedBrieIncreasesInQualityWithAge()
        {
            // Arrange
            var timer = new MeasureTime();

            var currentStock = new List <IStockable>();

            currentStock.Add(new AgedBrie {
                Name = "Aged Brie", Sellin = 2, Quality = 2, Timer = timer
            });


            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new AgedBrie {
                Name = "Aged Brie", Sellin = 1, Quality = 3
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);

            // Act
            timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #7
0
        public void itemWithNegativeQualityIsSetToZero()
        {
            // Arrange
            var timer = new MeasureTime();

            var currentStock = new List <IStockable>();

            currentStock.Add(new StandardItem {
                Name = "Normal Item", Sellin = 1, Quality = -1, Timer = timer
            });

            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new StandardItem {
                Name = "Normal Item", Sellin = 0, Quality = 0
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);

            // Act
            timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #8
0
        public void standardItemSellinAndQualityDecreaseOnDayPassedAndSellByPassed()
        {
            // Arrange
            var timer = new MeasureTime();

            var currentStock = new List <IStockable>();

            currentStock.Add(new StandardItem {
                Name = "Normal Item", Sellin = 1, Quality = 2, Timer = timer
            });


            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new StandardItem {
                Name = "Normal Item", Sellin = 0, Quality = 0
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);

            // Act
            timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #9
0
        public void RetrieveUpdatedStockAfter1Day()
        {
            // Arrange
            var currentStock = new List <IStockable>();

            currentStock.Add(ItemFactory.getStock("Aged Brie", 1, 1));
            currentStock.Add(ItemFactory.getStock("Backstage Passes", -1, 2));
            currentStock.Add(ItemFactory.getStock("Backstage Passes", 9, 2));
            currentStock.Add(ItemFactory.getStock("Sulfuras", 2, 2));
            currentStock.Add(ItemFactory.getStock("Normal Item", -1, 55));
            currentStock.Add(ItemFactory.getStock("Normal Item", 2, 2));
            currentStock.Add(ItemFactory.getStock("INVALID ITEM", 2, 2));
            currentStock.Add(ItemFactory.getStock("Conjured", 2, 2));
            currentStock.Add(ItemFactory.getStock("Conjured", -1, 5));

            var expectedStockAfter1Day = new List <IStockable>();

            expectedStockAfter1Day.Add(new AgedBrie {
                Name = "Aged Brie", Sellin = 0, Quality = 2
            });
            expectedStockAfter1Day.Add(new BackStagePass {
                Name = "Backstage Passes", Sellin = -2, Quality = 0
            });
            expectedStockAfter1Day.Add(new BackStagePass {
                Name = "Backstage Passes", Sellin = 8, Quality = 4
            });
            expectedStockAfter1Day.Add(new LegendaryItem {
                Name = "Sulfuras", Sellin = 2, Quality = 2
            });
            expectedStockAfter1Day.Add(new StandardItem {
                Name = "Normal Item", Sellin = -2, Quality = 50
            });
            expectedStockAfter1Day.Add(new StandardItem {
                Name = "Normal Item", Sellin = 1, Quality = 1
            });
            expectedStockAfter1Day.Add(new NoSuchItem {
                Name = "NO SUCH ITEM"
            });
            expectedStockAfter1Day.Add(new ConjuredItem {
                Name = "Conjured", Sellin = 1, Quality = 0
            });
            expectedStockAfter1Day.Add(new ConjuredItem {
                Name = "Conjured", Sellin = -2, Quality = 1
            });

            var stockManager = new ManageStock();

            stockManager.AddStock(currentStock);



            // Act
            ItemFactory.timer.advanceDay();
            var finalStock = stockManager.GetStock();

            // Assert
            CollectionAssert.AreEqual(finalStock, expectedStockAfter1Day, new StockComparer());
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            var stockManager = new ManageStock();

            Console.WriteLine("Welcome to the Guilded Rose Stock Managmenet Program..  ");
            writeHelp();
            bool cont = true;

            while (cont)
            {
                string line = Console.ReadLine();
                switch (line.ToLower())
                {
                case "h":
                    writeHelp();
                    break;

                case "c":
                    cont = false;
                    break;

                case "a":
                    ItemFactory.timer.advanceDay();
                    Console.WriteLine("day advanced");
                    EnterCmd();
                    break;

                case "l":
                    var stock = stockManager.GetStock();
                    Console.WriteLine("Stock found : " + stock.Count);
                    foreach (var item in stock)
                    {
                        Console.WriteLine(item.writeStock());
                    }
                    break;

                default:
                    var list = line.Split(' ');
                    if (list.Length <= 0)
                    {
                        Console.WriteLine("Invalid stock structure - please re-enter");
                    }
                    else
                    {
                        string name = "";
                        int    sellin;
                        int    qual;
                        try
                        {
                            if (list.Length > 3)
                            {
                                // assume our title has a space or two in.
                                qual   = int.Parse(list[list.Length - 1]);
                                sellin = int.Parse(list[list.Length - 2]);
                                var sb = new StringBuilder();
                                for (var i = 0; i < list.Length - 2; i++)
                                {
                                    sb.AppendFormat("{0} ", list[i]);
                                }
                                name = sb.ToString().TrimEnd();
                            }
                            else
                            {
                                qual   = int.Parse(list[2]);
                                sellin = int.Parse(list[1]);
                                name   = list[0].TrimEnd();
                            }

                            stockManager.AddStock(ItemFactory.getStock(name, sellin, qual));
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Invalid stock structure - please re-enter");
                        }
                    }
                    break;
                }
                //if (cont) EnterCmd();
            }
            ;
        }