Exemplo n.º 1
0
        private void ProcessInput(string name, Money tender)
        {
            ProductAndChange pac = vm.buy(name, tender);

            if (pac.Result == ResultEnum.Ok)
            {
                Console.WriteLine("Enjoy!");
                Console.WriteLine("Change:" + pac.Change);
            }
            else
            {
                Console.WriteLine(pac.Message);
            }
        }
Exemplo n.º 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.");
        }
Exemplo n.º 3
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.");
        }
Exemplo n.º 4
0
        public void Buy_CannotGiveChange()
        {
            IVendingMachine vm = SampleVendingMachine_LimitedFloat();

            Money tendered = new Money();

            tendered.Add(DenominationEnum.TwoEuro, 2);

            decimal expectedFloatAfterSale = vm.getFloat().Total;
            decimal expectedChange         = tendered.Total - fanta.Price;

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

            Assert.IsNotNull(pac);
            Assert.AreEqual(ResultEnum.NoChange, pac.Result, "Result incorrect. Product expected.");
            Assert.IsFalse(String.IsNullOrEmpty(pac.Message), "Message incorrect. Message expected.");
            Assert.AreEqual(1, vm.countProduct(fanta.Name), "Product quantity not decremented after sale.");
            Assert.AreEqual(expectedFloatAfterSale, vm.getFloat().Total, "The money in the machine after the sale is incorrect.");
        }
Exemplo n.º 5
0
        public void Buy_NoChangeRequired()
        {
            IVendingMachine vm = SampleVendingMachine_FullFloat();

            //23 x 10cents
            Money tendered = new Money();

            tendered.Add(DenominationEnum.TenCents, 23);

            decimal expectedFloatAfterSale = vm.getFloat().Total + fanta.Price;

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

            Assert.IsNotNull(pac);
            Assert.AreEqual(ResultEnum.Ok, pac.Result, "Result incorrect. Product expected.");
            Assert.IsTrue(String.IsNullOrEmpty(pac.Message), "Message incorrect. No message expected.");
            Assert.AreEqual(fanta, pac.Product, "Product incorrect. Fanta expected.");
            Assert.AreEqual(0.0M, pac.Change.Total, "Change incorrect.");
            Assert.AreEqual(0, vm.countProduct(fanta.Name), "Product quantity incorrect. Product quantity not decremented after sale.");
            Assert.AreEqual(expectedFloatAfterSale, vm.getFloat().Total, "Float incorrect. The float after the sale is incorrect.");
        }