private void PersistTestHearingData(VideoHearing seededHearing)
 {
     _hearingId = seededHearing.Id;
     Context.TestData.NewHearingId  = seededHearing.Id;
     Context.TestData.SeededHearing = seededHearing;
     Context.TestData.TestContextData.Add(ExistingEndPoints, seededHearing.GetEndpoints());
 }
        public async Task <List <Participant> > AddParticipantToService(VideoHearing hearing, List <NewParticipant> participants)
        {
            var participantList = new List <Participant>();

            foreach (var participantToAdd in participants)
            {
                var existingPerson = await _context.Persons
                                     .Include("Organisation")
                                     .SingleOrDefaultAsync(x => x.Username == participantToAdd.Person.Username);

                switch (participantToAdd.HearingRole.UserRole.Name)
                {
                case "Individual":
                    var individual = hearing.AddIndividual(existingPerson ?? participantToAdd.Person, participantToAdd.HearingRole,
                                                           participantToAdd.CaseRole, participantToAdd.DisplayName);

                    UpdateOrganisationDetails(participantToAdd.Person, individual);
                    participantList.Add(individual);
                    break;

                case "Representative":
                {
                    var representative = hearing.AddRepresentative(existingPerson ?? participantToAdd.Person,
                                                                   participantToAdd.HearingRole,
                                                                   participantToAdd.CaseRole, participantToAdd.DisplayName,
                                                                   participantToAdd.Representee);

                    UpdateOrganisationDetails(participantToAdd.Person, representative);
                    participantList.Add(representative);
                    break;
                }

                case "Judicial Office Holder":
                {
                    var joh = hearing.AddJudicialOfficeHolder(existingPerson ?? participantToAdd.Person,
                                                              participantToAdd.HearingRole, participantToAdd.CaseRole, participantToAdd.DisplayName);

                    participantList.Add(joh);
                    break;
                }

                case "Judge":
                {
                    var judge = hearing.AddJudge(existingPerson ?? participantToAdd.Person,
                                                 participantToAdd.HearingRole,
                                                 participantToAdd.CaseRole, participantToAdd.DisplayName);

                    participantList.Add(judge);
                    break;
                }

                default:
                    throw new DomainRuleException(nameof(participantToAdd.HearingRole.UserRole.Name),
                                                  $"Role {participantToAdd.HearingRole.UserRole.Name} not recognised");
                }
            }

            return(participantList);
        }
 public static Dictionary <string, string> LogInfo(VideoHearing queriedVideoHearing)
 {
     return(new Dictionary <string, string>
     {
         { "HearingId", queriedVideoHearing.Id.ToString() },
         { "CaseType", queriedVideoHearing.CaseType?.Name },
         { "Participants.Count", queriedVideoHearing.Participants.Count.ToString() },
     });
 }
Exemplo n.º 4
0
        public async Task SeedVideoHearing(VideoHearing videoHearing)
        {
            await using var db = new BookingsDbContext(_dbContextOptions);
            await db.VideoHearings.AddAsync(videoHearing);

            await db.SaveChangesAsync();

            _seededHearings.Add(videoHearing.Id);
        }
        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)
                                             );
        }
Exemplo n.º 6
0
 public UpdateParticipantCommand(Guid participantId, string title, string displayName, string telphoneNumber,
                                 NewAddress address, string organisationName, VideoHearing videoHearing, RepresentativeInformation representativeInformation)
 {
     ParticipantId             = participantId;
     Title                     = title;
     DisplayName               = displayName;
     TelephoneNumber           = telphoneNumber;
     OrganisationName          = organisationName;
     NewAddress                = address;
     VideoHearing              = videoHearing;
     RepresentativeInformation = representativeInformation;
 }
