Ejemplo n.º 1
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.");
        }
Ejemplo n.º 2
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.");
        }