Beispiel #1
0
        public Result Handle(SelectPlayerThatAdvancesDuringProblematicTime command)
        {
            Tournament tournament = _tournamentRepository.GetTournamentById(command.TournamentId);

            if (tournament == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Tournament ({ command.TournamentId }) not found."));
            }

            GroupBase group = tournament.GetGroupById(command.GroupId);

            if (group == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Group not found."));
            }

            List <PlayerReference> playerReferences = group.GetPlayerReferences();
            PlayerReference        playerReference  = playerReferences.FirstOrDefault(playerReference => playerReference.Name == command.PlayerName);

            if (playerReference == null)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie. Player not found."));
            }

            bool playerChosenSuccessfully = _tournamentRepository.SolveTieByChoosingPlayerInGroup(group, playerReference);

            if (!playerChosenSuccessfully)
            {
                return(Result.Failure($"Could not select advancing player ({ command.PlayerName }) in group ({ command.GroupId }) during problematic tie."));
            }

            _tournamentRepository.Save();
            return(Result.Success());
        }
Beispiel #2
0
        public void ThenGroupShouldContainExactlyThesePlayerReferencesWithNames(int groupIndex, string commaSeparatedPlayerNames)
        {
            GroupBase     group       = createdGroups[groupIndex];
            List <string> playerNames = StringUtility.ToStringList(commaSeparatedPlayerNames, ",");

            List <PlayerReference> playerReferences = group.GetPlayerReferences();

            playerReferences.Should().HaveCount(playerNames.Count);
            foreach (string playerName in playerNames)
            {
                playerReferences.FirstOrDefault(playerReference => playerReference.Name == playerName).Should().NotBeNull();
            }
        }