public async Task Should_change_judge() { //Arrange var judgeCaseRole = _genericCaseType.CaseRoles.First(x => x.Name == "Judge"); var judgeHearingRole = judgeCaseRole.HearingRoles.First(x => x.Name == "Judge"); var oldJudgeId = _hearing.GetParticipants().SingleOrDefault(x => x.HearingRole.Id == judgeHearingRole.Id).Id; var newJudge = new PersonBuilder(true).Build(); var newParticipant = new NewParticipant() { Person = newJudge, CaseRole = judgeCaseRole, HearingRole = judgeHearingRole, DisplayName = $"{newJudge.FirstName} {newJudge.LastName}" }; _removedParticipantIds.Add(oldJudgeId); _newParticipants.Add(newParticipant); _command = BuildCommand(); //Act await _handler.Handle(_command); var updatedVideoHearing = await _getHearingByIdQueryHandler.Handle(new GetHearingByIdQuery(_hearing.Id)); var addedJudge = updatedVideoHearing.GetParticipants().SingleOrDefault(x => x.HearingRole.Id == judgeHearingRole.Id); //Assert addedJudge.Person.FirstName.Should().Be(newJudge.FirstName); addedJudge.Person.LastName.Should().Be(newJudge.LastName); }
public async Task Should_add_participants_to_video_hearing() { //Arrange var originalParticipantCount = _hearing.GetParticipants().Count; var applicantCaseRole = _genericCaseType.CaseRoles.First(x => x.Name == "Applicant"); var applicantRepresentativeHearingRole = applicantCaseRole.HearingRoles.First(x => x.Name == "Representative"); var newPerson = new PersonBuilder(true).Build(); var newParticipant = new NewParticipant() { Person = newPerson, CaseRole = applicantCaseRole, HearingRole = applicantRepresentativeHearingRole, DisplayName = $"{newPerson.FirstName} {newPerson.LastName}", Representee = string.Empty }; _newParticipants.Add(newParticipant); _command = BuildCommand(); //Act await _handler.Handle(_command); var updatedVideoHearing = await _getHearingByIdQueryHandler.Handle(new GetHearingByIdQuery(_hearing.Id)); var newParticipantCount = updatedVideoHearing.GetParticipants().Count; //Assert newParticipantCount.Should().Be(originalParticipantCount + 1); }
public async Task Should_add_participant_links() { //Arrange var unlinkedParticipants = _hearing.Participants.Where(x => !x.LinkedParticipants.Any()).ToList(); var primaryParticipant = unlinkedParticipants[0]; var secondaryParticipant = unlinkedParticipants[1]; _linkedParticipants = new List <LinkedParticipantDto> { new LinkedParticipantDto(primaryParticipant.Person.ContactEmail, secondaryParticipant.Person.ContactEmail, LinkedParticipantType.Interpreter) }; _command = BuildCommand(); //Act await _handler.Handle(_command); var updatedVideoHearing = await _getHearingByIdQueryHandler.Handle(new GetHearingByIdQuery(_hearing.Id)); var linkedPrimaryParticipant = updatedVideoHearing.Participants.SingleOrDefault(x => x.Id == primaryParticipant.Id); var linkedSecondaryParticipant = updatedVideoHearing.Participants.SingleOrDefault(x => x.Id == secondaryParticipant.Id); linkedPrimaryParticipant.LinkedParticipants.Should().NotBeEmpty(); linkedPrimaryParticipant.LinkedParticipants[0].ParticipantId.Should().Be(primaryParticipant.Id); linkedPrimaryParticipant.LinkedParticipants[0].LinkedId.Should().Be(secondaryParticipant.Id); linkedSecondaryParticipant.LinkedParticipants.Should().NotBeEmpty(); linkedSecondaryParticipant.LinkedParticipants[0].ParticipantId.Should().Be(secondaryParticipant.Id); linkedSecondaryParticipant.LinkedParticipants[0].LinkedId.Should().Be(primaryParticipant.Id); }
public async Task Should_remove_participants() { //Arrange var participantToRemoveIdOne = _hearing.Participants.First(p => p.HearingRole.Name != "Judge").Id; var participantToRemoveIdTwo = _hearing.Participants.Last(p => p.HearingRole.Name != "Judge").Id; _removedParticipantIds = new List <Guid> { participantToRemoveIdOne, participantToRemoveIdTwo }; _command = BuildCommand(); //Act await _handler.Handle(_command); var updatedVideoHearing = await _getHearingByIdQueryHandler.Handle(new GetHearingByIdQuery(_hearing.Id)); var removedParticipantOne = (Representative)updatedVideoHearing.Participants.SingleOrDefault(x => x.Id == participantToRemoveIdOne); var removedParticipantTwo = (Representative)updatedVideoHearing.Participants.SingleOrDefault(x => x.Id == participantToRemoveIdTwo); removedParticipantOne.Should().BeNull(); removedParticipantTwo.Should().BeNull(); }
public void Should_throw_hearing_not_found_exception_when_hearing_does_not_exist() { //Arrange _command = BuildCommand(); _command.HearingId = Guid.Empty; //Act/Assert Assert.ThrowsAsync <HearingNotFoundException>(() => _handler.Handle(_command)); }
public void Should_throw_participant_not_found_exception_when_participant_does_not_exist() { //Arrange _existingParticipants.Add(new ExistingParticipantDetails { ParticipantId = Guid.Empty }); _command = BuildCommand(); //Act/Assert Assert.ThrowsAsync <ParticipantNotFoundException>(() => _handler.Handle(_command)); }
public async Task Should_update_participants_and_remove_any_existing_participant_links() { //Arrange _hearing = await Hooks.SeedVideoHearing(null, withLinkedParticipants : true); var beforeUpdatedDate = _hearing.UpdatedDate; var participantToUpdate = _hearing.GetParticipants().First(x => x.LinkedParticipants.Any()); var updateParticipantDetails = new ExistingParticipantDetails { DisplayName = "UpdatedDisplayName", OrganisationName = "UpdatedOrganisation", ParticipantId = participantToUpdate.Id, TelephoneNumber = "07123456789", Title = "UpdatedTitle" }; if (participantToUpdate.HearingRole.UserRole.IsRepresentative) { updateParticipantDetails.RepresentativeInformation = new RepresentativeInformation { Representee = "UpdatedRepresentee" }; } _existingParticipants.Add(updateParticipantDetails); _command = BuildCommand(); //Act await _handler.Handle(_command); var updatedVideoHearing = await _getHearingByIdQueryHandler.Handle(new GetHearingByIdQuery(_hearing.Id)); var updatedParticipant = updatedVideoHearing.Participants.SingleOrDefault(x => x.Id == participantToUpdate.Id); updatedParticipant.Should().NotBeNull(); updatedParticipant.UpdatedDate.Should().BeAfter(beforeUpdatedDate); updatedParticipant.Person.Title.Should().Be(updateParticipantDetails.Title); updatedParticipant.DisplayName.Should().Be(updateParticipantDetails.DisplayName); updatedParticipant.Person.TelephoneNumber.Should().Be(updateParticipantDetails.TelephoneNumber); updatedParticipant.Person.Organisation.Name.Should().Be(updateParticipantDetails.OrganisationName); updatedParticipant.LinkedParticipants.Should().BeEmpty(); if (participantToUpdate.HearingRole.UserRole.IsRepresentative) { ((Representative)updatedParticipant).Representee.Should() .Be(updateParticipantDetails.RepresentativeInformation.Representee); } }
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()); }