Example #1
0
        public bool TransferToNextRound(RoundBase currentRound)
        {
            bool roundHasFinished = currentRound.GetPlayState() == PlayStateEnum.Finished;

            if (roundHasFinished)
            {
                RoundBase nextRound            = currentRound.GetNextRound();
                bool      hasRoundToTransferTo = nextRound != null;

                if (hasRoundToTransferTo)
                {
                    PlayerReferences = currentRound.GetAdvancingPlayerReferences();
                    bool hasPlayerReferencesToTransfer = PlayerReferences.Count > 0;

                    if (hasPlayerReferencesToTransfer)
                    {
                        nextRound.ReceiveTransferedPlayerReferences(this);
                        return(true);
                    }

                    // LOG Error: Tried to transfer advancing player references to next round without any player references.
                    return(false);
                }

                // LOG Error: Tried to transfer advancing player references to nonexistent next round.
                return(false);
            }

            // LOG Error: Tried to transfer advancing player references to next round before current round is finished.
            return(false);
        }
Example #2
0
        public Result Handle(ChangeAdvancingPerGroupCountInRound command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId }). Tournament ({ command.TournamentId }) not found."));
            }

            RoundBase round = tournament.GetRoundById(command.RoundId);

            if (round == null)
            {
                return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId }). Round not found."));
            }

            bool changeSuccessful = _tournamentRepository.SetAdvancingPerGroupCountInRound(round, command.AdvancingPerGroupCount);

            if (!changeSuccessful)
            {
                return(Result.Failure($"Could not change advancing per group count ({ command.AdvancingPerGroupCount }) setting in round ({ command.RoundId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Example #3
0
        public void ThenRoundsInTournamentShouldBeValidWithValues(int tournamentIndex, Table table)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            Tournament tournament = createdTournaments[tournamentIndex];

            for (int index = 0; index < table.Rows.Count; ++index)
            {
                TestUtilities.ParseRoundTable(table.Rows[index], out ContestTypeEnum roundType, out string name, out int advancingCount, out int playersPerGroupCount);

                RoundBase round = tournament.Rounds[index];

                if (round is BracketRound bracketRound)
                {
                    roundType.Should().Be(ContestTypeEnum.Bracket);
                }
                else if (round is DualTournamentRound dualTournamentRound)
                {
                    roundType.Should().Be(ContestTypeEnum.DualTournament);
                }
                else if (round is RoundRobinRound roundRobinRound)
                {
                    roundType.Should().Be(ContestTypeEnum.RoundRobin);
                }

                CheckRoundValidity(round, name, advancingCount, playersPerGroupCount);
            }
        }
Example #4
0
        public Result Handle(RenameRoundInTournament command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId }). Tournament not found."));
            }

            RoundBase round = tournament.GetRoundById(command.RoundId);

            if (round == null)
            {
                return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId }). Round not found."));
            }

            bool renameSuccessful = _tournamentRepository.RenameRoundInTournament(round, command.NewRoundName);

            if (!renameSuccessful)
            {
                return(Result.Failure($"Could not rename round ({ command.RoundId }) to { command.NewRoundName } in tournament ({ command.TournamentId })."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
        public void WhenMatchesInTournamentNamedSwitchesPlayerReferences(string tournamentName, Table table)
        {
            using (TournamentRepository tournamentRepository = CreateTournamentRepository())
            {
                Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName);

                foreach (TableRow row in table.Rows)
                {
                    ParsePlayerSwitch(row,
                                      out int roundIndex,
                                      out int groupIndex1,
                                      out int matchIndex1,
                                      out string playerName1,
                                      out int groupIndex2,
                                      out int matchIndex2,
                                      out string playerName2);

                    RoundBase roundBase = tournament.Rounds[roundIndex];

                    GroupBase groupBase1 = roundBase.Groups[groupIndex1];
                    Match     match1     = groupBase1.Matches[matchIndex1];
                    Player    player1    = match1.FindPlayer(playerName1);

                    GroupBase groupBase2 = roundBase.Groups[groupIndex2];
                    Match     match2     = groupBase2.Matches[matchIndex2];
                    Player    player2    = match2.FindPlayer(playerName2);

                    tournamentRepository.SwitchPlayersInMatches(player1, player2);
                }

                tournamentRepository.Save();
            }
        }
Example #6
0
        public void Report(RoundBase round, TournamentIssues issue)
        {
            int    roundIndex  = GetIndexOf(round);
            string description = GetDescriptionFor(issue);

            Issues.Add(TournamentIssue.Create(roundIndex, -1, -1, description));
        }
Example #7
0
        private bool ManageRoundRemoval(RoundBase round)
        {
            bool containsSoughtRound = Rounds.Contains(round);

            if (containsSoughtRound)
            {
                bool removalSuccessful = Rounds.Remove(round);

                if (removalSuccessful)
                {
                    round.MarkForDeletion();

                    bool stillContainsRounds = Rounds.Count > 0;
                    if (stillContainsRounds)
                    {
                        GetFirstRound().Construct();
                    }

                    FindIssues();
                    return(true);
                }
            }

            return(false);
        }
Example #8
0
 private void RoundFinalComplete(RoundBase r)
 {
     if (r.Data == rounds.GetRound(rounds.NumberRound - 1))
     {
         Invoke("ComingHome", 3f);
     }
 }
Example #9
0
        public void GivenBettersPlacesMatchBets(Table table)
        {
            foreach (TableRow row in table.Rows)
            {
                TestUtilities.ParseBetterMatchBetPlacements(row, out string betterName, out int roundIndex, out int groupIndex, out int matchIndex, out string playerName);

                RoundBase round = createdRounds[roundIndex];
                GroupBase group = createdGroups[groupIndex];
                Match     match = group.Matches[matchIndex];

                bool betterNameIsNotEmpty = betterName.Length > 0;
                bool playerNameIsNotEmpty = playerName.Length > 0;

                if (betterNameIsNotEmpty && playerNameIsNotEmpty)
                {
                    Better better = round.Tournament.GetBetterByName(betterName);
                    Player player = match.FindPlayer(playerName);

                    better.Should().NotBeNull();
                    player.Should().NotBeNull();

                    better.PlaceMatchBet(match, player).Should().NotBeNull();
                }
            }
        }
Example #10
0
        public void CanRemoveBracketRoundFromTournamentById()
        {
            List <Guid> roundIds = new List <Guid>();

            using (TournamentRepository tournamentRepository = CreateTournamentRepository())
            {
                Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName);

                RoundBase round = tournamentRepository.AddBracketRoundToTournament(tournament);
                roundIds.Add(round.Id);

                round = tournamentRepository.AddDualTournamentRoundToTournament(tournament);
                roundIds.Add(round.Id);

                round = tournamentRepository.AddRoundRobinRoundToTournament(tournament);
                roundIds.Add(round.Id);

                tournamentRepository.Save();
            }

            using (TournamentRepository tournamentRepository = CreateTournamentRepository())
            {
                Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName);

                foreach (Guid roundId in roundIds)
                {
                    bool removeResult = tournamentRepository.RemoveRoundFromTournament(tournament, roundId);
                    tournamentRepository.Save();

                    removeResult.Should().BeTrue();
                }

                tournament.Rounds.Should().BeEmpty();
            }
        }
