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)
                                             );
        }
        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);
        }
Esempio n. 3
0
 public VideoHearingBuilder WithCase()
 {
     _videoHearing.AddCase("AutoTest", "Test", true);
     return(this);
 }
        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);
        }
Esempio n. 5
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);
        }