Exemplo n.º 7
0
        private Participant Create(VideoHearing hearing, string fName, string lName, int addHour)
        {
            var participant = new Mock <Participant>();

            participant.SetupGet(p => p.Hearing).Returns(hearing);
            participant.SetupGet(p => p.Questionnaire).Returns(new Questionnaire {
                UpdatedDate = DateTime.Now.AddHours(addHour)
            });
            participant.SetupGet(p => p.Person).Returns(new Person("Mr", fName, lName, $"{fName} {lName}"));
            participant.SetupGet(p => p.HearingRole).Returns(new Bookings.Domain.RefData.HearingRole(1, "Test"));

            return(participant.Object);
        }
        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);
            }
        }
        protected VideoHearing GetVideoHearing(bool createdStatus = false)
        {
            Hearing = new VideoHearingBuilder().Build();
            Hearing.AddCase("123", "Case name", true);
            Hearing.CaseType = CaseType;

            if (createdStatus)
            {
                Hearing.UpdateStatus(BookingsApi.Domain.Enumerations.BookingStatus.Created, "administrator", string.Empty);
            }

            var endpoint = new Endpoint("one", $"{Guid.NewGuid().ToString()}{KinlyConfiguration.SipAddressStem}",
                                        "1234", null);

            Hearing.AddEndpoint(endpoint);
            return(Hearing);
        }
Exemplo n.º 11
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);

            _context.VideoHearings.Add(videoHearing);

            await _hearingService.AddParticipantToService(videoHearing, command.Participants);

            videoHearing.AddCases(command.Cases);

            await _context.SaveChangesAsync();

            command.NewHearingId = videoHearing.Id;
        }
Exemplo n.º 12
0
        public async Task AddParticipantToService(VideoHearing hearing, List <NewParticipant> participants)
        {
            foreach (var participantToAdd in participants)
            {
                var existingPerson = await _context.Persons
                                     .Include("Address")
                                     .Include("Organisation")
                                     .SingleOrDefaultAsync(x => x.Username == participantToAdd.Person.Username);

                switch (participantToAdd.HearingRole.UserRole.Name)
                {
                case "Individual":
                    var individual = hearing.AddIndividual(existingPerson ?? participantToAdd.Person, participantToAdd.HearingRole,
                                                           participantToAdd.CaseRole, participantToAdd.DisplayName);

                    UpdateAddressAndOrganisationDetails(participantToAdd.Person, individual);
                    break;

                case "Representative":
                {
                    var representative = hearing.AddRepresentative(existingPerson ?? participantToAdd.Person, participantToAdd.HearingRole,
                                                                   participantToAdd.CaseRole, participantToAdd.DisplayName,
                                                                   participantToAdd.Reference, participantToAdd.Representee);
                    UpdateAddressAndOrganisationDetails(participantToAdd.Person, representative);
                    break;
                }

                case "Judge":
                    hearing.AddJudge(existingPerson ?? participantToAdd.Person, participantToAdd.HearingRole,
                                     participantToAdd.CaseRole, participantToAdd.DisplayName);
                    break;

                default:
                    throw new DomainRuleException(nameof(participantToAdd.HearingRole.UserRole.Name),
                                                  $"Role {participantToAdd.HearingRole.UserRole.Name} not recognised");
                }
            }
        }
Exemplo n.º 13
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;
        }
        public async Task Setup()
        {
            _context = new BookingsDbContext(BookingsDbContextOptions);
            _getHearingByIdQueryHandler = new GetHearingByIdQueryHandler(_context);
            _genericCaseType            = _context.CaseTypes
                                          .Include(x => x.CaseRoles)
                                          .ThenInclude(x => x.HearingRoles)
                                          .ThenInclude(x => x.UserRole)
                                          .Include(x => x.HearingTypes)
                                          .First(x => x.Name == "Generic");

            var hearingService = new HearingService(_context);

            _hearing = await Hooks.SeedVideoHearing();

            TestContext.WriteLine($"New seeded video hearing id: {_hearing.Id}");

            _existingParticipants  = new List <ExistingParticipantDetails>();
            _newParticipants       = new List <NewParticipant>();
            _removedParticipantIds = new List <Guid>();
            _linkedParticipants    = new List <LinkedParticipantDto>();

            _handler = new UpdateHearingParticipantsCommandHandler(_context, hearingService);
        }
