public void GolfClubAggregate_AddTournamentDivision_NullTournamentDivision_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = null;

            Should.Throw <ArgumentNullException>(() => { aggregate.AddTournamentDivision(tournamentDivision); });
        }
        public void GolfClubAggregate_AddTournamentDivision_DivisionAdded()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = GolfClubTestData.GetTournamentDivision1();

            Should.NotThrow(() => { aggregate.AddTournamentDivision(tournamentDivision); });
        }
        public void GolfClubAggregate_AddTournamentDivision_ClubNotCreated_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetEmptyGolfClubAggregate();
            TournamentDivisionDataTransferObject tournamentDivision = GolfClubTestData.GetTournamentDivision1();

            Should.Throw <InvalidOperationException>(() => { aggregate.AddTournamentDivision(tournamentDivision); });
        }
        public void GolfClubAggregate_AddTournamentDivision_DuplicateDivision_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = GolfClubTestData.GetTournamentDivision1();

            aggregate.AddTournamentDivision(tournamentDivision);

            Should.Throw <InvalidOperationException>(() => { aggregate.AddTournamentDivision(tournamentDivision); });
        }
        public void GolfClubAggregate_AddTournamentDivision_InvalidDivisionData_ErrorThrown(Int32 division,
                                                                                            Int32 startHandicap,
                                                                                            Int32 endHandicap,
                                                                                            Type exceptionType)
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = new TournamentDivisionDataTransferObject
            {
                Division      = division,
                EndHandicap   = endHandicap,
                StartHandicap = startHandicap
            };

            Should.Throw(() => { aggregate.AddTournamentDivision(tournamentDivision); }, exceptionType);
        }
        public void GolfClubAggregate_AddTournamentDivision_DivisionStartHandicapClashesWithExistingRange_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse();
            TournamentDivisionDataTransferObject tournamentDivision = GolfClubTestData.GetTournamentDivision1();

            aggregate.AddTournamentDivision(tournamentDivision);

            TournamentDivisionDataTransferObject tournamentDivisionInvalid = new TournamentDivisionDataTransferObject
            {
                Division      = 2,
                EndHandicap   = 12,
                StartHandicap = GolfClubTestData.GetTournamentDivision1().StartHandicap
            };

            Should.Throw <InvalidDataException>(() => { aggregate.AddTournamentDivision(tournamentDivisionInvalid); });
        }
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task HandleCommand(AddTournamentDivisionToGolfClubCommand command,
                                         CancellationToken cancellationToken)
        {
            // Rehydrate the aggregate
            GolfClubAggregate golfClubAggregate = await this.GolfClubRepository.GetLatestVersion(command.GolfClubId, cancellationToken);

            // Create the dto from the request in the command
            TournamentDivisionDataTransferObject tournamentDivisionDataTransferObject = new TournamentDivisionDataTransferObject
            {
                Division      = command.AddTournamentDivisionToGolfClubRequest.Division,
                StartHandicap = command.AddTournamentDivisionToGolfClubRequest.StartHandicap,
                EndHandicap   = command.AddTournamentDivisionToGolfClubRequest.EndHandicap
            };

            golfClubAggregate.AddTournamentDivision(tournamentDivisionDataTransferObject);

            await this.GolfClubRepository.SaveChanges(golfClubAggregate, cancellationToken);
        }