Example #1
0
        public void Cannot_make_purchase_where_there_is_no_snack()
        {
            var    snackMachine   = new SnackMachine();
            Action actionDelegate = () => snackMachine.BuySnack(1);

            actionDelegate.Should().Throw <InvalidOperationException>();
        }
        public void CannotMakePurchaseWhenThereIsNoSnacks()
        {
            var snackMachine = new SnackMachine();

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void Cant_make_purchase_if_no_snacks()
        {
            var machine = new SnackMachine();

            Action action = () => machine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void BuySnack_ShouldThrowAnException_WhenThereIsNoSnacks()
        {
            var snackMachine = new SnackMachine();

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void cannot_make_purchase_when_there_are_no_snacks()
        {
            var snackMachine = new SnackMachine();

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void Calling_Buy_Snack_When_There_Are_No_Snacks_In_Position_Should_Throw_Error()
        {
            SnackMachine machine = new SnackMachine();

            Action action = () => machine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
Example #7
0
        public void Cannot_make_purchase_if_not_enough_money_inserted()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Chocolate, 1, 2m));
            Action actionDelegate = () => snackMachine.BuySnack(1);

            actionDelegate.Should().Throw <InvalidOperationException>();
        }
        public void Cannot_Call_Buy_Snack_With_An_Invalid_Position(int position)
        {
            SnackMachine machine = new SnackMachine();

            Action action = () => machine.BuySnack(position);


            action.Should().Throw <InvalidOperationException>();
        }
Example #9
0
 public IActionResult Buy()
 {
     _snackMachine.BuySnack();
     return(View("Index",
                 new SnackModel
     {
         Machine = _snackMachine, Message = "Congratulations you have just brought a delicious snack!"
     }));
 }
Example #10
0
        public void Cannot_make_purchase_when_there_is_no_snacks()
        {
            // Tenta comprar um lanche em um slot que não possui lanches carregados ainda.

            var snackMachine = new SnackMachine();

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void Cannot_buy_snack_if_not_enough_change()
        {
            var snackMachine = new SnackMachine();
            snackMachine.LoadSnacks(1, new SnackPile(Chocolate, 1, 0.5m));
            snackMachine.InsertMoney(Dollar);

            Action action = () => snackMachine.BuySnack(1);

            action.ShouldThrow<InvalidOperationException>();
        }
Example #12
0
        public void Cannot_make_purchase_if_not_enough_money_inserted()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Snack.Chocolate, 1, 2.0m));
            snackMachine.InsertMoney(Money.Dollar);

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void BuySnack_ShouldThrowAnException_WhenNotEnoughChange()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnack(1, new SnackPile(Soda, 1, 0.5m));
            snackMachine.InsertMoney(OneDollar);

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void Cannot_Make_Purchase_If_There_Isnt_Enough_Money_Inserted()
        {
            SnackMachine machine = new SnackMachine();

            machine.LoadSnacks(1, new SnackPile(new Snack("Delicious Snack"), 4, .75m));
            machine.InsertMoney(Money.Quarter);

            Action action = () => machine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
 private void BuySnack()
 {
     _snackMachine.BuySnack();
     using (ISession session = SessionFactory.OpenSession())
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.SaveOrUpdate(_snackMachine);
             transaction.Commit();
         }
     NotifyClient("You have bought a snack");
 }
Example #16
0
        public void CanNot_BuySnack_If_NotEnought_Money()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Snack.Chocolate, 1, 2m));
            snackMachine.InsertMoney(Money.OneDollar);

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void CannotMakePurchaseIfNotEnoughMoneyInserted()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Chocolate, 1, 2m));
            snackMachine.InsertMoney(Dollar);

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
Example #18
0
        public void MoneyInTransactionGoToMoneyInsideAfterPurchase()
        {
            var snackMachine = new SnackMachine();

            snackMachine.InsertMoney(OneEuro);
            snackMachine.InsertMoney(OneEuro);

            snackMachine.BuySnack();

            snackMachine.MoneyInTransaction.Should().Be(None);
            snackMachine.MoneyInside.Amount.Should().Be(2m);
        }
