Ejemplo n.º 1
0
        public void RemoveAllChangeItem()
        {
            VendingMachine machine = new GreedyVendingMachine();
            machine.Add
            (
                Change.TenPence(5),
                Change.TwentyPence(1)
            );

            int preBalance = machine.Balance.TotalValue();

            // Take out 20p and make sure the balance is right
            machine.Remove(Change.TenPence(5));
            Assert.AreEqual(machine.Balance.TotalValue(), preBalance - 50);

            // There shouldn't be any 10p items in the machine
            Assert.IsFalse(machine.Balance.Any(c => c.Denomination == 10));
        }
Ejemplo n.º 2
0
        public void RemoveChangeItem_DoesNotExist()
        {
            VendingMachine machine = new GreedyVendingMachine();
            machine.Add
            (
                Change.TenPence(5),
                Change.TwentyPence(1)
            );

            // Take out 5p. This isn't in the machine, so should fail
            machine.Remove(Change.FivePence(1));
        }
Ejemplo n.º 3
0
        public void RemoveChangeItem()
        {
            VendingMachine machine = new GreedyVendingMachine();
            machine.Add
            (
                Change.TenPence(5),
                Change.TwentyPence(1)
            );

            int preBalance = machine.Balance.TotalValue();

            // Take out 20p and make sure the balance is right
            machine.Remove(Change.TenPence(2));
            Assert.AreEqual(machine.Balance.TotalValue(), preBalance - 20);
        }
Ejemplo n.º 4
0
        public void RemoveChangeItem_TooManySpecified()
        {
            VendingMachine machine = new GreedyVendingMachine();
            machine.Add
            (
                Change.TenPence(5),
                Change.TwentyPence(1)
            );

            // Take out 6 x 10p. That's more than is in the machine, so should fail
            machine.Remove(Change.TenPence(6));
        }
Ejemplo n.º 5
0
        public void RemoveChangeItem_Rollback()
        {
            VendingMachine machine = new GreedyVendingMachine();
            machine.Add
            (
                Change.TenPence(5),
                Change.TwentyPence(3),
                Change.FiftyPence(1)
            );

            int preBalance = machine.Balance.TotalValue();

            Change[] changeToRemove =
            {
                Change.FiftyPence(1),
                Change.TwentyPence(4)
            };

            bool caughtException = false;

            try
            {
                machine.Remove(changeToRemove);
            }
            catch(ArgumentException)
            {
                caughtException = true;
            }

            Assert.IsTrue(caughtException);

            // The balance should be the same
            Assert.AreEqual(preBalance, machine.Balance.TotalValue());

            // And the coins should be the same
            Assert.AreEqual(3, machine.Balance.Count());

            Assert.IsTrue(machine.Balance.FirstOrDefault(c => c.Denomination == 10 && c.Quantity == 5) != null);
            Assert.IsTrue(machine.Balance.FirstOrDefault(c => c.Denomination == 20 && c.Quantity == 3) != null);
            Assert.IsTrue(machine.Balance.FirstOrDefault(c => c.Denomination == 50 && c.Quantity == 1) != null);
        }