Example #1
0
        public void CanRackIsEmptyTest()
        {
            int maxInventory = 5;
            var cr           = new CanRack(maxInventory);

            cr.FillTheCanRack();

            foreach (Flavor f in Enum.GetValues(typeof(Flavor)))
            {
                for (int i = maxInventory; i >= -1; i--)
                {
                    // While amount is at least 1 soda, rack is not empty
                    if (i >= 1)
                    {
                        Assert.IsFalse(cr.IsEmpty(f));
                    }
                    else
                    {
                        Assert.IsTrue(cr.IsEmpty(f));
                    }

                    cr.RemoveACanOf(f);
                }
            }
        }
Example #2
0
        private void ejectcoke_Click(object sender, EventArgs e)
        {
            if (insertedCoin.ValueOf >= myPrice.PriceDecimal)
            {
                rack.RemoveACanOf(Flavor.REGULAR);
                insertedCoin.Transfer(mainCoinBox, myPrice.PriceDecimal, false);
                total.Text = string.Format("Total: {0:C}", insertedCoin.ValueOf);
                MessageBox.Show("Enjoy your soda!");
                ejectcoke.Enabled = !rack.IsEmpty(Flavor.REGULAR);
            }
            else
            {
                MessageBox.Show("Please insert the required amount");
            }

            updateVendViews();
        }
Example #3
0
        public void CanRackRemoveACanOfTest()
        {
            int maxInventory = 3;
            var cr           = new CanRack(maxInventory);

            cr.FillTheCanRack();
            foreach (Flavor f in Enum.GetValues(typeof(Flavor)))
            {
                for (int i = maxInventory; i >= -1; i--)
                {
                    // Check inventory is decremented by 1 for each iteration but never less than 0
                    cr.RemoveACanOf(f);
                    Assert.AreEqual(cr.Contents(f).Amount, Math.Max(0, i - 1));
                }
            }
        }
Example #4
0
        //Main method to eject cans of soda - provide with a flavor
        private void EjectCan(Flavor flavorToEject)
        {
            //Do we have enough money and do we have a can of this flavor
            if (tempBox.ValueOf >= sodaPrice.PriceDecimal && sodaRack.IsEmpty(flavorToEject) == false)
            {
                //Check if the change box can make change
                if (changeBox.CanMakeChange)
                {
                    //Make change using tempbox minus purchase price
                    decimal changeToReturn = tempBox.ValueOf - sodaPrice.PriceDecimal;

                    //If there is some change to return
                    if (changeToReturn > 0M)
                    {
                        //Remove the change from the changeBox
                        changeBox.Withdraw(changeToReturn);

                        //Notify the user
                        ReturnCoins(changeToReturn);
                    }
                }
                //Either way, update the the temp box indicator with zero
                textBoxTotalMoneyInserted.Text = "$0.00";

                //Transfer the temp box in to the main box
                tempBox.Transfer(changeBox);

                //Check the exact change light
                labelExactChangeRequired.Visible = !changeBox.CanMakeChange;

                //Eject the soda out to the user, and remove one soda from the rack
                sodaRack.RemoveACanOf(flavorToEject);

                //Turn off the eject button
                buttonRegular.Enabled = false;
                buttonOrange.Enabled  = false;
                buttonLemon.Enabled   = false;

                //Notify the customer they got a can of soda
                MessageBox.Show($"Here is your can of {flavorToEject}");
            }
        }