Example #19
0
        public void CanNot_BuySnack_when_There_is_no_snacks()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Snack.Chocolate, 0, 1m));
            snackMachine.InsertMoney(Money.OneDollar);
            snackMachine.InsertMoney(Money.OneDollar);

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <ArgumentException>();
        }
        public void After_purchase_change_is_returned()
        {
            var snackMachine = new SnackMachine();
            snackMachine.LoadSnacks(1, new SnackPile(Chocolate, 1, 0.5m));
            snackMachine.LoadMoney(TenCent * 10);

            snackMachine.InsertMoney(Dollar);
            snackMachine.BuySnack(1);

            snackMachine.MoneyInside.Amount.Should().Be(1.5m);
            snackMachine.MoneyInTransaction.Should().Be(0m);
        }
        public void Buysnack_trades_inserted_money_for_a_snack()
        {
            var snackMachine = new SnackMachine();
            snackMachine.LoadSnacks(1, new SnackPile(Chocolate, 10, 1m));

            snackMachine.InsertMoney(Dollar);
            snackMachine.BuySnack(1);

            snackMachine.MoneyInTransaction.Should().Be(0);
            snackMachine.MoneyInside.Amount.Should().Be(1m);
            snackMachine.GetSnackPile(1).Quantity.Should().Be(9);
        }
        public void MoneyInTransaction_GoesToMoneyInside_AfterPurchase()
        {
            var snackMachine = new SnackMachine();

            snackMachine.InsertMoney(Dollar);
            snackMachine.InsertMoney(Dollar);

            snackMachine.BuySnack();

            snackMachine.MoneyInTransaction.Should().Be(Empty);
            snackMachine.MoneyInside.Amount.Should().Be(2m);
        }
        public void Money_in_transaction_goes_to_money_inside_after_purchase()
        {
            var snackMachine = new SnackMachine();

            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);

            snackMachine.BuySnack();

            snackMachine.MoneyInside.Amount.Should().Be(2M);
            snackMachine.MoneyInTransaction.Amount.Should().Be(0M);
        }
        public void Purchase_moves_MoneyInTransaction_to_MoneyInside()
        {
            var snackMachine = new SnackMachine();

            snackMachine.InsertMoney(Dollar);
            snackMachine.InsertMoney(Dollar);

            snackMachine.BuySnack();

            snackMachine.MoneyInTransaction.Should().Be(None);
            snackMachine.MoneyInside.Amount.Should().Be(2m);
        }
Example #25
0
        public void Money_in_trans_goes_to_money_inside_afther_purchase()
        {
            var snackMachine = new SnackMachine();

            snackMachine.InsertMoney(Money.OneCent);
            snackMachine.InsertMoney(Money.OneCent);

            snackMachine.BuySnack(1);

            snackMachine.MoneyInTransaction.Should().Be(0);
            snackMachine.MoneyInside.Amount.Should().Be(0.02m);
        }
Example #26
0
        public void BuySnack_trades_inserted_money_for_a_snack()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new Snack("Some snack"), 10, 1m);
            snackMachine.InsertMoney(Money.Dollar);

            snackMachine.BuySnack(1);

            snackMachine.MoneyInTransaction.Should().Be(Money.None);
            snackMachine.MoneyInside.Amount.Should().Be(2m);
            snackMachine.Slots.Single(x => x.Position == 1).Quantity.Should().Be(9);
        }
Example #27
0
        public void Cannot_make_purchase_if_not_enough_money_inserted()
        {
            // Insere 1 dolar e tenta comprar um lanche que vale 2 dolares.

            var snackMachine = new SnackMachine();

            snackMachine.LoadSnacks(1, new SnackPile(Chocolate, 1, 2m));
            snackMachine.InsertMoney(Dollar);

            Action action = () => snackMachine.BuySnack(1);

            action.Should().Throw <InvalidOperationException>();
        }
        public void WhenBroughtSnack_ShouldMoneyInTransactionGoToMoneyInside()
        {
            // Arrange
            var snackMachine = new SnackMachine();

            snackMachine.InsertMoney(Money.Dollar);
            snackMachine.InsertMoney(Money.Dollar);
            // Act
            snackMachine.BuySnack();
            // Assert
            snackMachine.MoneyInTransaction.Should().Be(Money.None);
            snackMachine.MoneyInside?.Amount.Should().Be(2M);
        }
        public void BuildSnack_ShouldTradesInsertedMoneyForASnack()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnack(1, new SnackPile(Soda, 10, 1));
            snackMachine.InsertMoney(OneDollar);

            snackMachine.BuySnack(1);

            snackMachine.MoneyInside.Amount.Should().Be(1);
            snackMachine.MoneyInTransaction.Should().Be(0);
            snackMachine.GetSnackPile(1).Quantity.Should().Be(9);
        }
        public void BuySnack_ShouldReturnChangeAfterPurchase()
        {
            var snackMachine = new SnackMachine();

            snackMachine.LoadSnack(1, new SnackPile(Soda, 1, 0.5m));
            snackMachine.LoadMoney(TenCent * 10);
            snackMachine.InsertMoney(OneDollar);

            snackMachine.BuySnack(1);

            snackMachine.MoneyInside.Amount.Should().Be(1.5m);
            snackMachine.MoneyInTransaction.Should().Be(0);
        }