/**
         * Tells this delivery chute to deliver the indicated pop can. If the
         * delivery is successful, an "ItemDelivered" event is announced to its
         * listeners. If the successful delivery causes the chute to become full, a
         * "ChuteFull" event is announced to its listeners.
         */
        public void AcceptPopCan(PopCan popCan)
        {
            if (!this.Enabled)
            {
                throw new Exception("Delivery chute disabled");
            }

            if (this.Count >= this.Capacity)
            {
                throw new Exception("Delivery chute already full - cannot accept new pop can");
            }

            this.chute.Add(popCan);

            if (this.ItemDelivered != null)
            {
                this.ItemDelivered(this, new DeliverableEventArgs()
                {
                    Item = popCan
                });
            }

            if (this.Count >= this.Capacity)
            {
                if (this.ChuteFull != null)
                {
                    this.ChuteFull(this, new EventArgs());
                }
            }
        }
        /**
         * Adds the indicated pop can to this pop can rack if there is sufficient
         * space available. If the pop can is successfully added to this pop can
         * rack, a "PopCanAdded" event is announced to its listeners. If, as a result
         * of adding this pop can, this pop can rack has become full, a "PopCanRackFull"
         * event is announced to its listeners.
         *
         * @param popCan
         *            The pop can to be added.
         */
        public void AddPopCan(PopCan popCan)
        {
            if (!this.Enabled)
            {
                throw new Exception("Pop can rackdisabled");
            }

            if (this.Count >= this.Capacity)
            {
                throw new Exception("Pop can rack already full - cannot accept new pop can");
            }

            this.queue.Enqueue(popCan);

            if (this.PopCanAdded != null)
            {
                this.PopCanAdded(this, new PopCanEventArgs()
                {
                    PopCan = popCan
                });
            }

            if (this.Count >= this.Capacity)
            {
                if (this.PopCanRackFull != null)
                {
                    this.PopCanRackFull(this, new EventArgs());
                }
            }
        }
Example #3
0
        public List <PopCan> removePop(List <PopCan> searchIn, PopCan searchFor)
        {
            foreach (var item in searchIn)
            {
                if (((PopCan)item).Name == ((PopCan)searchFor).Name)
                {
                    searchIn.Remove(item);
                    break;
                }
            }

            return(searchIn);
        }
Example #4
0
        public bool containsPop(List <PopCan> searchIn, PopCan searchFor)
        {
            Boolean contains = false;

            foreach (var item in searchIn)
            {
                if (((PopCan)item).Name == ((PopCan)searchFor).Name)
                {
                    contains = true;
                    break;
                }
            }

            return(contains);
        }
Example #5
0
 // takes the expected delivery items and ensures that all
 // expected items are in the actual delivered items
 // returns true if expected items are there, false if not
 public Boolean checkDelivery(List <IDeliverable> expectedList, List <IDeliverable> itemsList)
 {
     foreach (var item in expectedList)
     {
         Boolean itemFound = false;
         if (item.GetType() == typeof(PopCan))
         {
             PopCan pop  = (PopCan)item;
             string name = pop.Name;
             foreach (var delivered in itemsList)
             {
                 if (delivered.GetType() == typeof(PopCan))
                 {
                     PopCan delPop     = (PopCan)delivered;
                     string delPopName = delPop.Name;
                     if (name.Equals(delPopName))
                     {
                         itemFound = true;
                         break;
                     }
                 }
             }
         }
         else
         {
             Coin coinItem = (Coin)item;
             int  coinVal  = coinItem.Value;
             foreach (var delivered in itemsList)
             {
                 if (delivered.GetType() == typeof(Coin))
                 {
                     Coin delCoin    = (Coin)delivered;
                     int  delCoinVal = delCoin.Value;
                     if (delCoinVal == coinVal)
                     {
                         itemFound = true;
                         break;
                     }
                 }
             }
         }
         if (!itemFound)
         {
             return(false);
         }
     }
     return(true);
 }
