public void Auction_EndTimeHasArrived_AuctionGetsClosed()
        {
            var repo       = new InMemoryMainRepository();
            var auctioneer = new Auctioneer(repo);

            var auction = CreateAndStoreAuction(repo, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1));

            auctioneer.DoAllWork();

            Assert.IsFalse(auction.IsClosed);

            // Turn back the time
            auction.EndDateTimeUtc = DateTime.UtcNow;

            auctioneer.DoAllWork();

            Assert.IsTrue(auction.IsClosed);
            Assert.IsFalse(auction.IsRunning);
        }
        public void Bid_WhenAccepted_EventIsRaised()
        {
            var repo       = new InMemoryMainRepository();
            var auctioneer = new Auctioneer(repo);

            var auction = CreateAndStoreAuction(repo, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1));

            ProcessedBidEventArgs raisedArgs = null;

            auctioneer.BidAccepted += (sender, args) => raisedArgs = args;

            AddInitialBidToAuction(repo, auction);

            auctioneer.DoAllWork();

            Assert.NotNull(raisedArgs);
            Assert.NotNull(raisedArgs.Auction);
            Assert.NotNull(raisedArgs.Bid);
        }
        public void Auction_WhenEnded_EventIsRaised()
        {
            var repo       = new InMemoryMainRepository();
            var auctioneer = new Auctioneer(repo);

            var auction = CreateAndStoreAuction(repo, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1));

            AuctionEventArgs raisedArgs = null;

            auctioneer.AuctionEnded += (sender, args) => raisedArgs = args;

            // Turn back the time
            auction.EndDateTimeUtc = DateTime.UtcNow;

            auctioneer.DoAllWork();

            Assert.NotNull(raisedArgs);
            Assert.NotNull(raisedArgs.Auction);
            Assert.NotNull(raisedArgs.IsSuccessful);
        }
        public void AuctionStartedAndEndedInThePast_AuctioneerRuns_DontGetsStarted()
        {
            var repo       = new InMemoryMainRepository();
            var auctioneer = new Auctioneer(repo);

            AuctionEventArgs raisedArgs = null;

            auctioneer.AuctionStarted += (sender, args) => raisedArgs = args;

            var auction = CreateAndStoreAuction(repo, DateTime.UtcNow.AddHours(-2), DateTime.UtcNow.AddHours(-1));

            auction.IsRunning = false;
            auction.IsClosed  = true;

            auctioneer.DoAllWork();

            Assert.IsNull(raisedArgs);
            Assert.IsTrue(auction.IsClosed);
            Assert.IsFalse(auction.IsRunning);
        }
Beispiel #5
0
        public static TradingHistory ToTradingHistory(
            this TradingHistoryModel tradingHistory,
            Auctioneer auctioneer,
            Trader trader,
            Lot lot)
        {
            if (tradingHistory == null)
            {
                throw new ArgumentNullException(nameof(tradingHistory));
            }

            if (auctioneer == null)
            {
                throw new ArgumentNullException(nameof(auctioneer));
            }

            if (trader == null)
            {
                throw new ArgumentNullException(nameof(trader));
            }

            if (lot == null)
            {
                throw new ArgumentNullException(nameof(lot));
            }

            return(new TradingHistory
            {
                AuctioneerId = auctioneer.Id,
                LotId = lot.Id,
                TraderId = trader.Id,
                BidTime = tradingHistory.BidTime,
                BidOrder = tradingHistory.BidOrder,
                RecordedPrice = tradingHistory.RecordedPrice,
                Auctioneer = auctioneer,
                Lot = lot,
                Trader = trader
            });
        }
        public void TestTimersSold()
        {
            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);

            auction.PlaceBid(1, 1100, "bla");

            Thread.Sleep(2000);

            Assert.AreEqual("First!", receivedEvents[0]);
            Assert.AreEqual("Second!", receivedEvents[1]);
            bool containsThird = receivedEvents[2].Contains("Third!");

            Assert.IsTrue(containsThird);
        }
        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;
        }