Example #11
0
        public void ThenFetchedAdvancingPlayersInRoundShouldBeExactly(int roundIndex, string commaSeparatedPlayerNames)
        {
            RoundBase     round       = createdRounds[roundIndex];
            List <string> playerNames = StringUtility.ToStringList(commaSeparatedPlayerNames, ",");

            RoundInteractionStepUtility.FetchingAdvancingPlayersInRoundYieldsGivenPlayerNames(round, playerNames);
        }
Example #12
0
        public void ThenPlayStateOfRoundIsSetTo(int roundIndex, string playStateString)
        {
            RoundBase round = createdRounds[roundIndex];

            PlayStateEnum playState = ParsePlayStateString(playStateString);

            round.GetPlayState().Should().Be(playState);
        }
Example #13
0
        public void FetchingPreviousRoundWithFirstRoundYieldsNull()
        {
            RoundBase firstRound = tournament.AddRoundRobinRound();

            RoundBase previousRound = firstRound.GetPreviousRound();

            previousRound.Should().BeNull();
        }
Example #14
0
        public void CanGetRoundInTournamentByRoundName()
        {
            RoundBase fetchedRound = tournament.GetRoundByName(bracketRound.Name);

            fetchedRound.Should().NotBeNull();
            fetchedRound.Id.Should().Be(bracketRound.Id);
            fetchedRound.Name.Should().Be(bracketRound.Name);
        }
Example #15
0
        private static void CheckWhetherLastRoundContainsMoreThanOneGroup(RoundBase round)
        {
            bool lastRoundHasSeveralGroups = round.Groups.Count > 1;

            if (lastRoundHasSeveralGroups)
            {
                round.Tournament.TournamentIssueReporter.Report(round, TournamentIssues.LastRoundContainsMoreThanOneGroup);
            }
        }
Example #16
0
        public bool RenameRoundInTournament(RoundBase round, string name)
        {
            if (round != null)
            {
                return(round.RenameTo(name));
            }

            return(false);
        }
Example #17
0
        public bool SetPlayersPerGroupCountInRound(RoundBase round, int count)
        {
            if (round != null)
            {
                return(round.SetPlayersPerGroupCount(count));
            }

            return(false);
        }
