public async Task SignUpPlayerForTournament(Guid tournamentId,
                                                    Guid playerId, CancellationToken cancellationToken)
        {
            // Validate the tournament Id
            TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(tournamentId, cancellationToken);

            PlayerAggregate player = await this.PlayerRepository.GetLatestVersion(playerId, cancellationToken);

            if (!player.HasBeenRegistered)
            {
                throw new InvalidOperationException("A player must be registered to sign up for a club tournament");
            }

            try
            {
                GolfClubMembershipAggregate golfClubMembership = await this.ClubMembershipRepository.GetLatestVersion(tournament.GolfClubId, cancellationToken);

                golfClubMembership.GetMembership(player.AggregateId, player.DateOfBirth, player.Gender);
            }
            catch (NotFoundException nex)
            {
                throw new InvalidOperationException("A player must be a member of the club to sign up for a club tournament");
            }

            tournament.SignUpForTournament(playerId);

            await this.TournamentRepository.SaveChanges(tournament, cancellationToken);
        }
        public static TournamentAggregate GetCreatedTournamentAggregateWithPlayerSignedUp()
        {
            TournamentAggregate aggregate = TournamentAggregate.Create(TournamentTestData.AggregateId);

            aggregate.CreateTournament(TournamentTestData.TournamentDate, TournamentTestData.GolfClubId, TournamentTestData.MeasuredCourseId, TournamentTestData.MeasuredCourseSSS, TournamentTestData.Name, TournamentTestData.PlayerCategoryEnum, TournamentTestData.TournamentFormatEnum);

            aggregate.SignUpForTournament(TournamentTestData.PlayerId);

            return(aggregate);
        }
        public static TournamentAggregate GetCreatedTournamentWithScoresRecordedAggregate()
        {
            TournamentAggregate aggregate = TournamentAggregate.Create(TournamentTestData.AggregateId);

            aggregate.CreateTournament(TournamentTestData.TournamentDate, TournamentTestData.GolfClubId, TournamentTestData.MeasuredCourseId, TournamentTestData.MeasuredCourseSSS, TournamentTestData.Name, TournamentTestData.PlayerCategoryEnum, TournamentTestData.TournamentFormatEnum);

            aggregate.SignUpForTournament(TournamentTestData.PlayerId);

            aggregate.RecordPlayerScore(TournamentTestData.PlayerId, TournamentTestData.PlayingHandicap, TournamentTestData.HoleScores);

            return(aggregate);
        }
        public static TournamentAggregate GetCompletedTournamentAggregate(Int32 category1Scores = 1, Int32 category2Scores  = 2, Int32 category3Scores = 7,
                                                                          Int32 category4Scores = 20, Int32 category5Scores = 5, Int32 bufferorbetter  = 5)
        {
            TournamentAggregate aggregate = TournamentAggregate.Create(TournamentTestData.AggregateId);

            aggregate.CreateTournament(TournamentTestData.TournamentDate, TournamentTestData.GolfClubId, TournamentTestData.MeasuredCourseId, TournamentTestData.MeasuredCourseSSS, TournamentTestData.Name, TournamentTestData.PlayerCategoryEnum, TournamentTestData.TournamentFormatEnum);

            List <GeneratedPlayerScore> scoresToRecord = TournamentTestData.GenerateScores(category1Scores, category2Scores, category3Scores, category4Scores, category5Scores, bufferorbetter);

            foreach (GeneratedPlayerScore playerScoreForTest in scoresToRecord)
            {
                aggregate.SignUpForTournament(playerScoreForTest.PlayerId);
                aggregate.RecordPlayerScore(playerScoreForTest.PlayerId, playerScoreForTest.Handicap, playerScoreForTest.HoleScores);
            }

            aggregate.CompleteTournament(TournamentTestData.CompletedDateTime);

            return(aggregate);
        }
        public void TournamentAggregate_SignUpForTournament_TournamentNotCreated_ErrorThrown()
        {
            TournamentAggregate tournament = TournamentTestData.GetEmptyTournamentAggregate();

            Should.Throw <InvalidOperationException>(() => { tournament.SignUpForTournament(TournamentTestData.PlayerId); });
        }
        public void TournamentAggregate_SignUpForTournament_PlayerSignedUp()
        {
            TournamentAggregate tournament = TournamentTestData.GetCreatedTournamentAggregate();

            tournament.SignUpForTournament(TournamentTestData.PlayerId);
        }
        public void TournamentAggregate_SignUpForTournament_PlayerAlreadySignedUp_ErrorThrown()
        {
            TournamentAggregate tournament = TournamentTestData.GetCreatedTournamentAggregateWithPlayerSignedUp();

            Should.Throw <InvalidOperationException>(() => { tournament.SignUpForTournament(TournamentTestData.PlayerId); });
        }