public void TournamentAggregate_CancelTournament_InvalidData_ErrorThrown(Boolean validCancellationDate,
                                                                                 String cancellationReason)
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            DateTime cancellationDateTime = validCancellationDate ? TournamentTestData.CancelledDateTime : DateTime.MinValue;

            Should.Throw <ArgumentNullException>(() => { aggregate.CancelTournament(cancellationDateTime, cancellationReason); });
        }
        public void TournamentAggregate_CancelTournament_TournamentComplete()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate();

            aggregate.CancelTournament(TournamentTestData.CancelledDateTime, TournamentTestData.CancellationReason);

            aggregate.HasBeenCancelled.ShouldBeTrue();
            aggregate.CancelledDateTime.ShouldBe(TournamentTestData.CancelledDateTime);
            aggregate.CancelledReason.ShouldBe(TournamentTestData.CancellationReason);
        }
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task HandleCommand(CancelTournamentCommand command,
                                         CancellationToken cancellationToken)
        {
            // Rehydrate the aggregate
            TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken);

            DateTime cancelledDateTime = DateTime.Now;

            tournament.CancelTournament(cancelledDateTime, command.CancelTournamentRequest.CancellationReason);

            // Save the changes
            await this.TournamentRepository.SaveChanges(tournament, cancellationToken);
        }
        public static TournamentAggregate GetCancelledTournamentAggregate()
        {
            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);

            aggregate.CancelTournament(TournamentTestData.CancelledDateTime, TournamentTestData.CancellationReason);

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

            Should.Throw <InvalidOperationException>(() => { aggregate.CancelTournament(TournamentTestData.CancelledDateTime, TournamentTestData.CancellationReason); });
        }
        public void TournamentAggregate_CancelTournament_TournamentAlreadyCompleted_ErrorThrown()
        {
            TournamentAggregate aggregate = TournamentTestData.GetCompletedTournamentAggregate(1, 2, 7, 20, 5, 5);

            Should.Throw <InvalidOperationException>(() => { aggregate.CancelTournament(TournamentTestData.CancelledDateTime, TournamentTestData.CancellationReason); });
        }