Exemplo n.º 15
0
        public VideoHearingBuilder()
        {
            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)";

            _videoHearing = Builder <VideoHearing> .CreateNew().WithFactory(() =>
                                                                            new VideoHearing(caseType, hearingType, scheduledDateTime, duration, venue, hearingRoomName,
                                                                                             otherInformation, createdBy, questionnaireNotRequired, audioRecordingRequired, cancelReason))
                            .Build();

            var applicantCaseRole = new CaseRole(1, "Applicant")
            {
                Group = CaseRoleGroup.Applicant
            };
            var respondentCaseRole = new CaseRole(2, "Respondent")
            {
                Group = CaseRoleGroup.Respondent
            };
            var applicantLipHearingRole = new HearingRole(1, "Litigant in person")
            {
                UserRole = new UserRole(1, "Individual")
            };
            var respondentRepresentativeHearingRole = new HearingRole(5, "Representative")
            {
                UserRole = new UserRole(1, "Representative")
            };

            var respondentLipHearingRole = new HearingRole(4, "Litigant in person")
            {
                UserRole = new UserRole(1, "Individual")
            };
            var judgeCaseRole = new CaseRole(5, "Judge")
            {
                Group = CaseRoleGroup.Judge
            };
            var judgeHearingRole = new HearingRole(13, "Judge")
            {
                UserRole = new UserRole(1, "Judge")
            };
            var johHearingRole = new HearingRole(14, "Judicial Office Holder")
            {
                UserRole = new UserRole(7, "Judicial Office Holder")
            };
            var johCaseRole = new CaseRole(11, "Winger")
            {
                Group = CaseRoleGroup.Winger
            };

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

            _judgePerson = new PersonBuilder(true).Build();
            _johPerson   = new PersonBuilder(true).Build();

            _videoHearing.AddIndividual(person1, applicantLipHearingRole, applicantCaseRole,
                                        $"{person1.FirstName} {person1.LastName}");
            var indApplicant = _videoHearing?.Participants.Last();

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

            _videoHearing.AddIndividual(person3, respondentLipHearingRole, respondentCaseRole,
                                        $"{person3.FirstName} {person3.LastName}");
            var indRespondent = _videoHearing?.Participants.Last();

            indRespondent.SetProtected(nameof(indApplicant.CaseRole), respondentCaseRole);
            indRespondent.SetProtected(nameof(indRespondent.HearingRole), respondentLipHearingRole);

            _videoHearing.AddRepresentative(person2, respondentRepresentativeHearingRole, respondentCaseRole,
                                            $"{person2.FirstName} {person2.LastName}", string.Empty);
            var repRespondent = _videoHearing?.Participants.Last();

            repRespondent.SetProtected(nameof(indApplicant.CaseRole), respondentCaseRole);
            repRespondent.SetProtected(nameof(repRespondent.HearingRole), respondentRepresentativeHearingRole);

            _videoHearing.AddJudge(_judgePerson, judgeHearingRole, judgeCaseRole,
                                   $"{_judgePerson.FirstName} {_judgePerson.LastName}");
            var judge = _videoHearing?.Participants.Last();

            judge.SetProtected(nameof(indApplicant.CaseRole), judgeCaseRole);
            judge.SetProtected(nameof(judge.HearingRole), judgeHearingRole);

            _videoHearing.AddJudicialOfficeHolder(_johPerson, johHearingRole, johCaseRole,
                                                  $"{_johPerson.FirstName} {_johPerson.LastName}");
            var joh = _videoHearing?.Participants.Last();

            joh.SetProtected(nameof(indApplicant.CaseRole), johCaseRole);
            joh.SetProtected(nameof(joh.HearingRole), johHearingRole);

            // 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);
        }
