예제 #1
0
        public void SimpleVendingMachine_OnRequestToVendOfMoreThan25Cans_ThrowsException()
        {
            var paymentProvider = MockRepository.GenerateMock <IPaymentProvider>();

            paymentProvider.Expect(x => x.HasBalance()).Return(true);
            paymentProvider.Expect(x => x.IsValidPin(Arg <string> .Is.NotNull)).Return(true);
            paymentProvider.Expect(x => x.UpdateCardBalance(Arg <Payment> .Is.Anything)).Return(true);
            SimpleVendingMachine machine = new SimpleVendingMachine();

            for (int i = 0; i < 25; i++)
            {
                machine.SelectItem(ItemType.SoftDrink);
                machine.Vend(paymentProvider, "12345");
            }
            Assert.Throws <Exception>(() => machine.SelectItem(ItemType.SoftDrink));
        }
예제 #2
0
        public void SimpleVendingMachine_OnMultipleCashCardsLinkedtoSingleAccount_UpdatesAccountSuccessfully()
        {
            var account   = new Account("HSBC", "Avinash Jethani", new Payment(1000m, CurrencyEnum.GBP));
            var cashCard1 = new CashCard(account, "12345");
            var cashCard2 = new CashCard(account, "67890");
            IPaymentProvider paymentProvider1 = new CashCardPaymentProvider(cashCard1);
            IPaymentProvider paymentProvider2 = new CashCardPaymentProvider(cashCard2);

            SimpleVendingMachine machine = new SimpleVendingMachine();

            machine.SelectItem(ItemType.SoftDrink);
            machine.Vend(paymentProvider1, "12345");

            machine.SelectItem(ItemType.SoftDrink);
            machine.Vend(paymentProvider2, "67890");

            Assert.That(cashCard1.CurrentBalance, Is.EqualTo(new Payment(999m, CurrencyEnum.GBP)));
            Assert.That(cashCard2.CurrentBalance, Is.EqualTo(new Payment(999m, CurrencyEnum.GBP)));
            Assert.That(account.CurrentBalance, Is.EqualTo(new Payment(999m, CurrencyEnum.GBP)));
        }