public async Task should_return_kinly_status_code_on_error()
        {
            var conferenceId = Guid.NewGuid();
            var request      = new TransferParticipantRequest
            {
                ParticipantId = Guid.NewGuid(),
                TransferType  = TransferType.Call
            };
            var message    = "Transfer Error";
            var response   = "Unable to transfer participant";
            var statusCode = (int)HttpStatusCode.Unauthorized;
            var exception  =
                new KinlyApiException(message, statusCode, response, null, null);

            VideoPlatformServiceMock
            .Setup(x => x.TransferParticipantAsync(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <RoomType>(),
                                                   It.IsAny <RoomType>())).ThrowsAsync(exception);

            var result = await Controller.TransferParticipantAsync(conferenceId, request);

            result.Should().BeOfType <ObjectResult>();
            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be(statusCode);
            typedResult.Value.Should().Be(response);
        }
        public async Task should_move_room_into_hearing_room()
        {
            var conferenceId    = TestConference.Id;
            var participant     = TestConference.Participants.First(x => x.UserRole == UserRole.Individual);
            var interpreterRoom = new ParticipantRoom(TestConference.Id, "Interpreter1", VirtualCourtRoomType.Civilian);

            interpreterRoom.SetProtectedProperty(nameof(interpreterRoom.Id), 999);
            var roomParticipant = new RoomParticipant(participant.Id)
            {
                Room   = interpreterRoom,
                RoomId = interpreterRoom.Id
            };

            interpreterRoom.AddParticipant(roomParticipant);
            participant.RoomParticipants.Add(roomParticipant);
            UpdateConferenceQueryMock();

            var request = new TransferParticipantRequest
            {
                ParticipantId = participant.Id,
                TransferType  = TransferType.Call
            };

            var result = await Controller.TransferParticipantAsync(conferenceId, request);

            result.Should().BeOfType <AcceptedResult>();

            VideoPlatformServiceMock.Verify(
                x => x.TransferParticipantAsync(conferenceId, interpreterRoom.Id.ToString(),
                                                RoomType.WaitingRoom.ToString(), RoomType.HearingRoom.ToString()), Times.Once);
        }
        public async Task should_pass_validation()
        {
            var request = new TransferParticipantRequest
            {
                ParticipantId = Guid.NewGuid(),
                TransferType  = TransferType.Call
            };
            var result = await _validator.ValidateAsync(request);

            result.IsValid.Should().BeTrue();
        }
        public async Task should_fail_validation_when_transfer_type_is_invalid()
        {
            var request = new TransferParticipantRequest
            {
                ParticipantId = Guid.NewGuid(),
                TransferType  = null
            };
            var result = await _validator.ValidateAsync(request);

            result.Errors.Any(x => x.ErrorMessage == TransferParticipantRequestValidation.MissingTransferType)
            .Should().BeTrue();
        }
        public async Task should_fail_validation_when_participant_id_is_invalid()
        {
            var request = new TransferParticipantRequest
            {
                ParticipantId = Guid.Empty,
                TransferType  = TransferType.Call
            };
            var result = await _validator.ValidateAsync(request);

            result.Errors.Any(x => x.ErrorMessage == TransferParticipantRequestValidation.MissingParticipantId)
            .Should().BeTrue();
        }
        private void SetupTransferRequest(TransferType transferType)
        {
            var conference   = _context.Test.Conference;
            var conferenceId = conference.Id;

            _context.Uri        = ApiUriFactory.ConferenceManagementEndpoints.TransferParticipant(conferenceId);
            _context.HttpMethod = HttpMethod.Post;
            var request = new TransferParticipantRequest
            {
                ParticipantId = conference.Participants.First().Id, TransferType = transferType
            };
            var jsonBody = RequestHelper.Serialise(request);

            _context.HttpContent = new StringContent(jsonBody, Encoding.UTF8, "application/json");
        }
        public void should_return_internal_server_error_when_transfer_type_is_not_handled()
        {
            var conferenceId = Guid.NewGuid();
            var request      = new TransferParticipantRequest
            {
                ParticipantId = Guid.NewGuid(),
                TransferType  = null
            };

            Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                           Controller.TransferParticipantAsync(conferenceId, request));

            VideoPlatformServiceMock.Verify(
                x => x.TransferParticipantAsync(conferenceId, request.ParticipantId, It.IsAny <RoomType>(),
                                                It.IsAny <RoomType>()), Times.Never);
        }
        public async Task should_dismiss_participant_from_hearing_room()
        {
            var conferenceId = Guid.NewGuid();
            var request      = new TransferParticipantRequest
            {
                ParticipantId = Guid.NewGuid(),
                TransferType  = TransferType.Dismiss
            };

            var result = await Controller.TransferParticipantAsync(conferenceId, request);

            result.Should().BeOfType <AcceptedResult>();

            VideoPlatformServiceMock.Verify(
                x => x.TransferParticipantAsync(conferenceId, request.ParticipantId, RoomType.HearingRoom,
                                                RoomType.WaitingRoom), Times.Once);
        }
        public void should_return_internal_server_error_when_transfer_type_is_not_handled()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.Participants.First(x => x.UserRole == UserRole.Individual);
            var request      = new TransferParticipantRequest
            {
                ParticipantId = participant.Id,
                TransferType  = null
            };

            Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                           Controller.TransferParticipantAsync(conferenceId, request));

            VideoPlatformServiceMock.Verify(
                x => x.TransferParticipantAsync(conferenceId, request.ParticipantId.ToString(), It.IsAny <string>(),
                                                It.IsAny <string>()), Times.Never);
        }
        public async Task should_dismiss_participant_from_hearing_room()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.Participants.First(x => x.UserRole == UserRole.Individual);
            var request      = new TransferParticipantRequest
            {
                ParticipantId = participant.Id,
                TransferType  = TransferType.Dismiss
            };

            var result = await Controller.TransferParticipantAsync(conferenceId, request);

            result.Should().BeOfType <AcceptedResult>();

            VideoPlatformServiceMock.Verify(
                x => x.TransferParticipantAsync(conferenceId, request.ParticipantId.ToString(), RoomType.HearingRoom.ToString(),
                                                RoomType.WaitingRoom.ToString()), Times.Once);
        }
        public async Task <IActionResult> TransferParticipantAsync(Guid conferenceId, TransferParticipantRequest transferRequest)
        {
            var conference =
                await _queryHandler.Handle <GetConferenceByIdQuery, Conference>(
                    new GetConferenceByIdQuery(conferenceId));

            var participant        = conference.GetParticipants().Single(x => x.Id == transferRequest.ParticipantId);
            var kinlyParticipantId = participant.GetParticipantRoom()?.Id.ToString() ?? participant.Id.ToString();
            var transferType       = transferRequest.TransferType;

            try
            {
                switch (transferType)
                {
                case TransferType.Call:
                    _logger.LogDebug("Attempting to transfer {Participant} into hearing room in {Conference}",
                                     kinlyParticipantId, conferenceId);
                    await _videoPlatformService.TransferParticipantAsync(conferenceId, kinlyParticipantId,
                                                                         RoomType.WaitingRoom.ToString(), RoomType.HearingRoom.ToString());

                    break;

                case TransferType.Dismiss:
                    _logger.LogDebug("Attempting to transfer {Participant} out of hearing room in {Conference}",
                                     kinlyParticipantId, conferenceId);
                    await _videoPlatformService.TransferParticipantAsync(conferenceId, kinlyParticipantId,
                                                                         RoomType.HearingRoom.ToString(), RoomType.WaitingRoom.ToString());

                    break;

                default:
                    _logger.LogWarning("Unable to transfer Participant {Participant} in {Conference}. Transfer type {TransferType} is unsupported",
                                       kinlyParticipantId, conferenceId, transferType);
                    throw new InvalidOperationException($"Unsupported transfer type: {transferType}");
                }

                return(Accepted());
            }
            catch (KinlyApiException ex)
            {
                _logger.LogError(ex,
                                 "Error from Kinly API. Unable to {TransferType} Participant {Participant} in/from {Conference}",
                                 transferType, kinlyParticipantId, conferenceId);
                return(StatusCode(ex.StatusCode, ex.Response));
            }
        }
