예제 #1
0
        public Program()
        {
            ca = new ChangeAlgorithm();
            vm = new TheVendingMachine(ca);

            FillFloat();

            StockMachine();
        }
예제 #2
0
        public void Buy_ProductNotAvailable()
        {
            IVendingMachine vm = new TheVendingMachine(changeAlgorithm);

            Product selection = new Product("Fanta", 1.1M);
            Money   moneyIn   = new Money();

            moneyIn.Add(DenominationEnum.TwoEuro, 1);

            ProductAndChange pac = vm.buy(selection.Name, moneyIn);

            Assert.IsNotNull(pac);
            Assert.AreEqual(ResultEnum.NoProduct, pac.Result, "Result incorrect. No product expected.");
            Assert.IsFalse(String.IsNullOrEmpty(pac.Message), "Message incorrect.");
        }
예제 #3
0
        /// <summary>
        /// Creates a sample vending machine with a float that has few coins and a single product.
        /// </summary>
        /// <returns></returns>
        private IVendingMachine SampleVendingMachine_LimitedFloat()
        {
            IVendingMachine vm = new TheVendingMachine(changeAlgorithm);

            //fill the vending machine with products
            fanta = new Product("Fanta", 2.3M);
            vm.addProduct(fanta, 1);

            //fill the vending machine with change
            Money moneyFloat = new Money();

            moneyFloat.Add(DenominationEnum.FiftyCents, 1);
            vm.addToFloat(moneyFloat);

            return(vm);
        }
예제 #4
0
        public void Buy_NotEnoughMoney()
        {
            IVendingMachine vm = new TheVendingMachine(changeAlgorithm);

            Product selection = new Product("Fanta", 1.1M);

            vm.addProduct(selection, 1);
            Money tendered = new Money();

            tendered.Add(DenominationEnum.TenCents, 1);

            ProductAndChange pac = vm.buy(selection.Name, tendered);

            Assert.IsNotNull(pac);
            Assert.AreEqual(ResultEnum.NotEnoughMoney, pac.Result, "Result incorrect. Not enough money expected.");
            Assert.IsFalse(String.IsNullOrEmpty(pac.Message), "Message incorrect.");
        }