Beispiel #8
0
        public static void Run()
        {
            Console.WriteLine($"{Environment.NewLine}*** MEDIATOR PATTERN ***{Environment.NewLine}");

            Auction     auction = new Auction();
            Participant tom     = new Bidder("Tom");
            Participant dick    = new Bidder("Dick");
            Participant harry   = new Bidder("Harry");
            Participant fred    = new Auctioneer("Fred");

            // Register the participants in the auction
            auction.Register(tom);
            auction.Register(dick);
            auction.Register(harry);
            auction.Register(fred);

            // Do some auctioning
            fred.Participate("Who will start the bidding?");
            tom.Participate("Bidding 100");
            dick.Participate("Bidding 110");
            harry.Participate("Bidding 150");
            fred.Participate("Bike sold to Harry for 150");
        }
        public void Auction_GetsOlderButHigherBid_FailsWithException()
        {
            var repo       = new InMemoryMainRepository();
            var auctioneer = new Auctioneer(repo);

            var auction = CreateAndStoreAuction(repo, DateTime.UtcNow.AddHours(-1), DateTime.UtcNow.AddHours(1));

            AddInitialBidToAuction(repo, auction);

            auctioneer.DoAllWork();

            var bidder2 = new Member()
            {
                DisplayName = "Bidder2", UniqueId = Guid.NewGuid().ToString()
            };

            repo.Add(bidder2);
            repo.Add(new Bid()
            {
                ReceivedOnUtc = DateTime.UtcNow.AddMinutes(-10), Bidder = bidder2, Amount = 70, Auction = auction
            });

            auctioneer.DoAllWork();
        }
Beispiel #10
0
        public void Auctioneer_Participate_CallsParticipantsReceive()
        {
            // Arrange
            string      bidderName     = "bidder";
            string      auctioneerName = "auctioneer";
            Auction     auction        = new Auction();
            Participant bidder         = new Bidder(bidderName);
            Participant auctioneer     = new Auctioneer(auctioneerName);

            auction.Register(bidder);
            auction.Register(auctioneer);

            using (StringWriter writer = new StringWriter())
            {
                // Capture the console output
                Console.SetOut(writer);

                // Act
                auctioneer.Participate("Who will start the bidding?");

                // Assert
                Assert.IsTrue(writer.ToString().Contains($"{auctioneerName} to {bidderName}"));
            }
        }
