Beispiel #1
0
        private void PlayMatch(TournamentRepository tournamentRepository, Match match)
        {
            bool matchHaveNotStarted = match.StartDateTime > SystemTime.Now;

            if (matchHaveNotStarted)
            {
                SystemTimeMocker.SetOneSecondAfter(match.StartDateTime);
            }

            int winningScore = (int)Math.Ceiling(match.BestOf / 2.0);

            // Give points to player with name that precedes the other alphabetically
            bool increasePlayer1Score = match.Player1.GetName().CompareTo(match.Player2.GetName()) <= 0;

            Tournament tournament      = match.Group.Round.Tournament;
            Guid       scoringPlayerId = increasePlayer1Score ? match.Player1.Id : match.Player2.Id;

            tournamentRepository.AddScoreToPlayerInMatch(tournament, match.Id, scoringPlayerId, winningScore);
            tournamentRepository.Save();
        }
Beispiel #2
0
        public void GivenScoreIsAddedToPlayersInGivenMatchesInGroups(string tournamentName, Table table)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }

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

                foreach (TableRow row in table.Rows)
                {
                    TestUtilities.ParseScoreAddedToMatchPlayer(row, out int roundIndex, out int groupIndex, out int matchIndex, out string scoringPlayer, out int scoreAdded);

                    RoundBase round = tournament.Rounds[roundIndex];
                    GroupBase group = round.Groups[groupIndex];
                    Match     match = group.Matches[matchIndex];

                    SystemTimeMocker.SetOneSecondAfter(match.StartDateTime);

                    Player player = match.FindPlayer(scoringPlayer);

                    if (player != null)
                    {
                        tournamentRepository.AddScoreToPlayerInMatch(tournament, match.Id, player.Id, scoreAdded);
                    }
                    else
                    {
                        // LOG Error: Invalid player name in given match within given group
                        throw new NotImplementedException();
                    }
                }

                tournamentRepository.Save();
            }
        }