public void TournamentAggregate_CalculateCSS_CSSAlreadyCalculated_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCompletedTournamentAggregate(1, 2, 7, 20, 5, 5);

            aggregate.CalculateCSS();

            Should.Throw <InvalidOperationException>(() => { aggregate.CalculateCSS(); });
        }
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task HandleCommand(CompleteTournamentCommand command,
                                         CancellationToken cancellationToken)
        {
            // Rehydrate the aggregate
            TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken);

            DateTime completedDateTime = DateTime.Now;

            tournament.CompleteTournament(completedDateTime);

            tournament.CalculateCSS();

            // Save the changes
            await this.TournamentRepository.SaveChanges(tournament, cancellationToken);
        }
        public void TournamentAggregate_CalculateCSS_CSSCalculated(Int32 category1Scores,
                                                                   Int32 category2Scores,
                                                                   Int32 category3Scores,
                                                                   Int32 category4Scores,
                                                                   Int32 category5Scores,
                                                                   Int32 bufferorbetter,
                                                                   Int32 expectedAdjustment,
                                                                   Int32 expectedCSS)
        {
            TournamentAggregate aggregate =
                TournamentTestData.GetCompletedTournamentAggregate(category1Scores, category2Scores, category3Scores, category4Scores, category5Scores, bufferorbetter);

            aggregate.CalculateCSS();

            aggregate.Adjustment.ShouldBe(expectedAdjustment);
            aggregate.CSS.ShouldBe(expectedCSS);
            aggregate.GetScores().All(s => s.IsPublished).ShouldBeTrue();
        }
        public static TournamentAggregate GetCompletedTournamentAggregateWithCSSCalculatedAggregate(Int32 category1Scores = 1, Int32 category2Scores  = 2, Int32 category3Scores = 7,
                                                                                                    Int32 category4Scores = 20, Int32 category5Scores = 5, Int32 bufferorbetter  = 5, ManagementAPI.Tournament.TournamentFormat tournamentFormat = ManagementAPI.Tournament.TournamentFormat.Strokeplay)
        {
            TournamentAggregate aggregate = TournamentAggregate.Create(TournamentTestData.AggregateId);

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

            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);

            aggregate.CalculateCSS();

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

            Should.Throw <InvalidOperationException>(() => { aggregate.CalculateCSS(); });
        }
        public void TournamentAggregate_CalculateCSS_TournamentNotCompleted_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            Should.Throw <InvalidOperationException>(() => { aggregate.CalculateCSS(); });
        }