public void Setup()
        {
            _mocker = AutoMock.GetLoose();
            var parameters = new ParameterBuilder(_mocker)
                             .AddTypedParameters <ParticipantResponseMapper>()
                             .AddTypedParameters <EndpointsResponseMapper>()
                             .Build();

            _sut = _mocker.Create <ConferenceResponseMapper>(parameters);
        }
Beispiel #2
0
        public void Should_map_all_properties()
        {
            var hearing                   = new CreateHearingRequestBuilder().Build();
            var hearingResponse           = new HearingsResponseBuilder(hearing).Build();
            var conferenceDetailsResponse = new ConferenceDetailsResponseBuilder(hearingResponse).Build();
            var conferenceResponse        = new ConferenceResponseBuilder(conferenceDetailsResponse).Build();

            var response = ConferenceResponseMapper.Map(conferenceDetailsResponse);

            response.Should().BeEquivalentTo(conferenceResponse, options => options.ExcludingMissingMembers());
        }
Beispiel #3
0
        public async Task <ActionResult <ConferenceResponse> > GetConferenceByIdAsync(Guid conferenceId)
        {
            _logger.LogDebug("GetConferenceById");
            if (conferenceId == Guid.Empty)
            {
                _logger.LogWarning("Unable to get conference when id is not provided");
                ModelState.AddModelError(nameof(conferenceId), $"Please provide a valid {nameof(conferenceId)}");
                return(BadRequest(ModelState));
            }

            var username = User.Identity.Name.ToLower().Trim();

            ConferenceDetailsResponse conference;

            try
            {
                _logger.LogTrace($"Retrieving conference details for conference: ${conferenceId}");
                conference = await _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId);
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, $"Unable to retrieve conference: ${conferenceId}");
                return(StatusCode(e.StatusCode, e.Response));
            }

            var exceededTimeLimit = !ConferenceHelper.HasNotPassed(conference.Current_status, conference.Closed_date_time);

            if (conference.Participants.All(x => x.Username.ToLower().Trim() != username) || exceededTimeLimit)
            {
                _logger.LogInformation(
                    $"Unauthorised to view conference details {conferenceId} because user is neither a VH " +
                    "Officer nor a participant of the conference, or the conference has been closed for over 30 minutes");
                return(Unauthorized());
            }

            // these are roles that are filtered against when lists participants on the UI
            var displayRoles = new List <Role>
            {
                Role.Judge,
                Role.Individual,
                Role.Representative
            };

            conference.Participants = conference.Participants
                                      .Where(x => displayRoles.Contains((Role)x.User_role)).ToList();

            var response = ConferenceResponseMapper.MapConferenceDetailsToResponseModel(conference);
            await _conferenceCache.AddConferenceAsync(conference);

            return(Ok(response));
        }
Beispiel #4
0
        public async Task <IActionResult> GetConferenceByHearingRefId(Guid hearingRefId)
        {
            _logger.LogDebug("GetConferenceByHearingRefId {hearingRefId}", hearingRefId);

            try
            {
                var conferenceResponse = await _testApiClient.GetConferenceByHearingRefIdAsync(hearingRefId);

                var conferences = ConferenceResponseMapper.Map(conferenceResponse);
                return(Ok(conferences));
            }
            catch (TestApiException e)
            {
                _logger.LogError(e, "Unable to fetch conference with error '{message}'", e.Message);
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Beispiel #5
0
        public void Should_map_all_properties_for_more_then_4_participants()
        {
            var participants = new List <ParticipantDetailsResponse>
            {
                new ParticipantDetailsResponseBuilder(UserRole.Individual, "Claimant").WithHearingRole("Litigant in person").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Individual, "Defendant").WithHearingRole("Litigant in person").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Representative, "Defendant").WithHearingRole("Representative").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Judge, "None").WithHearingRole("Judge").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.CaseAdmin, "None").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Individual, "Observer").WithHearingRole("Observer").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Individual, "Panel Member").WithHearingRole("Panel Member").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Individual, "Panel Member").WithHearingRole("Panel Member").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Individual, "Witness").WithHearingRole("Witness").Build()
            };


            var expectedConferenceStatus = ConferenceStatus.Suspended;

            var meetingRoom = Builder <MeetingRoomResponse> .CreateNew().Build();

            var conference = Builder <ConferenceDetailsResponse> .CreateNew()
                             .With(x => x.Current_status = ConferenceState.Suspended)
                             .With(x => x.Participants   = participants)
                             .With(x => x.Meeting_room   = meetingRoom)
                             .Build();

            var response = ConferenceResponseMapper.MapConferenceDetailsToResponseModel(conference);

            response.Id.Should().Be(conference.Id);
            response.CaseName.Should().Be(conference.Case_name);
            response.CaseType.Should().Be(conference.Case_type);
            response.CaseNumber.Should().Be(conference.Case_number);
            response.ScheduledDateTime.Should().Be(conference.Scheduled_date_time);
            response.ScheduledDuration.Should().Be(conference.Scheduled_duration);
            response.Status.Should().Be(expectedConferenceStatus);

            var participantsResponse = response.Participants;

            participantsResponse.Should().NotBeNullOrEmpty();

            var tiledNames = participantsResponse.Select(x => x.TiledDisplayName).ToList();

            foreach (var participantResponse in participantsResponse)
            {
                var position = participantResponse.TiledDisplayName.Split(';');
                if (participantResponse.Role == Role.Judge)
                {
                    participantResponse.TiledDisplayName.StartsWith("T0").Should().BeTrue();
                }

                if (position[0].StartsWith("T"))
                {
                    tiledNames.Count(x => x.StartsWith(position[0])).Should().Be(1);
                }
                if (participantResponse.HearingRole == "Witness" && participantResponse.Role == Role.Individual)
                {
                    participantResponse.TiledDisplayName.StartsWith("W").Should().BeTrue();
                    tiledNames.Count(x => x.StartsWith(position[0])).Should().Be(1);
                }
            }

            var caseTypeGroups = participantsResponse.Select(p => p.CaseTypeGroup).Distinct().ToList();

            caseTypeGroups.Count.Should().BeGreaterThan(2);
            caseTypeGroups[0].Should().Be("Claimant");
            caseTypeGroups[1].Should().Be("Defendant");
            caseTypeGroups[2].Should().Be("None");
            caseTypeGroups[3].Should().Be("Observer");
            caseTypeGroups[4].Should().Be("Panel Member");

            response.ParticipantUri.Should().Be(meetingRoom.Participant_uri);
            response.PexipNodeUri.Should().Be(meetingRoom.Pexip_node);
            response.PexipSelfTestNodeUri.Should().NotBeNullOrWhiteSpace();
        }