Exemplo n.º 16
0
        public async Task <VideoHearing> SeedVideoHearing(Action <SeedVideoHearingOptions> configureOptions,
                                                          bool addSuitabilityAnswer = false, BookingStatus status = BookingStatus.Booked)
        {
            var options = new SeedVideoHearingOptions();

            configureOptions?.Invoke(options);
            var caseType = GetCaseTypeFromDb(options.CaseTypeName);

            var claimantCaseRole  = caseType.CaseRoles.First(x => x.Name == options.ClaimantRole);
            var defendantCaseRole = caseType.CaseRoles.First(x => x.Name == options.DefendentRole);
            var judgeCaseRole     = caseType.CaseRoles.First(x => x.Name == "Judge");

            var claimantLipHearingRole             = claimantCaseRole.HearingRoles.First(x => x.Name == options.ClaimantHearingRole);
            var claimantRepresentativeHearingRole  = claimantCaseRole.HearingRoles.First(x => x.Name == "Representative");
            var defendantRepresentativeHearingRole = defendantCaseRole.HearingRoles.First(x => x.Name == "Representative");
            var judgeHearingRole = judgeCaseRole.HearingRoles.First(x => x.Name == "Judge");

            var hearingType = caseType.HearingTypes.First(x => x.Name == options.HearingTypeName);

            var venues = new RefDataBuilder().HearingVenues;

            var          person1                  = new PersonBuilder(true).WithOrganisation().WithAddress().Build();
            var          person2                  = new PersonBuilder(true).Build();
            var          person3                  = new PersonBuilder(true).Build();
            var          person4                  = new PersonBuilder(true).Build();
            var          scheduledDate            = DateTime.Today.AddDays(1).AddHours(10).AddMinutes(30);
            const int    duration                 = 45;
            const string hearingRoomName          = "Room02";
            const string otherInformation         = "OtherInformation02";
            const string createdBy                = "*****@*****.**";
            const bool   questionnaireNotRequired = false;
            const bool   audioRecordingRequired   = true;
            var          cancelReason             = "Online abandonment (incomplete registration)";

            var videoHearing = new VideoHearing(caseType, hearingType, scheduledDate, duration,
                                                venues.First(), hearingRoomName, otherInformation, createdBy, questionnaireNotRequired,
                                                audioRecordingRequired, cancelReason);

            videoHearing.AddIndividual(person1, claimantLipHearingRole, claimantCaseRole,
                                       $"{person1.FirstName} {person1.LastName}");

            videoHearing.AddRepresentative(person2, claimantRepresentativeHearingRole, claimantCaseRole,
                                           $"{person2.FirstName} {person2.LastName}", string.Empty, "Ms X");

            videoHearing.AddRepresentative(person3, defendantRepresentativeHearingRole, defendantCaseRole,
                                           $"{person3.FirstName} {person3.LastName}", string.Empty, "Ms Y");

            videoHearing.AddJudge(person4, judgeHearingRole, judgeCaseRole, $"{person4.FirstName} {person4.LastName}");

            videoHearing.AddCase($"{Faker.RandomNumber.Next(1000, 9999)}/{Faker.RandomNumber.Next(1000, 9999)}",
                                 $"{_defaultCaseName} {Faker.RandomNumber.Next(900000, 999999)}", true);
            videoHearing.AddCase($"{Faker.RandomNumber.Next(1000, 9999)}/{Faker.RandomNumber.Next(1000, 9999)}",
                                 $"{_defaultCaseName} {Faker.RandomNumber.Next(900000, 999999)}", false);
            if (status == BookingStatus.Created)
            {
                videoHearing.UpdateStatus(BookingStatus.Created, createdBy, null);
            }

            await using (var db = new BookingsDbContext(_dbContextOptions))
            {
                await db.VideoHearings.AddAsync(videoHearing);

                await db.SaveChangesAsync();
            }

            var hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));

            _individualId = hearing.Participants.First(x =>
                                                       x.HearingRole.Name.ToLower().IndexOf("judge", StringComparison.Ordinal) < 0 &&
                                                       x.HearingRole.Name.ToLower().IndexOf("representative", StringComparison.Ordinal) < 0).Id;
            _participantRepresentativeIds = hearing.Participants
                                            .Where(x => x.HearingRole.Name.ToLower().IndexOf("representative", StringComparison.Ordinal) >= 0).Select(x => x.Id).ToList();

            if (addSuitabilityAnswer)
            {
                await AddQuestionnaire();
            }

            hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));
            _seededHearings.Add(hearing.Id);
            return(hearing);
        }
