public async Task <Guid> HandleAsync(JoinOrganisation message) { authorization.EnsureCanAccessExternalArea(); var userId = userContext.UserId; if (!await dataAccess.DoesUserExist(userId)) { throw new ArgumentException(string.Format("Could not find a user with id {0}", userId)); } if (!await dataAccess.DoesOrganisationExist(message.OrganisationId)) { throw new ArgumentException(string.Format("Could not find an organisation with id {0}", message.OrganisationId)); } var organisationUser = new OrganisationUser(userId, message.OrganisationId, Domain.User.UserStatus.Pending); var result = await dataAccess.JoinOrganisation(organisationUser); if (!result.Successful) { throw new InvalidOperationException(result.ErrorMessage); } return(message.OrganisationId); }
public async Task JoinOrganisationHandler_UserDoesExist_ButOrganisationDoesNotExist_ShouldVerifyAuthorization_AndThrowArgumentException() { A.CallTo(() => userContext.UserId) .Returns(Guid.NewGuid()); A.CallTo(() => dataAccess.DoesUserExist(A <Guid> ._)) .Returns(true); A.CallTo(() => dataAccess.DoesOrganisationExist(A <Guid> ._)) .Returns(false); await Assert.ThrowsAnyAsync <ArgumentException>( () => JoinOrganisationHandler().HandleAsync(new JoinOrganisation(Guid.NewGuid()))); A.CallTo(() => weeeAuthorization.EnsureCanAccessExternalArea()) .MustHaveHappened(); }