Beispiel #6
0
        public void Should_map_all_properties()
        {
            var participants = new List <ParticipantDetailsResponse>
            {
                new ParticipantDetailsResponseBuilder(UserRole.Individual, "Claimant").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Individual, "Defendant").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Representative, "Defendant").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.Judge, "None").Build(),
                new ParticipantDetailsResponseBuilder(UserRole.CaseAdmin, "None").Build(),
            };

            var endpoints = new List <EndpointResponse>
            {
                new EndpointsResponseBuilder().Build(),
                new EndpointsResponseBuilder().Build(),
            };

            var expectedConferenceStatus = ConferenceStatus.Suspended;

            var meetingRoom = Builder <MeetingRoomResponse> .CreateNew().Build();

            var conference = Builder <ConferenceDetailsResponse> .CreateNew()
                             .With(x => x.Current_status = ConferenceState.Suspended)
                             .With(x => x.Participants   = participants)
                             .With(x => x.Meeting_room   = meetingRoom)
                             .With(x => x.Endpoints      = endpoints)
                             .Build();

            var response = ConferenceResponseMapper.MapConferenceDetailsToResponseModel(conference);

            response.Id.Should().Be(conference.Id);
            response.CaseName.Should().Be(conference.Case_name);
            response.CaseType.Should().Be(conference.Case_type);
            response.CaseNumber.Should().Be(conference.Case_number);
            response.ScheduledDateTime.Should().Be(conference.Scheduled_date_time);
            response.ScheduledDuration.Should().Be(conference.Scheduled_duration);
            response.Status.Should().Be(expectedConferenceStatus);
            response.Endpoints.Should().NotBeNull();
            response.Endpoints.Count.Should().Be(2);

            var participantsResponse = response.Participants;

            participantsResponse.Should().NotBeNullOrEmpty();
            foreach (var participantResponse in participantsResponse)
            {
                if (participantResponse.Role == Role.Representative)
                {
                    participantResponse.TiledDisplayName.StartsWith("T4").Should().BeTrue();
                }
                if (participantResponse.Role == Role.Judge)
                {
                    participantResponse.TiledDisplayName.StartsWith("T0").Should().BeTrue();
                }
                if (participantResponse.Role == Role.Individual)
                {
                    (participantResponse.TiledDisplayName.StartsWith("T1") ||
                     participantResponse.TiledDisplayName.StartsWith("T2")).Should().BeTrue();
                }
                if (participantResponse.Role == Role.CaseAdmin)
                {
                    participantResponse.TiledDisplayName.Should().BeNull();
                }
            }

            var caseTypeGroups = participantsResponse.Select(p => p.CaseTypeGroup).Distinct().ToList();

            caseTypeGroups.Count.Should().BeGreaterThan(2);
            caseTypeGroups[0].Should().Be("Claimant");
            caseTypeGroups[1].Should().Be("Defendant");
            caseTypeGroups[2].Should().Be("None");

            response.ParticipantUri.Should().Be(meetingRoom.Participant_uri);
            response.PexipNodeUri.Should().Be(meetingRoom.Pexip_node);
            response.PexipSelfTestNodeUri.Should().NotBeNullOrWhiteSpace();
        }