Esempio n. 1
0
        public void OnlyOneBuzzHandledWhenQueueDisabled()
        {
            Buzz lateBuzz = new Buzz()
            {
                PlayerDisplayName = "Late",
                TeamId            = "743",
                Timestamp         = DateTime.Now,
                UserId            = DefaultBuzz.UserId + 1
            };

            TossupBonusPhaseState phaseState = new TossupBonusPhaseState(disableBuzzQueue: true);

            Assert.IsFalse(phaseState.HasBonus, "We shouldn't have a bonus until a correct buzz");
            Assert.AreEqual(PhaseStage.Tossup, phaseState.CurrentStage, "We should be in the tossup phase");

            phaseState.AddBuzz(DefaultBuzz);
            phaseState.AddBuzz(lateBuzz);

            Assert.IsTrue(phaseState.TryScoreBuzz(0), "Scoring the buzz should succeed");
            Assert.IsFalse(
                phaseState.TryGetNextPlayer(out _), "There shouldn't be another player after the incorrect buzz");
            Assert.IsFalse(phaseState.HasBonus, "We should still be on the tossup phase");

            phaseState.AddBuzz(lateBuzz);
            Assert.IsTrue(
                phaseState.TryGetNextPlayer(out _), "There should be a player after buzzing in again");
            Assert.IsTrue(phaseState.TryScoreBuzz(10), "Scoring the buzz the second time should succeed");
            Assert.AreEqual(PhaseStage.Bonus, phaseState.CurrentStage, "We should be in the bonus phase");
        }
        private static TossupBonusPhaseState CreatePhaseInBonusStage()
        {
            TossupBonusPhaseState phaseState = new TossupBonusPhaseState();

            phaseState.AddBuzz(DefaultBuzz);
            phaseState.TryScoreBuzz(10);
            return(phaseState);
        }
        public void UndoScoredTossup()
        {
            TossupBonusPhaseState phaseState = new TossupBonusPhaseState();

            phaseState.AddBuzz(DefaultBuzz);
            Assert.IsTrue(phaseState.TryScoreBuzz(-5), "Scoring the first buzz should succeed");

            Assert.IsTrue(
                phaseState.AlreadyBuzzedPlayerIds.Contains(DefaultBuzz.UserId),
                "Default player not in the list of already buzzed players");
            Assert.AreEqual(1, phaseState.Actions.Count, "Unexpected number of buzzes recorded");

            ulong  secondBuzzPlayerId = DefaultBuzz.UserId + 1;
            string secondTeamId       = $"{DefaultBuzz.TeamId}1";
            Buzz   incorrectBuzz      = new Buzz()
            {
                TeamId            = secondTeamId,
                PlayerDisplayName = "Bob",
                UserId            = secondBuzzPlayerId,
                Timestamp         = DateTime.Now + TimeSpan.FromSeconds(1)
            };

            phaseState.AddBuzz(incorrectBuzz);
            Assert.IsTrue(phaseState.TryScoreBuzz(0), "Scoring the second buzz should succeed");
            Assert.IsTrue(
                phaseState.AlreadyBuzzedPlayerIds.Contains(secondBuzzPlayerId),
                "Second player not in the list of already buzzed players");
            Assert.AreEqual(2, phaseState.Actions.Count, "Unexpected number of buzzes recorded after the second buzz");

            phaseState.Undo(out ulong?userId);
            Assert.AreEqual(secondBuzzPlayerId, userId, "Unexpected userId returned by Undo");
            Assert.IsTrue(
                phaseState.AlreadyScoredTeamIds.Contains(DefaultBuzz.TeamId),
                "Default player not in the list of already scored teams after the first undo");
            Assert.IsFalse(
                phaseState.AlreadyScoredTeamIds.Contains(secondTeamId),
                "Second player not in the list of already scored teams after the first undo");
            Assert.AreEqual(1, phaseState.Actions.Count, "Unexpected number of buzzes recorded after the first undo");

            phaseState.Undo(out userId);
            Assert.AreEqual(DefaultBuzz.UserId, userId, "Unexpected userId returned by Undo");
            Assert.IsFalse(
                phaseState.AlreadyScoredTeamIds.Contains(DefaultBuzz.TeamId),
                "Default player not in the list of already scored teams after the second undo");
            Assert.AreEqual(0, phaseState.Actions.Count, "Unexpected number of buzzes recorded after the second undo");
        }
        public void TestStagesForIncorrectBuzz()
        {
            TossupBonusPhaseState phaseState = new TossupBonusPhaseState();

            Assert.IsFalse(phaseState.HasBonus, "We should have a bonus on a correct buzz");
            Assert.AreEqual(PhaseStage.Tossup, phaseState.CurrentStage, "We should be in the tossup phase");

            phaseState.AddBuzz(DefaultBuzz);
            Assert.IsTrue(phaseState.TryScoreBuzz(0), "Scoring the buzz should succeed");

            // Should be the same
            Assert.IsFalse(phaseState.HasBonus, "We shouldn't have a bonus on an incorrect buzz");
            Assert.AreEqual(PhaseStage.Tossup, phaseState.CurrentStage, "We should still be in the tossup phase");
        }
        public void TestStagesForCorrectBuzz()
        {
            TossupBonusPhaseState phaseState = new TossupBonusPhaseState();

            Assert.IsFalse(phaseState.HasBonus, "We should have a bonus on a correct buzz");
            Assert.AreEqual(PhaseStage.Tossup, phaseState.CurrentStage, "We should be in the tossup phase");

            phaseState.AddBuzz(DefaultBuzz);
            Assert.IsTrue(phaseState.TryScoreBuzz(10), "Scoring the buzz should succeed");

            Assert.IsTrue(phaseState.HasBonus, "We should have a bonus on a correct buzz");
            Assert.AreEqual(PhaseStage.Bonus, phaseState.CurrentStage, "We should be in the bonus phase");

            Assert.IsTrue(phaseState.TryScoreBonus("0"), "Scoring the bonus should succeed");
            Assert.AreEqual(PhaseStage.Complete, phaseState.CurrentStage, "We should be done with this phase");
        }