Example #6
0
 public void Initialize()
 {
     //VMF = new VendingMachineFactory();
     VMs     = new List <VendingMachine>();
     checker = new Checker();
     //delivered = new List<IDeliverable>();
     expected = new List <IDeliverable>();
     unaccountedForDelivery = new List <IDeliverable>();
     actualUnload           = new VendingMachineStoredContents();
     expectedUnload         = new VendingMachineStoredContents();
     unaccountedForUnload   = new VendingMachineStoredContents();
     five  = new Coin(5);
     ten   = new Coin(10);
     two5  = new Coin(25);
     hund  = new Coin(100);
     coke  = new PopCan("Coke");
     water = new PopCan("water");
     stuff = new PopCan("stuff");
 }
Example #7
0
        public void CongifureThenConstructFail()
        {
            coinKinds            = new int[] { 5, 10, 25, 100 };
            selectionButtonCount = 3;
            coinRackCapacity     = 10;
            popCanRackCapacity   = 10;
            receptacleCapacity   = 10;

            List <string> name = new List <string>()
            {
                "Coke", "water", "stuff"
            };
            List <int> cost = new List <int>()
            {
                250, 250, 205
            };

            int[] coinCounts   = new int[] { 1, 1, 2, 0 };
            int[] popCanCounts = new int[] { 1, 1, 1 };
            var   pop1         = new PopCan("Coke");
            var   pop2         = new PopCan("water");
            var   pop3         = new PopCan("stuff");

            vm = new VendingMachine(coinKinds, selectionButtonCount, coinRackCapacity, popCanRackCapacity, receptacleCapacity);
            new VendingMachineLogic(null);
            vm.Configure(name, cost);
            vm.LoadCoins(coinCounts);
            vm.LoadPopCans(popCanCounts);

            // var items = vm.DeliveryChute.RemoveItems();
            // extraction = new List<IDeliverable>(items);

            teardown = UnloadVendingMachine(vm);

            CheckTeardown(65, 0, new List <PopCan>()
            {
                pop1, pop2, pop3
            });
            Assert.Fail("Fail!");
        }
        public void TestMethod1()
        {
            int[] coins = { 5, 10, 25, 100 };

            int selectionButtonCount = 3;
            int coinRackCapacity     = 10;
            int popRackCapacity      = 10;
            int receptacleCapacity   = 10;

            VendingMachine      vm = new VendingMachine(coins, selectionButtonCount, coinRackCapacity, popRackCapacity, receptacleCapacity);
            VendingMachineLogic l  = new VendingMachineLogic(vm);

            List <string> popNames = new List <string>();

            popNames.Add("Coke");
            popNames.Add("water");
            popNames.Add("stuff");

            List <int> popCosts = new List <int>();

            popCosts.Add(250);
            popCosts.Add(250);
            popCosts.Add(205);

            vm.Configure(popNames, popCosts);

            Coin five       = new Coin(5);
            Coin ten        = new Coin(10);
            Coin twentyFive = new Coin(25);
            Coin hundred    = new Coin(100);

            List <Coin> fiveCoins = new List <Coin>();

            fiveCoins.Add(five);

            List <Coin> tenCoins = new List <Coin>();

            tenCoins.Add(ten);

            List <Coin> twentyFiveCoins = new List <Coin>();

            twentyFiveCoins.Add(twentyFive);

            var rack = vm.CoinRacks;

            rack[0].LoadCoins(fiveCoins);
            rack[1].LoadCoins(tenCoins);
            rack[2].LoadCoins(twentyFiveCoins);

            PopCan coke  = new PopCan("Coke");
            PopCan water = new PopCan("water");
            PopCan stuff = new PopCan("stuff");

            List <PopCan> cokes = new List <PopCan>();

            cokes.Add(coke);

            List <PopCan> waters = new List <PopCan>();

            waters.Add(water);

            List <PopCan> stuffs = new List <PopCan>();

            stuffs.Add(stuff);
        }
 /**
  * This method should only be called from hardware devices.
  */
 public void AcceptPopCan(PopCan popCan)
 {
     this.sink.AcceptPopCan(popCan);
 }