/// <summary> /// Handles the command. /// </summary> /// <param name="command">The command.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task HandleCommand(CreateMatchSecretaryCommand command, CancellationToken cancellationToken) { Guid golfClubAggregateId = command.GolfClubId; // Rehydrate the aggregate GolfClubAggregate golfClubAggregate = await this.GolfClubRepository.GetLatestVersion(golfClubAggregateId, cancellationToken); // Create the user RegisterUserRequest registerUserRequest = new RegisterUserRequest { EmailAddress = command.CreateMatchSecretaryRequest.EmailAddress, Claims = new Dictionary <String, String> { { "GolfClubId", golfClubAggregateId.ToString() } }, Password = "******", PhoneNumber = command.CreateMatchSecretaryRequest.TelephoneNumber, MiddleName = command.CreateMatchSecretaryRequest.MiddleName, FamilyName = command.CreateMatchSecretaryRequest.FamilyName, GivenName = command.CreateMatchSecretaryRequest.GivenName, Roles = new List <String> { RoleNames.MatchSecretary } }; // Create the user RegisterUserResponse registerUserResponse = await this.OAuth2SecurityService.RegisterUser(registerUserRequest, cancellationToken); // Record against the aggregate golfClubAggregate.CreateMatchSecretarySecurityUser(registerUserResponse.UserId); // Save the changes await this.GolfClubRepository.SaveChanges(golfClubAggregate, cancellationToken); }
public void GolfClubAggregate_CreateMatchSecretarySecurityUser_MatchSecretaryUserAdded() { GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregate(); Should.NotThrow(() => { aggregate.CreateMatchSecretarySecurityUser(GolfClubTestData.MatchSecretarySecurityUserId); }); }
public void GolfClubAggregate_CreateMatchSecretarySecurityUser_DuplicateSecurityUserId() { GolfClubAggregate aggregate = GolfClubTestData.GetCreatedGolfClubAggregateWithMatchSecretaryUser(); Should.Throw <InvalidOperationException>(() => { aggregate.CreateMatchSecretarySecurityUser(GolfClubTestData.MatchSecretarySecurityUserId); }); }
public void GolfClubAggregate_CreateMatchSecretarySecurityUser_InvalidData_ErrorThrown() { GolfClubAggregate aggregate = GolfClubTestData.GetEmptyGolfClubAggregate(); Should.Throw <ArgumentNullException>(() => { aggregate.CreateMatchSecretarySecurityUser(Guid.Empty); }); }
public void GolfClubAggregate_CreateMatchSecretarySecurityUser_ClubNotCreated_ErrorThrown() { GolfClubAggregate aggregate = GolfClubTestData.GetEmptyGolfClubAggregate(); Should.Throw <InvalidOperationException>(() => { aggregate.CreateMatchSecretarySecurityUser(GolfClubTestData.MatchSecretarySecurityUserId); }); }