Exemplo n.º 17
0
        public async Task <VideoHearing> SeedVideoHearing(Action <SeedVideoHearingOptions> configureOptions,
                                                          bool addSuitabilityAnswer = false, BookingStatus status = BookingStatus.Booked, int endPointsToAdd = 0, bool addJoh = false, bool withLinkedParticipants = false)
        {
            var options = new SeedVideoHearingOptions();

            configureOptions?.Invoke(options);
            var caseType = GetCaseTypeFromDb(options.CaseTypeName);

            var applicantCaseRole  = caseType.CaseRoles.First(x => x.Name == options.ApplicantRole);
            var respondentCaseRole = caseType.CaseRoles.First(x => x.Name == options.RespondentRole);
            var judgeCaseRole      = caseType.CaseRoles.First(x => x.Name == "Judge");

            var applicantLipHearingRole             = applicantCaseRole.HearingRoles.First(x => x.Name == options.LipHearingRole);
            var applicantRepresentativeHearingRole  = applicantCaseRole.HearingRoles.First(x => x.Name == "Representative");
            var respondentRepresentativeHearingRole = respondentCaseRole.HearingRoles.First(x => x.Name == "Representative");
            var respondentLipHearingRole            = respondentCaseRole.HearingRoles.First(x => x.Name == options.LipHearingRole);
            var judgeHearingRole = judgeCaseRole.HearingRoles.First(x => x.Name == "Judge");

            var hearingType = caseType.HearingTypes.First(x => x.Name == options.HearingTypeName);

            var venues = new RefDataBuilder().HearingVenues;

            var          person1                  = new PersonBuilder(true).WithOrganisation().Build();
            var          person2                  = new PersonBuilder(true).Build();
            var          person3                  = new PersonBuilder(true).Build();
            var          person4                  = new PersonBuilder(true).Build();
            var          judgePerson              = new PersonBuilder(true).Build();
            var          johPerson                = new PersonBuilder(true).Build();
            var          scheduledDate            = options.ScheduledDate ?? DateTime.Today.AddDays(1).AddHours(10).AddMinutes(30);
            const int    duration                 = 45;
            const string hearingRoomName          = "Room02";
            const string otherInformation         = "OtherInformation02";
            const string createdBy                = "*****@*****.**";
            const bool   questionnaireNotRequired = false;
            const bool   audioRecordingRequired   = true;
            var          cancelReason             = "Online abandonment (incomplete registration)";

            var videoHearing = new VideoHearing(caseType, hearingType, scheduledDate, duration,
                                                venues.First(), hearingRoomName, otherInformation, createdBy, questionnaireNotRequired,
                                                audioRecordingRequired, cancelReason);

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

            videoHearing.AddRepresentative(person2, applicantRepresentativeHearingRole, applicantCaseRole,
                                           $"{person2.FirstName} {person2.LastName}", "Ms X");

            videoHearing.AddRepresentative(person3, respondentRepresentativeHearingRole, respondentCaseRole,
                                           $"{person3.FirstName} {person3.LastName}", "Ms Y");

            videoHearing.AddIndividual(person4, respondentLipHearingRole, respondentCaseRole,
                                       $"{person4.FirstName} {person4.LastName}");

            videoHearing.AddJudge(judgePerson, judgeHearingRole, judgeCaseRole, $"{judgePerson.FirstName} {judgePerson.LastName}");

            if (addJoh)
            {
                var johCaseRole    = caseType.CaseRoles.First(x => x.Name == "Judicial Office Holder");
                var johHearingRole = johCaseRole.HearingRoles.First(x => x.Name == "Judicial Office Holder");
                videoHearing.AddJudicialOfficeHolder(johPerson, johHearingRole, johCaseRole,
                                                     $"{johPerson.FirstName} {johPerson.LastName}");
            }

            if (endPointsToAdd > 0)
            {
                var r = new RandomGenerator();
                for (int i = 0; i < endPointsToAdd; i++)
                {
                    var sip = r.GetWeakDeterministic(DateTime.UtcNow.Ticks, 1, 10);
                    var pin = r.GetWeakDeterministic(DateTime.UtcNow.Ticks, 1, 4);
                    videoHearing.AddEndpoints(new List <Endpoint>
                    {
                        new Endpoint($"new endpoint {i}", $"{sip}@hmcts.net", pin, null)
                    });
                }
            }

            if (withLinkedParticipants)
            {
                var interpretee = videoHearing.Participants[0];
                var interpreter = videoHearing.Participants[1];
                CreateParticipantLinks(interpretee, interpreter);
            }

            videoHearing.AddCase($"{Faker.RandomNumber.Next(1000, 9999)}/{Faker.RandomNumber.Next(1000, 9999)}",
                                 $"{_defaultCaseName} {Faker.RandomNumber.Next(900000, 999999)}", true);
            videoHearing.AddCase($"{Faker.RandomNumber.Next(1000, 9999)}/{Faker.RandomNumber.Next(1000, 9999)}",
                                 $"{_defaultCaseName} {Faker.RandomNumber.Next(900000, 999999)}", false);

            var dA = videoHearing.Participants[1];

            videoHearing.AddEndpoints(
                new List <Endpoint> {
                new Endpoint("new endpoint", Guid.NewGuid().ToString(), "pin", null),
                new Endpoint("new endpoint", Guid.NewGuid().ToString(), "pin", dA),
            });

            if (status == BookingStatus.Created)
            {
                videoHearing.UpdateStatus(BookingStatus.Created, createdBy, null);
            }

            await using (var db = new BookingsDbContext(_dbContextOptions))
            {
                await db.VideoHearings.AddAsync(videoHearing);

                await db.SaveChangesAsync();
            }

            var hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));

            _individualId = hearing.Participants.First(x => x.HearingRole.UserRole.IsIndividual).Id;
            _participantRepresentativeIds = hearing.Participants
                                            .Where(x => x.HearingRole.UserRole.IsRepresentative).Select(x => x.Id).ToList();

            if (addSuitabilityAnswer)
            {
                await AddQuestionnaire();
            }

            hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));
            _seededHearings.Add(hearing.Id);
            return(hearing);
        }
