Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }