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 void Should_map_all_properties()
        {
            var refDataBuilder = new RefDataBuilder();
            var venue          = refDataBuilder.HearingVenues.First(x => x.Name == _hearingVenueName);
            var caseType       = new CaseType(1, _caseTypeName);
            var hearingType    = Builder <HearingType> .CreateNew().WithFactory(() => new HearingType(_hearingTypeName)).Build();

            var        scheduledDateTime        = DateTime.Today.AddDays(1).AddHours(11).AddMinutes(45);
            var        duration                 = 80;
            var        hearingRoomName          = "Roome03";
            var        otherInformation         = "OtherInformation03";
            var        createdBy                = "User03";
            const bool questionnaireNotRequired = false;
            const bool audioRecordingRequired   = true;
            var        cancelReason             = "Online abandonment (incomplete registration)";

            var hearing = new VideoHearing(caseType, hearingType, scheduledDateTime, duration, venue, hearingRoomName,
                                           otherInformation, createdBy, questionnaireNotRequired, audioRecordingRequired, cancelReason);

            _videoHearing = Builder <VideoHearing> .CreateNew().WithFactory(() =>
                                                                            hearing).Build();

            var applicantCaseRole       = new CaseRole(1, "Applicant");
            var applicantLipHearingRole = new HearingRole(1, "Litigant in person")
            {
                UserRole = new UserRole(1, "Individual")
            };

            _videoHearing.AddCase("0875", "Test Case Add", false);

            var person1 = new PersonBuilder(true).Build();

            _videoHearing.AddIndividual(person1, applicantLipHearingRole, applicantCaseRole,
                                        $"{person1.FirstName} {person1.LastName}");

            var party = _videoHearing.GetParticipants().FirstOrDefault();

            party.SetProtected(nameof(party.CaseRole), applicantCaseRole);
            party.SetProtected(nameof(party.HearingRole), applicantLipHearingRole);

            var endpoints = new Endpoint("displayName", "333", "200", null);

            _videoHearing.AddEndpoint(endpoints);

            // Set the navigation properties as well since these would've been set if we got the hearing from DB
            _videoHearing.SetProtected(nameof(_videoHearing.HearingType), hearingType);
            _videoHearing.SetProtected(nameof(_videoHearing.CaseType), caseType);
            _videoHearing.SetProtected(nameof(_videoHearing.HearingVenue), venue);

            var response = _mapper.MapHearingToDetailedResponse(_videoHearing);

            response.Should().BeEquivalentTo(response, options => options
                                             .Excluding(v => v.Id)
                                             );
        }
        public BookingsHearingResponse MapHearingResponse(VideoHearing videoHearing)
        {
            var @case = videoHearing.GetCases().FirstOrDefault();

            if (@case == null)
            {
                throw new ArgumentException("Hearing is missing case");
            }

            if (videoHearing.CaseType == null)
            {
                throw new ArgumentException("Hearing is missing case type");
            }
            if (videoHearing.HearingType == null)
            {
                throw new ArgumentException("Hearing is missing hearing type");
            }

            var judgeParticipant = videoHearing.GetParticipants().FirstOrDefault(s => s.HearingRole?.UserRole != null && s.HearingRole.UserRole.Name == "Judge");
            var judgeName        = judgeParticipant != null ? judgeParticipant.DisplayName : string.Empty;
            var courtRoomAccount = judgeParticipant != null ? judgeParticipant.Person.Username : string.Empty;

            var response = new BookingsHearingResponse
            {
                HearingId                = videoHearing.Id,
                HearingNumber            = @case.Number,
                HearingName              = @case.Name,
                ScheduledDuration        = videoHearing.ScheduledDuration,
                ScheduledDateTime        = videoHearing.ScheduledDateTime,
                HearingTypeName          = videoHearing.HearingType.Name,
                CaseTypeName             = videoHearing.CaseType.Name,
                CourtAddress             = videoHearing.HearingVenueName,
                CourtRoom                = videoHearing.HearingRoomName,
                CreatedDate              = videoHearing.CreatedDate,
                CreatedBy                = videoHearing.CreatedBy,
                LastEditDate             = videoHearing.UpdatedDate,
                LastEditBy               = videoHearing.UpdatedBy,
                ConfirmedBy              = videoHearing.ConfirmedBy,
                ConfirmedDate            = videoHearing.ConfirmedDate,
                JudgeName                = judgeName,
                Status                   = videoHearing.Status.MapToContractEnum(),
                QuestionnaireNotRequired = videoHearing.QuestionnaireNotRequired,
                AudioRecordingRequired   = videoHearing.AudioRecordingRequired,
                CancelReason             = videoHearing.CancelReason,
                GroupId                  = videoHearing.SourceId,
                CourtRoomAccount         = courtRoomAccount
            };

            return(response);
        }
        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);
            }
        }
Beispiel #5
0
        public async Task Handle(CreateVideoHearingCommand command)
        {
            var videoHearing = new VideoHearing(command.CaseType, command.HearingType, command.ScheduledDateTime,
                                                command.ScheduledDuration, command.Venue, command.HearingRoomName,
                                                command.OtherInformation, command.CreatedBy, command.QuestionnaireNotRequired,
                                                command.AudioRecordingRequired, command.CancelReason);

            // denotes this hearing is cloned
            if (command.SourceId.HasValue)
            {
                videoHearing.SourceId = command.SourceId;
            }

            await _context.VideoHearings.AddAsync(videoHearing);

            var participants = await _hearingService.AddParticipantToService(videoHearing, command.Participants);

            await _hearingService.CreateParticipantLinks(participants, command.LinkedParticipants);

            videoHearing.AddCases(command.Cases);

            if (command.Endpoints != null && command.Endpoints.Count > 0)
            {
                var dtos         = command.Endpoints;
                var newEndpoints = (from dto in dtos
                                    let defenceAdvocate =
                                        DefenceAdvocateHelper.CheckAndReturnDefenceAdvocate(dto.DefenceAdvocateUsername,
                                                                                            videoHearing.GetParticipants())
                                        select new Endpoint(dto.DisplayName, dto.Sip, dto.Pin, defenceAdvocate)).ToList();

                videoHearing.AddEndpoints(newEndpoints);
            }

            await _context.SaveChangesAsync();

            command.NewHearingId = videoHearing.Id;
        }