Exemplo n.º 18
0
        public async Task <VideoHearing> SeedVideoHearingLinkedParticipants(Action <SeedVideoHearingOptions> configureOptions)
        {
            var options = new SeedVideoHearingOptions();

            configureOptions?.Invoke(options);
            var caseType = GetCaseTypeFromDb(options.CaseTypeName);

            var applicantCaseRole  = caseType.CaseRoles.First(x => x.Name == options.ApplicantRole);
            var respondentCaseRole = caseType.CaseRoles.First(x => x.Name == options.RespondentRole);
            var judgeCaseRole      = caseType.CaseRoles.First(x => x.Name == "Judge");

            var applicantLipHearingRole  = applicantCaseRole.HearingRoles.First(x => x.Name == options.LipHearingRole);
            var respondentLipHearingRole = respondentCaseRole.HearingRoles.First(x => x.Name == options.LipHearingRole);
            var judgeHearingRole         = judgeCaseRole.HearingRoles.First(x => x.Name == "Judge");

            var hearingType = caseType.HearingTypes.First(x => x.Name == options.HearingTypeName);

            var venues = new RefDataBuilder().HearingVenues;

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

            var          scheduledDate            = DateTime.Today.AddDays(1).AddHours(10).AddMinutes(30);
            const int    duration                 = 45;
            const string hearingRoomName          = "Room02";
            const string otherInformation         = "OtherInformation02";
            const string createdBy                = "*****@*****.**";
            const bool   questionnaireNotRequired = false;
            const bool   audioRecordingRequired   = true;
            var          cancelReason             = "Online abandonment (incomplete registration)";

            var videoHearing = new VideoHearing(caseType, hearingType, scheduledDate, duration,
                                                venues.First(), hearingRoomName, otherInformation, createdBy, questionnaireNotRequired,
                                                audioRecordingRequired, cancelReason);

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

            videoHearing.AddIndividual(person2, respondentLipHearingRole, respondentCaseRole,
                                       $"{person2.FirstName} {person2.LastName}");

            videoHearing.AddJudge(judgePerson, judgeHearingRole, judgeCaseRole, $"{judgePerson.FirstName} {judgePerson.LastName}");

            var interpretee = videoHearing.Participants[0];
            var interpreter = videoHearing.Participants[1];

            CreateParticipantLinks(interpretee, interpreter);

            await using (var db = new BookingsDbContext(_dbContextOptions))
            {
                await db.VideoHearings.AddAsync(videoHearing);

                await db.SaveChangesAsync();
            }

            var hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));

            _individualId = hearing.Participants.First(x => x.HearingRole.UserRole.IsIndividual).Id;
            _participantRepresentativeIds = hearing.Participants
                                            .Where(x => x.HearingRole.UserRole.IsRepresentative).Select(x => x.Id).ToList();

            hearing = await new GetHearingByIdQueryHandler(new BookingsDbContext(_dbContextOptions)).Handle(
                new GetHearingByIdQuery(videoHearing.Id));
            _seededHearings.Add(hearing.Id);
            return(hearing);
        }