/// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task HandleCommand(CreateGolfClubCommand command,
                                         CancellationToken cancellationToken)
        {
            Guid golfClubAggregateId = command.GolfClubId;

            // Rehydrate the aggregate
            GolfClubAggregate golfClubAggregate = await this.GolfClubRepository.GetLatestVersion(golfClubAggregateId, cancellationToken);

            // Call the aggregate method
            golfClubAggregate.CreateGolfClub(command.CreateGolfClubRequest.Name,
                                             command.CreateGolfClubRequest.AddressLine1,
                                             command.CreateGolfClubRequest.AddressLine2,
                                             command.CreateGolfClubRequest.Town,
                                             command.CreateGolfClubRequest.Region,
                                             command.CreateGolfClubRequest.PostalCode,
                                             command.CreateGolfClubRequest.TelephoneNumber,
                                             command.CreateGolfClubRequest.Website,
                                             command.CreateGolfClubRequest.EmailAddress);

            // Record club admin user against aggregate
            golfClubAggregate.CreateGolfClubAdministratorSecurityUser(command.SecurityUserId);

            // Save the changes
            await this.GolfClubRepository.SaveChanges(golfClubAggregate, cancellationToken);

            // Setup the response
            command.Response = new CreateGolfClubResponse
            {
                GolfClubId = golfClubAggregateId
            };
        }
        public void GolfClubAggregate_CreateGolfClubAdministratorSecurityUser_GolfClubAdministratorSecurityUserCreated()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            aggregate.CreateGolfClubAdministratorSecurityUser(GolfClubTestData.GolfClubAdministratorSecurityUserId);

            aggregate.GolfClubAdministratorSecurityUserId.ShouldBe(GolfClubTestData.GolfClubAdministratorSecurityUserId);
            aggregate.HasAdminSecurityUserBeenCreated.ShouldBeTrue();
        }
        public void GolfClubAggregate_CreateGolfClubAdministratorSecurityUser_InvalidData_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate();

            Should.Throw <ArgumentNullException>(() => { aggregate.CreateGolfClubAdministratorSecurityUser(Guid.Empty); });
        }
        public void GolfClubAggregate_CreateGolfClubAdministratorSecurityUser_ClubNotCreated_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetEmptyGolfClubAggregate();

            Should.Throw <InvalidOperationException>(() => { aggregate.CreateGolfClubAdministratorSecurityUser(GolfClubTestData.GolfClubAdministratorSecurityUserId); });
        }
        public void GolfClubAggregate_CreateGolfClubAdministratorSecurityUser_AdminSecurityUserAlreadyCreated_ErrorThrown()
        {
            GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregateWithGolfClubAdministratorUser();

            Should.Throw <InvalidOperationException>(() => { aggregate.CreateGolfClubAdministratorSecurityUser(GolfClubTestData.GolfClubAdministratorSecurityUserId); });
        }