public async Task Should_Return_BadRequest_When_Participant_Cannot_Be_Found_In_Consultation_Room()
        {
            var conferenceId     = TestConference.Id;
            var participantId    = TestConference.Participants[0].Id;
            var consultationRoom = new ConsultationRoom(TestConference.Id, "ConsultationRoom", VirtualCourtRoomType.JudgeJOH, false);

            TestConference.Participants[0].CurrentConsultationRoom = consultationRoom;
            var fromRoom = "ConsultationRoom";
            var toRoom   = "WaitingRoom";
            var leaveConsultationRequest = new LeaveConsultationRequest
            {
                ConferenceId = conferenceId, ParticipantId = participantId
            };

            var kinlyApiException = new KinlyApiException("", (int)HttpStatusCode.BadRequest, "payload",
                                                          new Dictionary <string, IEnumerable <string> >(), new Exception());

            ConsultationServiceMock.Setup(x => x.LeaveConsultationAsync(leaveConsultationRequest.ConferenceId,
                                                                        leaveConsultationRequest.ParticipantId, fromRoom, toRoom)).ThrowsAsync(kinlyApiException);

            var result = await Controller.LeaveConsultationAsync(leaveConsultationRequest);

            QueryHandlerMock.Verify(q => q.Handle <GetConferenceByIdQuery, VideoApi.Domain.Conference>
                                        (It.IsAny <GetConferenceByIdQuery>()), Times.Once);
            ConsultationServiceMock.Verify(v => v.LeaveConsultationAsync
                                               (leaveConsultationRequest.ConferenceId, leaveConsultationRequest.ParticipantId, fromRoom, toRoom),
                                           Times.Never);
            result.Should().BeOfType <BadRequestObjectResult>();
        }
        public async Task should_return_judge_joh_to_waiting_room_for_valid_conference_and_room_type()
        {
            var conferenceId     = TestConference.Id;
            var participantId    = TestConference.Participants[0].Id;
            var consultationRoom = new ConsultationRoom(TestConference.Id, "ConsultationRoom", VirtualCourtRoomType.JudgeJOH, false);

            TestConference.Participants[0].CurrentConsultationRoom   = consultationRoom;
            TestConference.Participants[0].CurrentConsultationRoomId = 1;
            QueryHandlerMock
            .Setup(x => x.Handle <GetConferenceByIdQuery, VideoApi.Domain.Conference>(
                       It.Is <GetConferenceByIdQuery>(q => q.ConferenceId == TestConference.Id)))
            .ReturnsAsync(TestConference);

            var fromRoom = "ConsultationRoom";
            var toRoom   = "WaitingRoom";
            var leaveConsultationRequest = new LeaveConsultationRequest
            {
                ConferenceId = conferenceId, ParticipantId = participantId
            };
            await Controller.LeaveConsultationAsync(leaveConsultationRequest);

            QueryHandlerMock.Verify(q => q.Handle <GetConferenceByIdQuery, VideoApi.Domain.Conference>
                                        (It.IsAny <GetConferenceByIdQuery>()), Times.Once);
            ConsultationServiceMock.Verify(v => v.LeaveConsultationAsync
                                               (leaveConsultationRequest.ConferenceId, leaveConsultationRequest.ParticipantId, fromRoom, toRoom),
                                           Times.Once);
        }
        public async Task Should_leave_private_consultation_with_valid_conference_and_room_type()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[1];

            var leaveConsultationRequest = new LeaveConsultationRequest {
                ConferenceId  = conferenceId,
                ParticipantId = participant.Id
            };

            await Controller.LeaveConsultationAsync(leaveConsultationRequest);

            QueryHandlerMock.Verify(q => q.Handle <GetConferenceByIdQuery, VideoApi.Domain.Conference>(It.IsAny <GetConferenceByIdQuery>()), Times.Once);
            ConsultationServiceMock.Verify(v => v.LeaveConsultationAsync(TestConference.Id, leaveConsultationRequest.ParticipantId, participant.GetCurrentRoom(), RoomType.WaitingRoom.ToString()), Times.Once);
            ConsultationServiceMock.VerifyNoOtherCalls();
        }
        public async Task Should_not_transfer_participant_when_consultation_is_not_accepted()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[3];

            var roomFrom = participant.GetCurrentRoom();
            var request  = new ConsultationRequestResponse
            {
                ConferenceId = conferenceId,
                RequestedFor = participant.Id,
                RoomLabel    = "ConsultationRoom",
                Answer       = ConsultationAnswer.Rejected
            };

            await Controller.RespondToConsultationRequestAsync(request);

            ConsultationServiceMock.Verify(x =>
                                           x.LeaveConsultationAsync(conferenceId, participant.Id, roomFrom, request.RoomLabel),
                                           Times.Never);
            ConsultationServiceMock.VerifyNoOtherCalls();
        }
        public async Task Should_transfer_participant_when_consultation_is_accepted()
        {
            var conferenceId = TestConference.Id;
            var participant  = TestConference.GetParticipants()[3];
            var requestedBy  = TestConference.GetParticipants()[1];

            var request = new ConsultationRequestResponse
            {
                ConferenceId = conferenceId,
                RequestedBy  = requestedBy.Id,
                RequestedFor = participant.Id,
                RoomLabel    = "ConsultationRoom",
                Answer       = ConsultationAnswer.Accepted
            };

            await Controller.RespondToConsultationRequestAsync(request);

            ConsultationServiceMock.Verify(x => x.ParticipantTransferToRoomAsync(conferenceId, participant.Id, request.RoomLabel),
                                           Times.Once);
            ConsultationServiceMock.VerifyNoOtherCalls();
        }
        public async Task Should_raise_notification_to_requester_and_admin_when_consultation_is_accepted()
        {
            var conferenceId = TestConference.Id;
            var requestedBy  = TestConference.GetParticipants()[2];
            var requestedFor = TestConference.GetParticipants()[3];

            var answer = ConsultationAnswer.Accepted;

            var request = new ConsultationRequestResponse
            {
                ConferenceId = conferenceId,
                RequestedBy  = requestedBy.Id,
                RequestedFor = requestedFor.Id,
                Answer       = answer,
                RoomLabel    = "Room1"
            };

            await Controller.RespondToConsultationRequestAsync(request);

            CommandHandlerMock.Verify(x => x.Handle(It.Is <SaveEventCommand>(s => s.Reason == $"Adding {requestedFor.DisplayName} to {request.RoomLabel}")), Times.Once);
            ConsultationServiceMock.Verify(x =>
                                           x.ParticipantTransferToRoomAsync(TestConference.Id, requestedFor.Id, "Room1"), Times.Once);
            ConsultationServiceMock.VerifyNoOtherCalls();
        }