Beispiel #1
0
        public void SimpleVendingMachine_OnRequestToVendWithLessThan50ponCard_ThrowsException()
        {
            var paymentProvider = MockRepository.GenerateMock <IPaymentProvider>();

            paymentProvider.Expect(x => x.HasBalance()).Return(false);
            SimpleVendingMachine machine = new SimpleVendingMachine();

            Assert.Throws <Exception>(() => machine.Vend(paymentProvider, "12345"));
        }
Beispiel #2
0
        public void SimpleVendingMachine_OnRequestToVendWithInvalidPin_ThrowsException()
        {
            var paymentProvider = MockRepository.GenerateMock <IPaymentProvider>();

            paymentProvider.Expect(
                //x => x.HasBalance(Arg<Payment>.Matches(y => y.Amount < .50m && y.Currency == CurrencyEnum.GBP)))
                x => x.HasBalance())
            .Return(true);
            paymentProvider.Expect(x => x.IsValidPin(Arg <string> .Is.NotNull)).Return(false);
            SimpleVendingMachine machine = new SimpleVendingMachine();

            Assert.Throws <Exception>(() => machine.Vend(paymentProvider, "12345"));
        }
Beispiel #3
0
        public void SimpleVendingMachine_OnVend_CallsUpdatesCardBalance()
        {
            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.NotNull)).Return(true);
            SimpleVendingMachine machine = new SimpleVendingMachine();

            machine.State = new CardInsertedState(machine);
            machine.Vend(paymentProvider, "12345");

            paymentProvider.VerifyAllExpectations();
        }
Beispiel #4
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));
        }
Beispiel #5
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)));
        }
 public EmptyState(SimpleVendingMachine machine)
 {
 }
Beispiel #7
0
 public CanVendingState(SimpleVendingMachine _vendingMachine)
 {
     this._vendingMachine = _vendingMachine;
 }
Beispiel #8
0
 public ItemSelectedState(SimpleVendingMachine vendingMachine)
 {
     _vendingMachine = vendingMachine;
 }
 public CardInsertedState(SimpleVendingMachine vendingMachine)
 {
     this._vendingMachine = vendingMachine;
 }