Example #18
0
        private void OnPlayerReferencesChanged()
        {
            RoundBase firstRound = GetFirstRound();

            firstRound.Construct();
            firstRound.FillGroupsWithPlayerReferences();

            FindIssues();
        }
Example #19
0
        public void CanDetectWhenRoundIsNotTheFirstOne()
        {
            RoundBase firstRound  = tournament.AddRoundRobinRound();
            RoundBase secondRound = tournament.AddRoundRobinRound();

            bool isFirstRound = secondRound.IsFirstRound();

            isFirstRound.Should().BeFalse();
        }
Example #20
0
        public void FetchingNextRoundWithLastRoundYieldsNull()
        {
            RoundBase firstRound  = tournament.AddRoundRobinRound();
            RoundBase secondRound = tournament.AddRoundRobinRound();

            RoundBase nextRound = secondRound.GetNextRound();

            nextRound.Should().BeNull();
        }
Example #21
0
        public void CanFetchRoundBeforeThisRound()
        {
            RoundBase beforeRound = tournament.AddRoundRobinRound();
            RoundBase thisRound   = tournament.AddRoundRobinRound();

            RoundBase previousRound = thisRound.GetPreviousRound();

            previousRound.Should().Be(beforeRound);
        }
Example #22
0
        public void CanDetectWhenRoundIsTheLastOne()
        {
            RoundBase firstRound  = tournament.AddRoundRobinRound();
            RoundBase secondRound = tournament.AddRoundRobinRound();

            bool isLastRound = secondRound.IsLastRound();

            isLastRound.Should().BeTrue();
        }
Example #23
0
        public void CanFetchRoundAfterThisRound()
        {
            RoundBase firstRound  = tournament.AddRoundRobinRound();
            RoundBase secondRound = tournament.AddRoundRobinRound();

            RoundBase nextRound = firstRound.GetNextRound();

            nextRound.Should().Be(secondRound);
        }
Example #24
0
        public void WhenRoundIsRemovedFromTournament(int tournamentIndex, int roundIndex)
        {
            RoundBase  round      = createdRounds[roundIndex];
            Tournament tournament = createdTournaments[tournamentIndex];

            tournament.RemoveRound(round);

            createdRounds.Clear();
            createdRounds.AddRange(tournament.Rounds);
        }
Example #25
0
        public static void FetchingAdvancingPlayersInRoundYieldsGivenPlayerNames(RoundBase round, List <string> playerNames)
        {
            List <PlayerReference> playerReferences = round.GetAdvancingPlayerReferences();

            playerReferences.Should().HaveCount(playerNames.Count);
            foreach (string playerName in playerNames)
            {
                playerReferences.SingleOrDefault(playerReference => playerReference.Name == playerName).Should().NotBeNull();
            }
        }
Example #26
0
 public static RoundDto ConvertToRoundDto(RoundBase round)
 {
     return(new RoundDto()
     {
         Id = round.Id,
         ContestType = round.ContestType.ToString(),
         Name = round.Name,
         Groups = round.Groups.Select(group => ConvertToGroupDto(group)).ToList()
     });
 }
Example #27
0
 public MatchBetTests()
 {
     user       = User.Create("Stålberto");
     tournament = Tournament.Create("GSL 2019");
     round      = tournament.AddBracketRound();
     tournament.RegisterPlayerReference("Maru");
     tournament.RegisterPlayerReference("Stork");
     group = round.Groups.First();
     match = group.Matches.First();
 }
Example #28
0
        public bool RemoveRoundFromTournament(Tournament tournament, string roundName)
        {
            RoundBase roundToRemove = tournament.GetRoundByName(roundName);

            if (roundToRemove != null)
            {
                return(tournament.RemoveRound(roundToRemove));
            }

            return(false);
        }
        public void GivenRoundNamedChangesPlayersPerGroupCountToInTournamentNamed(string roundName, int newPlayersPerGroupCount, string tournamentName)
        {
            using (TournamentRepository tournamentRepository = CreateTournamentRepository())
            {
                Tournament tournament = tournamentRepository.GetTournamentByName(tournamentName);
                RoundBase  round      = tournament.GetRoundByName(roundName);

                tournamentRepository.SetPlayersPerGroupCountInRound(round, newPlayersPerGroupCount);
                tournamentRepository.Save();
            }
        }
Example #30
0
        public bool RemoveRoundFromTournament(Tournament tournament, Guid roundId)
        {
            RoundBase roundToRemove = tournament.GetRoundById(roundId);

            if (roundToRemove != null)
            {
                return(tournament.RemoveRound(roundToRemove));
            }

            return(false);
        }