Beispiel #11
0
    // Update is called once per frame
    void Update()
    {
        if (Time.timeSinceLevelLoad > 1 && !hasPlacedAIBets)
        {
            TwitchChatExample ChatLink = gameObject.GetComponent <TwitchChatExample>();
            for (int i = 0; i <= 128; i++)
            {
                ChatLink.fakeMessage(TurtlesInTheRace[Random.Range(0, 10)].name);
                if (i > 122)
                {
                    ChatLink.fakeMessage("bid A " + CurrentTurtlesForSale[0].GetComponent <TurtleForSale>().myName + " " + Random.Range(1, 10));
                }
            }
            hasPlacedAIBets = true;
        }

        if (Input.GetKeyDown(KeyCode.M))
        {
            if (BonusRoundManager.IsMusicEnabled)
            {
                BonusRoundManager.IsMusicEnabled = false;
                Debug.Log("Disabling Music");
            }
            else
            {
                BonusRoundManager.IsMusicEnabled = true;
                Debug.Log("Enabling Music");
            }
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            foreach (GameObject eachTurtle in TurtlesInTheRace)
            {
                TurtleAI ti = eachTurtle.GetComponent <TurtleAI>();
                ti.BaseSpeed = 50;
            }
            TimeBetweenRaces = 2;
        }
        if (Input.GetKeyDown(KeyCode.S))
        { //start the race shortcut
            TimeBetweenRaces = 2;
        }

        if (TimeBetweenRaces - 9 < Time.timeSinceLevelLoad && BettingOpenDialog.activeInHierarchy == true)
        {
            AudioSource.PlayClipAtPoint(bellSound, Camera.main.transform.position);
            BettingClosedDialog.SetActive(true);
            BettingOpenDialog.SetActive(false);
            raceInfoDialog.SetActive(false);
            RaceDetailsGridObject.SetActive(false);
        }
        if (TimeBetweenRaces - Time.timeSinceLevelLoad < 40 && !startedMusic)
        {
            print("time race ended " + timeRaceEnded + " time between races " + TimeBetweenRaces);

            MainCameraHelper.StartTheRaceMusic();
            startedMusic = true;
        }
        if (TimeBetweenRaces - 6 < Time.timeSinceLevelLoad && isBettingOpen)
        {
            isBettingOpen = false;
        }

        if (TimeBetweenRaces * 0.9f < Time.timeSinceLevelLoad && !hasAucionCompleted)
        {
            Auctioneer.FinalizeAuction(this.gameObject);
            hasAucionCompleted = true;
            AuctionTimerObject.SetActive(false);
            WholeAuctionObject.SetActive(false);
        }
        else
        {
            AuctionTimer.text = Mathf.RoundToInt((TimeBetweenRaces * 0.9f) - Time.timeSinceLevelLoad) + " Seconds";
        }

        if (TimeBetweenRaces < Time.timeSinceLevelLoad && !hasRaceStarted)
        {
            hasRaceStarted = true;
            RaceStartingTimerObject.SetActive(false);
            BettingClosedDialog.SetActive(false);
            RaceCam1.m_Speed = 1;
            //TimeBetweenRaces += Time.time; //this was causing extra delays
            BetManager.FinalizeOdds(this.gameObject);
        }
        else
        {
            RaceStartingTimer.text = Mathf.RoundToInt(TimeBetweenRaces - Time.timeSinceLevelLoad) + " Seconds";
        }
        if (hasRaceStarted && FinishLineCam.Priority != 16)
        {
            foreach (GameObject turtleRef in TurtlesInTheRace)
            {
                TurtleAI turlteScriptRef = turtleRef.GetComponent <TurtleAI>();

                /*if(BackHalfCam.Priority!=15 && turlteScriptRef.percentFinished > 0.5f){
                 *                      BackHalfCam.Priority = 15;
                 *              }*/
                if (turlteScriptRef.percentFinished > 0.9f)
                {
                    FinishLineCam.Priority = 16;
                }
            }
        }

        //If a single turtle finshed, open the in-race results gui.
        if (TurtleAI.HowManyTurtlesFinished > 0 && !hasRaceEnded)
        {
            if (!InRaceresultsScreen.activeInHierarchy)
            {
                InRaceresultsScreen.SetActive(true);
            }
        }

        if (TurtleAI.HowManyTurtlesFinished == 10 && !hasRaceEnded)
        {
            hasRaceEnded = true;
            PayOutWinners();
            InRaceresultsScreen.SetActive(false);
            RaceResultsScreen.SetActive(true);
            RaceStartingTitle.text = "Bonus Round in";
            BettingClosedDialog.SetActive(true);
            raceInfoDialog.SetActive(true);
            RaceResultsGUITextA.text = TurtleAI.RaceResultsColumn1 + "<nobr>";
            RaceResultsGUITextB.text = TurtleAI.RaceResultsColumn2 + "<nobr>";
            RaceResultsGuiTextC.text = TurtleAI.RaceResultsColumn3 + "<nobr>";
            RaceResultsGiuTextD.text = TurtleAI.RaceResultsColumn4 + "<nobr>";

            timeRaceEnded = Time.timeSinceLevelLoad;
            int   totalTrueBets = 0;
            float totalPaidOut  = 0;
            foreach (BetData eachBet in CurrentRaceBets)
            {
                //Check for winning bets
                if (eachBet.BetType == "win")
                {
                    foreach (RaceResultData contestant in GuestManager.CurrentRaceresults)
                    {
                        if (contestant.FinishingPlace == 1 && contestant.TurtleName == eachBet.TurtlesName)
                        {
                            //They predicted this win!
                            eachBet.didBetComeTrue = true;
                            totalTrueBets++;
                        }
                    }
                }
                if (eachBet.BetType == "place")
                {
                    foreach (RaceResultData contestant in GuestManager.CurrentRaceresults)
                    {
                        if (contestant.TurtleName == eachBet.TurtlesName)
                        {
                            if (contestant.FinishingPlace == 1 || contestant.FinishingPlace == 2)
                            {
                                eachBet.didBetComeTrue = true;
                                totalTrueBets++;
                            }
                        }
                    }
                }
                if (eachBet.BetType == "show")
                {
                    foreach (RaceResultData contestant in GuestManager.CurrentRaceresults)
                    {
                        if (contestant.TurtleName == eachBet.TurtlesName)
                        {
                            if (contestant.FinishingPlace <= 3)
                            {
                                eachBet.didBetComeTrue = true;
                                totalTrueBets++;
                            }
                        }
                    }
                }

                foreach (GuestData eachGuest in GuestManager.AllGuests)
                {
                    if (eachGuest.guestName == eachBet.BettersName)
                    {
                        if (eachBet.didBetComeTrue)
                        {
                            //Pay them if the bet won.
                            float     amountToPay = eachBet.BetAmount * eachBet.BetOdds;
                            TwitchIRC tIRC        = GetComponent <TwitchIRC>();
                            if (eachBet.BetType == "place")
                            {
                                amountToPay = eachBet.BetAmount + OddsDisplay.CurrentTotalPlacePool * (eachBet.BetAmount / (OddsDisplay.CurrentTotalPlacePool / 2));
                                //Debug.Log("Paying out " + amountToPay + " to " + eachGuest.guestName + " for betting " + eachBet.BetAmount + " on " + eachBet.TurtlesName + " to place of a pool of " + OddsDisplay.CurrentTotalPlacePool);
                                if (!eachGuest.guestName.Contains("turtlebot"))
                                {
                                    //tIRC.SendMsg("Paying out " + amountToPay + " to " + eachGuest.guestName + " for betting " + eachBet.BetAmount + " on " + eachBet.TurtlesName + "to place of a pool of " + OddsDisplay.CurrentTotalPlacePool);
                                }
                            }
                            if (eachBet.BetType == "win")
                            {
                                //Debug.Log("Paying out " + amountToPay + " to " + eachGuest.guestName + " for betting " + eachBet.BetAmount + " on " + eachBet.TurtlesName + " at odds of " + eachBet.BetOdds);
                                if (!eachGuest.guestName.Contains("turtlebot"))
                                {
                                    //tIRC.SendMsg("Paying out " + amountToPay + " to " + eachGuest.guestName + " for betting " + eachBet.BetAmount + " on " + eachBet.TurtlesName + " at odds of " + eachBet.BetOdds);
                                }
                            }
                            if (eachBet.BetType == "show")
                            {
                                amountToPay = eachBet.BetAmount + OddsDisplay.CurrentTotalShowPool * (eachBet.BetAmount / (OddsDisplay.CurrentTotalShowPool / 3));
                                //Debug.Log("Paying out " + amountToPay + " to " + eachGuest.guestName + " for betting " + eachBet.BetAmount + " on " + eachBet.TurtlesName + " to show of a pool of " + OddsDisplay.CurrentTotalShowPool);
                                if (!eachGuest.guestName.Contains("turtlebot"))
                                {
                                    //tIRC.SendMsg("Paying out " + amountToPay + " to " + eachGuest.guestName + " for betting " + eachBet.BetAmount + " on " + eachBet.TurtlesName + " to show of a pool of " + OddsDisplay.CurrentTotalShowPool);
                                }
                            }
                            eachGuest.guestCash += amountToPay;
                            totalPaidOut        += amountToPay;
                            float totalPaidIn = OddsDisplay.CurrentTotalPlacePool + OddsDisplay.CurrentTotalPot + OddsDisplay.CurrentTotalShowPool;
                            //print("Total paid out = " + totalPaidOut + " Total paid in = " + totalPaidIn);
                        }
                    }
                }
            }
        }
        if (timeRaceEnded > 1)
        {
            if (RaceStartingTimerObject.activeInHierarchy != true)
            {
                RaceStartingTimerObject.SetActive(true);
            }
            RaceStartingTimer.text = Mathf.RoundToInt((timeRaceEnded + (TimeBetweenRaces / 5)) - Time.timeSinceLevelLoad) + " Seconds";
            RaceStartingTitle.text = "Bonus Round in...";
            //Debug.Log("Time race ended " + timeRaceEnded + "  Time between races " + TimeBetweenRaces + "  current time " + Time.time);
            if (Time.timeSinceLevelLoad > timeRaceEnded + (TimeBetweenRaces / 5))
            {
                GuestManager.SaveGuestData();
                GuestManager.ClearNextRaceTurtles();
                SceneManager.LoadScene("Pachinko");
            }
        }
    }
 public static bool IsEqualTo(this Auctioneer @this, AuctioneerModel auctioneer)
 {
     return(auctioneer.IsEqualTo(@this));
 }