예제 #1
0
        public void TestTimersNotSold()
        {
            List<string> receivedEvents = new List<string>();

            AuctionItem item = new AuctionItem(1, "Chair", 100, 1000);
            Auction auction = new Auction();
            auction.AddItem(item);

            Auctioneer auctioneer = new Auctioneer(auction, 500, 500, 500);

            auctioneer.CallFirst += delegate(string message)
            {
                receivedEvents.Add(message);
            };

            auctioneer.CallSecond += delegate(string message)
            {
                receivedEvents.Add(message);
            };

            auctioneer.CallThird += delegate(string message)
            {
                receivedEvents.Add(message);
            };

            auction.Start(auctioneer);

            Thread.Sleep(2000);

            Assert.AreEqual("First!", receivedEvents[0]);
            Assert.AreEqual("Second!", receivedEvents[1]);
            bool containsThird = receivedEvents[2].Contains("Third!");
            Assert.IsTrue(containsThird);
        }
예제 #2
0
        private void timerSignal(object sender, ElapsedEventArgs e)
        {
            timer.Stop();

            if (callNumber == 1)
            {
                CallFirst("First!");
                callNumber++;
                timer.Interval = secondTimeout;
                timer.Start();
            }
            else if (callNumber == 2)
            {
                CallSecond("Second!");
                callNumber++;
                timer.Interval = thirdTimeout;
                timer.Start();
            }
            else
            {
                bool isSold = auction.IsCurrentItemSold();

                AuctionItem item = auction.CurrentItem;

                if (isSold)
                {
                    CallThird("Third! " + item.ItemName + " sold to " + item.HighestBidder + " for " + item.Bid + " HollarDollars!");
                }
                else
                {
                    CallThird("Third! " + item.ItemName + " not sold");
                }
            }
        }
예제 #3
0
        // sellNextItem has to take a string as input because it subscribes to Auctioneer's 
        // CallThird, but the string is never used in sellNextItem.
        private void sellNextItem(string message)
        {
            // Stop the auction, wait a second then start the next round
            auctionRunning = false;
            Thread.Sleep(1000);
            auctionRunning = true;
            if (auctionItems.Count != 0)
            {
                lock (auctionLock)
                {
                    _currentItem = auctionItems.Dequeue();
                }

                NewRound();
            }
        }
예제 #4
0
        // sellNextItem has to take a string as input because it subscribes to Auctioneer's
        // CallThird, but the string is never used in sellNextItem.
        private void sellNextItem(string message)
        {
            // Stop the auction, wait a second then start the next round
            auctionRunning = false;
            Thread.Sleep(1000);
            auctionRunning = true;
            if (auctionItems.Count != 0)
            {
                lock (auctionLock)
                {
                    _currentItem = auctionItems.Dequeue();
                }

                NewRound();
            }
        }
예제 #5
0
        public PlaceBidsController()
        {
            auctionStarted = false;
            auction = new Auction();

            AuctionItem item1 = new AuctionItem(1, "Chair", 2000, 2000);
            auction.AddItem(item1);
            AuctionItem item2 = new AuctionItem(2, "Car", 50000, 70000);
            auction.AddItem(item2);
            AuctionItem item3 = new AuctionItem(3, "Couch", 400, 400);
            auction.AddItem(item3);

            auctioneer = new Auctioneer(auction, 10000, 5000, 3000);

            auction.NewRound += newRound;
            auction.NewBidAccepted += newBidAccepted;
            auctioneer.CallFirst += callFirst;
            auctioneer.CallSecond += callSecond;
            auctioneer.CallThird += callThird;
        }
예제 #6
0
 public void AddItem(AuctionItem item)
 {
     auctionItems.Enqueue(item);
 }
예제 #7
0
 public void AddItem(AuctionItem item)
 {
     auctionItems.Enqueue(item);
 }