public void TournamentAggregate_ProduceResult_ResultIsProduced()
        {
            TournamentAggregate tournamentAggregate = TournamentTestData.GetCompletedTournamentAggregateWithCSSCalculatedAggregate(20, 15, 23, 16, 0, 5);

            tournamentAggregate.ProduceResult();

            tournamentAggregate.HasResultBeenProduced.ShouldBeTrue();

            List <PlayerScoreRecordDataTransferObject> scores = tournamentAggregate.GetScores();

            scores.Any(s => s.Last9HolesScore == 0).ShouldBeFalse();
            scores.Any(s => s.Last6HolesScore == 0).ShouldBeFalse();
            scores.Any(s => s.Last3HolesScore == 0).ShouldBeFalse();
            scores.Any(s => s.TournamentDivision == 0).ShouldBeFalse();
            scores.Any(s => s.Position == 0).ShouldBeFalse();
            scores.Any(s => s.MeasuredCourseId == Guid.Empty).ShouldBeFalse();
            scores.Any(s => s.PlayerId == Guid.Empty).ShouldBeFalse();
            scores.Any(s => s.NetScore == 0).ShouldBeFalse();
            scores.Any(s => s.GrossScore == 0).ShouldBeFalse();
            scores.Any(s => s.PlayingHandicap < 0).ShouldBeFalse();
            scores.Any(s => s.PlayingHandicap > 36).ShouldBeFalse();
            scores.Any(s => s.TournamentId == Guid.Empty).ShouldBeFalse();
            scores.Any(s => s.ScoreDate == DateTime.MinValue).ShouldBeFalse();
            scores.Any(s => s.GolfClubId == Guid.Empty).ShouldBeFalse();
            scores.Any(s => s.HandicapCategory == 0).ShouldBeFalse();
            scores.Any(s => s.HoleScores.Count() != 18).ShouldBeFalse();
            scores.Any(s => s.CSS == 0).ShouldBeFalse();
        }
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task HandleCommand(ProduceTournamentResultCommand command,
                                         CancellationToken cancellationToken)
        {
            // Rehydrate the aggregate
            TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken);

            // Produce the result
            tournament.ProduceResult();

            // Save the changes
            await this.TournamentRepository.SaveChanges(tournament, cancellationToken);
        }
        public void TournamentAggregate_ProduceResult_UnsupportedFormat_ErrorThrown()
        {
            TournamentAggregate tournamentAggregate = TournamentTestData.GetCompletedTournamentAggregateWithCSSCalculatedAggregate(20, 15, 23, 16, 0, 5, TournamentFormat.Stableford);

            Should.Throw <NotSupportedException>(() => tournamentAggregate.ProduceResult());
        }
        public void TournamentAggregate_ProduceResult_CSSNotCalculated_ErrorThrown()
        {
            TournamentAggregate tournamentAggregate = TournamentTestData.GetCompletedTournamentAggregate(20, 15, 23, 16, 0, 5);

            Should.Throw <InvalidOperationException>(() => tournamentAggregate.ProduceResult());
        }