public void EstateAggregate_AddSecurityUserToEstate_SecurityUserIsAdded() { EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId); aggregate.Create(TestData.EstateName); aggregate.AddSecurityUser(TestData.SecurityUserId, TestData.EstateUserEmailAddress); }
public void EstateAggregate_AddSecurityUserToEstate_EstateNotCreated_ErrorThrown() { EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId); InvalidOperationException exception = Should.Throw <InvalidOperationException>(() => { aggregate.AddSecurityUser(TestData.SecurityUserId, TestData.EstateUserEmailAddress); }); exception.Message.ShouldContain("Estate has not been created"); }
public void EstateAggregate_GetEstate_WithASecurityUser_EstateIsReturned() { EstateAggregate aggregate = EstateAggregate.Create(TestData.EstateId); aggregate.Create(TestData.EstateName); aggregate.AddSecurityUser(TestData.SecurityUserId, TestData.EstateUserEmailAddress); Estate model = aggregate.GetEstate(); model.EstateId.ShouldBe(TestData.EstateId); model.Name.ShouldBe(TestData.EstateName); model.SecurityUsers.ShouldHaveSingleItem(); SecurityUser securityUser = model.SecurityUsers.Single(); securityUser.SecurityUserId.ShouldBe(TestData.SecurityUserId); securityUser.EmailAddress.ShouldBe(TestData.EstateUserEmailAddress); }
/// <summary> /// Creates the estate user. /// </summary> /// <param name="estateId">The estate identifier.</param> /// <param name="emailAddress">The email address.</param> /// <param name="password">The password.</param> /// <param name="givenName">Name of the given.</param> /// <param name="middleName">Name of the middle.</param> /// <param name="familyName">Name of the family.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <Guid> CreateEstateUser(Guid estateId, String emailAddress, String password, String givenName, String middleName, String familyName, CancellationToken cancellationToken) { EstateAggregate estateAggregate = await this.EstateAggregateRepository.GetLatestVersion(estateId, cancellationToken); CreateUserRequest createUserRequest = new CreateUserRequest { EmailAddress = emailAddress, FamilyName = familyName, GivenName = givenName, MiddleName = middleName, Password = password, PhoneNumber = "123456", // Is this really needed :| Roles = new List <String>(), Claims = new Dictionary <String, String>() }; // Check if role has been overridden String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName"); createUserRequest.Roles.Add(String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName); createUserRequest.Claims.Add("estateId", estateId.ToString()); CreateUserResponse createUserResponse = await this.SecurityServiceClient.CreateUser(createUserRequest, cancellationToken); // Add the user to the aggregate estateAggregate.AddSecurityUser(createUserResponse.UserId, emailAddress); // TODO: add a delete user here in case the aggregate add fails... await this.EstateAggregateRepository.SaveChanges(estateAggregate, cancellationToken); return(createUserResponse.UserId); }