コード例 #1
0
        public void AddInventory_AddingNewSoda_ReturnsTrue()
        {
            // Arrange
            var newSodaName     = "solo";
            var newSodaPrice    = 15;
            var newSodaQuantity = 10;

            var newSoda = new Soda(newSodaName, newSodaPrice, newSodaQuantity);

            // Act
            var result     = _storageService.AddInventory(newSoda);
            var storedSoda = _storageService.GetSoda(newSodaName);

            // Assert
            Assert.IsTrue(result);
            Assert.IsTrue(storedSoda.Name == newSodaName);
            Assert.IsTrue(storedSoda.Price == newSodaPrice);
            Assert.IsTrue(storedSoda.Quantity == newSodaQuantity);
        }
コード例 #2
0
        //Admin commands
        private void Admin()
        {
            //Add to inventory
            Console.WriteLine("\n\nAvailable commands for Admin:");
            Console.WriteLine("1. Show inventory");
            Console.WriteLine("2. Add new soda");
            Console.WriteLine("3. Change price of soda");
            Console.WriteLine("4. Add quantity of soda");
            Console.WriteLine("Hit return to go back");
            var adminInput = Console.ReadLine();

            if (adminInput.StartsWith("1"))
            {
                ShowInventory();
                Admin();
            }

            if (adminInput.StartsWith("2"))
            {
                Console.WriteLine("Name of soda:");
                var sodaName     = Console.ReadLine();
                var sodaPrice    = CheckForValidNumber("Price of soda (only valid numbers, greater than 0):");
                var sodaQuantity = CheckForValidNumber("Quantity of soda (only valid numbers, greater than 0):");

                var soda = new Soda(sodaName, sodaPrice, sodaQuantity);
                if (_storageService.AddInventory(soda))
                {
                    Console.WriteLine("Soda {0} was added", soda.Name);
                }
                else
                {
                    Console.WriteLine("Soda {0} could not be added", soda.Name);
                }
                Admin();
            }

            if (adminInput.StartsWith("3"))
            {
                Console.WriteLine("Name of soda:");
                var sodaName = Console.ReadLine();

                var soda = _storageService.GetSoda(sodaName);

                if (soda != null)
                {
                    var sodaPrice = CheckForValidNumber("New price (only valid numbers, greater than 0):");

                    Console.WriteLine(soda.ChangePrice(sodaPrice));
                }
                else
                {
                    Console.WriteLine("No such soda");
                }
                Admin();
            }

            if (adminInput.StartsWith("4"))
            {
                Console.WriteLine("Name of soda:");
                var sodaName = Console.ReadLine();
                var soda     = _storageService.GetSoda(sodaName);

                if (soda != null)
                {
                    var sodaQuantity = CheckForValidNumber("Add amaount (only valid numbers, greater than 0):");

                    Console.WriteLine(soda.AddQuantity(sodaQuantity));
                }
                else
                {
                    Console.WriteLine("No such soda");
                }
                Admin();
            }
        }