public void TestAddingMoney_Expect_MoneyAddedCorrectly()
        {
            var coffeeInput = new CoffeeInputModel {
                Increment = 0.25
            };

            var amount = _vmSvc.AddMoney(coffeeInput);

            Assert.AreEqual(amount, 0.25);
        }
        public void TestDispensingChange_Expect_AmountDispensedCorrectly()
        {
            var coffeeInput = new CoffeeInputModel {
                Increment = 10.00
            };

            var initialAmount = _vmSvc.AddMoney(coffeeInput);

            Assert.AreEqual(initialAmount, 10.00);

            var remainingAmount = _vmSvc.DispenseChange();

            Assert.AreEqual(remainingAmount, 10.00);
        }
        public void TestDispensingCoffee_Expect_CoffeeDispensedCorrectly()
        {
            AddCoffee();

            var coffeeInput = new CoffeeInputModel {
                Increment = 4.00
            };

            var initialAmount = _vmSvc.AddMoney(coffeeInput);

            Assert.AreEqual(initialAmount, 4.00);

            var viewModel = _vmSvc.DispenseCoffee();

            Assert.AreEqual(viewModel.HasError, false);
        }
        public void Setup()
        {
            var dataSvc = new InMemoryDataStoreService();

            _vmSvc = new VendingMachineService(dataSvc);

            _viewModel = _vmSvc.SetViewModel();

            _inputModel = new CoffeeInputModel
            {
                Cost     = 2.00,
                Size     = Size.Medium,
                Sugars   = 2,
                Creamers = 3,
            };
        }
        /// <inheritdoc />
        /// <summary>
        /// method to add coffee by performing the following steps:
        /// 1) add the cost for the number of sugars chosen by the user
        /// 2) add the cost for the number of creamers chose by the user
        /// 3) create the coffee item and set all the necessary values
        /// 4) if the static variable for coffee list doesn't exist yet, create it
        /// 5) add the new coffee item to the list
        /// 6) return the coffee item list
        /// </summary>
        /// <param name="inputModel">contains all the necessary user information to
        /// create a coffee item</param>
        /// <returns></returns>
        public IList <CoffeeModel> AddCoffee(CoffeeInputModel inputModel)
        {
            inputModel.Cost += inputModel.Sugars * 0.25;

            inputModel.Cost += inputModel.Creamers * 0.50;

            var coffee = new CoffeeModel
            {
                Cost        = inputModel.Cost,
                Size        = inputModel.Size,
                DisplaySize = inputModel.Size.ToString(),
                Sugars      = inputModel.Sugars,
                Creamers    = inputModel.Creamers
            };

            if (_coffeeList == null)
            {
                _coffeeList = new List <CoffeeModel>();
            }

            _coffeeList.Add(coffee);

            return(_coffeeList);
        }
Beispiel #6
0
        public JsonResult AddCoffee(CoffeeInputModel inputModel)
        {
            var data = _vmSvc.AddCoffee(inputModel);

            return(Json(data));
        }
        /// <inheritdoc />
        /// <summary>
        /// method simply takes the increment value, and adds it to the remaining balance
        /// </summary>
        /// <param name="inputModel">contains the necessary "increment" value</param>
        /// <returns>the new remaining balance amount</returns>
        public double AddMoney(CoffeeInputModel inputModel)
        {
            _model.RemainingAmount += inputModel.Increment;

            return(_model.RemainingAmount);
        }