public async Task Should_return_bad_request_when_hearing_id_is_empty() { //Arrange _request = BuildRequest(); //Act var response = await Controller.UpdateHearingParticipants(Guid.Empty, _request) as BadRequestObjectResult; //Assert response.Should().BeOfType <BadRequestObjectResult>(); ((SerializableError)response.Value).ContainsKeyAndErrorMessage(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}"); }
public async Task Should_add_given_participants_to_hearing_and_PublishParticipantsAddedEvent_if_several_matching_participant_with_username() { var hearing = GetVideoHearing(true); QueryHandler.Setup(q => q.Handle <GetHearingByIdQuery, VideoHearing>(It.IsAny <GetHearingByIdQuery>())).ReturnsAsync(hearing); _request = BuildRequest(withLinkedParticipants: false); var response = await Controller.UpdateHearingParticipants(hearingId, _request); response.Should().NotBeNull(); EventPublisher.Verify(e => e.PublishAsync(It.IsAny <HearingParticipantsUpdatedIntegrationEvent>()), Times.Once); }
public async Task Should_return_not_found_when_hearing_cannot_be_found() { //Arrange QueryHandler .Setup(x => x.Handle <GetHearingByIdQuery, VideoHearing>(It.IsAny <GetHearingByIdQuery>())) .ReturnsAsync((VideoHearing)null); _request = BuildRequest(); //Act var response = await Controller.UpdateHearingParticipants(hearingId, _request) as NotFoundResult; //Assert response.Should().BeOfType <NotFoundResult>(); }
public async Task Should_return_bad_request_for_given_invalid_representative_info() { //Arrange _request = BuildRequest(); _request.NewParticipants[0].HearingRoleName = "Litigant in person"; _request.NewParticipants[0].Representee = string.Empty; //Act var response = await Controller.UpdateHearingParticipants(hearingId, _request) as BadRequestObjectResult; response.Should().NotBeNull(); response.Should().BeOfType <BadRequestObjectResult>(); ((SerializableError)response.Value).ContainsKeyAndErrorMessage("Representee", "Representee is required"); }
public async Task Should_call_update_hearing_participants_command() { //Arrange _request = BuildRequest(); //Act var response = await Controller.UpdateHearingParticipants(hearingId, _request) as NoContentResult; //Assert CommandHandler.Verify(ch => ch.Handle(It.Is <UpdateHearingParticipantsCommand>(x => x.HearingId == hearingId && x.ExistingParticipants[0].DisplayName == _request.ExistingParticipants[0].DisplayName && x.ExistingParticipants[0].OrganisationName == _request.ExistingParticipants[0].OrganisationName && x.ExistingParticipants[0].ParticipantId == _request.ExistingParticipants[0].ParticipantId && x.ExistingParticipants[0].RepresentativeInformation.Representee == _request.ExistingParticipants[0].Representee && x.ExistingParticipants[0].TelephoneNumber == _request.ExistingParticipants[0].TelephoneNumber && x.ExistingParticipants[0].Title == _request.ExistingParticipants[0].Title && x.NewParticipants[0].CaseRole.Name == _request.NewParticipants[0].CaseRoleName && x.NewParticipants[0].DisplayName == _request.NewParticipants[0].DisplayName && x.NewParticipants[0].HearingRole.Name == _request.NewParticipants[0].HearingRoleName && x.NewParticipants[0].Representee == _request.NewParticipants[0].Representee && x.NewParticipants[0].Person.ContactEmail == _request.NewParticipants[0].ContactEmail && x.NewParticipants[0].Person.FirstName == _request.NewParticipants[0].FirstName && x.NewParticipants[0].Person.LastName == _request.NewParticipants[0].LastName && x.NewParticipants[0].Person.MiddleNames == _request.NewParticipants[0].MiddleNames && x.NewParticipants[0].Person.TelephoneNumber == _request.NewParticipants[0].TelephoneNumber && x.NewParticipants[0].Person.Title == _request.NewParticipants[0].Title && x.RemovedParticipantIds[0] == _request.RemovedParticipantIds[0] && x.LinkedParticipants[0].LinkedParticipantContactEmail == _request.LinkedParticipants[0].LinkedParticipantContactEmail && x.LinkedParticipants[0].ParticipantContactEmail == _request.LinkedParticipants[0].ParticipantContactEmail )), Times.Once); response.Should().BeOfType <NoContentResult>(); }
public async Task <IActionResult> UpdateHearingParticipants(Guid hearingId, [FromBody] UpdateHearingParticipantsRequest request) { if (hearingId == Guid.Empty) { ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}"); return(BadRequest(ModelState)); } var result = new UpdateHearingParticipantsRequestValidation().Validate(request); if (!result.IsValid) { ModelState.AddFluentValidationErrors(result.Errors); return(BadRequest(ModelState)); } var query = new GetHearingByIdQuery(hearingId); var videoHearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(query); if (videoHearing == null) { return(NotFound()); } var caseTypequery = new GetCaseTypeQuery(videoHearing.CaseType.Name); var caseType = await _queryHandler.Handle <GetCaseTypeQuery, CaseType>(caseTypequery); var representativeRoles = caseType.CaseRoles.SelectMany(x => x.HearingRoles).Where(x => x.UserRole.IsRepresentative).Select(x => x.Name).ToList(); var representatives = request.NewParticipants.Where(x => representativeRoles.Contains(x.HearingRoleName)).ToList(); var representativeValidationResult = RepresentativeValidationHelper.ValidateRepresentativeInfo(representatives); if (!representativeValidationResult.IsValid) { ModelState.AddFluentValidationErrors(representativeValidationResult.Errors); return(BadRequest(ModelState)); } var newParticipants = request.NewParticipants .Select(x => ParticipantRequestToNewParticipantMapper.Map(x, videoHearing.CaseType)).ToList(); var existingParticipants = request.ExistingParticipants .Select(x => new ExistingParticipantDetails { DisplayName = x.DisplayName, OrganisationName = x.OrganisationName, ParticipantId = x.ParticipantId, RepresentativeInformation = new RepresentativeInformation { Representee = x.Representee }, TelephoneNumber = x.TelephoneNumber, Title = x.Title }).ToList(); var linkedParticipants = LinkedParticipantRequestToLinkedParticipantDtoMapper.MapToDto(request.LinkedParticipants); var command = new UpdateHearingParticipantsCommand(hearingId, existingParticipants, newParticipants, request.RemovedParticipantIds, linkedParticipants); try { await _commandHandler.Handle(command); } catch (DomainRuleException e) { ModelState.AddDomainRuleErrors(e.ValidationFailures); return(BadRequest(ModelState)); } var hearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(query); // Publish this event if the hearing is ready for video if (hearing.Status == BookingStatus.Created) { await PublishUpdateHearingParticipantsEvent(hearing, existingParticipants, newParticipants, request.RemovedParticipantIds, linkedParticipants); } return(NoContent()); }