public async Task Should_return_missing_representee_error() { var request = BuildRequest(); request.HearingRoleName = "Representative"; request.Representee = string.Empty; var result = await _representativeValidator.ValidateAsync(request); result.IsValid.Should().BeFalse(); result.Errors.Count.Should().Be(1); result.Errors.Any(x => x.ErrorMessage == RepresentativeValidation.NoRepresentee) .Should().BeTrue(); }
public async Task <IActionResult> UpdateParticipantDetails(Guid hearingId, Guid participantId, [FromBody] UpdateParticipantRequest request) { if (hearingId == Guid.Empty) { ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}"); return(BadRequest(ModelState)); } if (participantId == Guid.Empty) { ModelState.AddModelError(nameof(participantId), $"Please provide a valid {nameof(participantId)}"); return(BadRequest(ModelState)); } var result = await new UpdateParticipantRequestValidation().ValidateAsync(request); if (!result.IsValid) { ModelState.AddFluentValidationErrors(result.Errors); return(BadRequest(ModelState)); } var getHearingByIdQuery = new GetHearingByIdQuery(hearingId); var videoHearing = await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(getHearingByIdQuery); if (videoHearing == null) { return(NotFound()); } Participant participant = null; var participants = videoHearing.GetParticipants(); if (participants != null) { participant = participants.SingleOrDefault(x => x.Id.Equals(participantId)); } if (participant == null) { return(NotFound()); } if (participant.HearingRole.UserRole.IsRepresentative) { var test = new RepresentativeValidation(); await test.ValidateAsync(request); var repValidationResult = await new RepresentativeValidation().ValidateAsync(request); if (!repValidationResult.IsValid) { ModelState.AddFluentValidationErrors(result.Errors); return(BadRequest(ModelState)); } } var representative = UpdateParticipantRequestToNewRepresentativeMapper.MapRequestToNewRepresentativeInfo(request); var linkedParticipants = LinkedParticipantRequestToLinkedParticipantDtoMapper.MapToDto(request.LinkedParticipants); var updateParticipantCommand = new UpdateParticipantCommand(hearingId, participantId, request.Title, request.DisplayName, request.TelephoneNumber, request.OrganisationName, representative, linkedParticipants); await _commandHandler.Handle(updateParticipantCommand); var updatedParticipant = updateParticipantCommand.UpdatedParticipant; var participantMapper = new ParticipantToResponseMapper(); ParticipantResponse response = null; if (updatedParticipant != null) { response = participantMapper.MapParticipantToResponse(updatedParticipant); } // ONLY publish this event when Hearing is set for ready for video if (videoHearing.Status == BookingStatus.Created) { await _eventPublisher.PublishAsync(new ParticipantUpdatedIntegrationEvent(hearingId, updatedParticipant)); } return(Ok(response)); }