Esempio n. 12
0
        public async Task <IActionResult> TransferParticipantAsync(Guid conferenceId, TransferParticipantRequest transferRequest)
        {
            var participantId = transferRequest.ParticipantId;
            var transferType  = transferRequest.TransferType;

            try
            {
                switch (transferType)
                {
                case TransferType.Call:
                    _logger.LogDebug("Attempting to transfer {Participant} into hearing room in {Conference}",
                                     participantId, conferenceId);
                    await _videoPlatformService.TransferParticipantAsync(conferenceId,
                                                                         transferRequest.ParticipantId,
                                                                         RoomType.WaitingRoom, RoomType.HearingRoom);

                    break;

                case TransferType.Dismiss:
                    _logger.LogDebug("Attempting to transfer {Participant} out of hearing room in {Conference}",
                                     participantId, conferenceId);
                    await _videoPlatformService.TransferParticipantAsync(conferenceId,
                                                                         transferRequest.ParticipantId,
                                                                         RoomType.HearingRoom, RoomType.WaitingRoom);

                    break;

                default:
                    _logger.LogWarning("Unable to transfer Participant {Participant} in {Conference}. Transfer type {TransferType} is unsupported",
                                       participantId, conferenceId, transferType);
                    throw new InvalidOperationException($"Unsupported transfer type: {transferType}");
                }

                return(Accepted());
            }
            catch (KinlyApiException ex)
            {
                _logger.LogError(ex,
                                 "Error from Kinly API. Unable to {TransferType} Participant {Participant} in/from {Conference}",
                                 transferType, participantId, conferenceId);
                return(StatusCode(ex.StatusCode, ex.Response));
            }
        }