public async Task should_join_jvs_to_consultation_when_vho_call_starts()
        {
            // Arrange
            _eventHandler = new VhOfficerCallEventHandler(EventHubContextMock.Object, ConferenceCache,
                                                          LoggerMock.Object, VideoApiClientMock.Object);

            var conference       = TestConference;
            var endpointForEvent = conference.Endpoints.First();


            var callbackEvent = new CallbackEvent
            {
                EventType     = EventType.VhoCall,
                EventId       = Guid.NewGuid().ToString(),
                ConferenceId  = conference.Id,
                ParticipantId = endpointForEvent.Id,
                TransferTo    = "ConsultationRoom1",
                TimeStampUtc  = DateTime.UtcNow
            };

            // Act
            await _eventHandler.HandleAsync(callbackEvent);

            // Assert
            VideoApiClientMock.Verify(x => x.JoinEndpointToConsultationAsync(It.Is <EndpointConsultationRequest>(r =>
                                                                                                                 r.ConferenceId == conference.Id &&
                                                                                                                 r.RequestedById == Guid.Empty &&
                                                                                                                 r.EndpointId == endpointForEvent.Id &&
                                                                                                                 r.RoomLabel == callbackEvent.TransferTo)), Times.Once);
        }
        public async Task Should_send_available_message_to_participants_and_service_bus_when_participant_joins()
        {
            MemoryCache.Remove(TestConference.Id);
            var confDetail = CreateConferenceDetailsResponse();

            VideoApiClientMock.Setup(x => x.GetConferenceDetailsByIdAsync(TestConference.Id)).ReturnsAsync(confDetail);

            _eventHandler = new JoinedEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                   VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantForEvent = conference.Participants.First(x => x.Role == Role.Individual);
            var participantCount    = conference.Participants.Count + 1; // plus one for admin

            var callbackEvent = new CallbackEvent
            {
                EventType     = EventType.Joined,
                EventId       = Guid.NewGuid().ToString(),
                ConferenceId  = conference.Id,
                ParticipantId = participantForEvent.Id,
                TimeStampUtc  = DateTime.UtcNow
            };

            await _eventHandler.HandleAsync(callbackEvent);

            EventHubClientMock.Verify(
                x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Id, _eventHandler.SourceParticipant.Username, conference.Id,
                                                ParticipantState.Available), Times.Exactly(participantCount));

            VideoApiClientMock.Verify(x => x.GetConferenceDetailsByIdAsync(TestConference.Id), Times.Once);
        }
 private void AssertMessageSentStatusToApi(string fromUsername, string toUsername, string message, Times times)
 {
     VideoApiClientMock.Verify(x => x.AddInstantMessageToConferenceAsync(
                                   It.Is <Guid>(c => c == Conference.Id),
                                   It.Is <AddInstantMessageRequest>(
                                       r => r.From == fromUsername && r.To == toUsername && r.MessageText == message
                                       ))
                               , times);
 }
Ejemplo n.º 4
0
        public async Task should_return_unauthorised_if_judge_not_assigned_to_conference()
        {
            var user = new ClaimsPrincipalBuilder()
                       .WithUsername("*****@*****.**")
                       .WithRole(AppRoles.JudgeRole).Build();

            Controller = SetupControllerWithClaims(user);

            var result = await Controller.EndVideoHearingAsync(TestConference.Id);

            var typedResult = (UnauthorizedObjectResult)result;

            typedResult.Should().NotBeNull();

            VideoApiClientMock.Verify(x => x.EndVideoHearingAsync(TestConference.Id), Times.Never);
        }
Ejemplo n.º 5
0
        public async Task should_return_unauthorised_if_user_not_judge()
        {
            var participant = TestConference.Participants.First(x => x.Role == Role.Individual);
            var user        = new ClaimsPrincipalBuilder()
                              .WithUsername(participant.Username)
                              .WithRole(AppRoles.CitizenRole).Build();

            Controller = SetupControllerWithClaims(user);

            var result = await Controller.EndVideoHearingAsync(TestConference.Id);

            var typedResult = (UnauthorizedObjectResult)result;

            typedResult.Should().NotBeNull();

            VideoApiClientMock.Verify(x => x.EndVideoHearingAsync(TestConference.Id), Times.Never);
        }
        public async Task should_return_unauthorised_if_judge_not_assigned_to_conference()
        {
            var user = new ClaimsPrincipalBuilder()
                       .WithUsername("*****@*****.**")
                       .WithRole(AppRoles.JudgeRole).Build();

            Controller = SetupControllerWithClaims(user);

            var result = await Controller.StartOrResumeVideoHearingAsync(TestConference.Id,
                                                                         new StartHearingRequest { Layout = HearingLayout.Dynamic });

            var typedResult = (UnauthorizedObjectResult)result;

            typedResult.Should().NotBeNull();
            typedResult.Value.Should().Be("User must be a Judge");

            VideoApiClientMock.Verify(
                x => x.StartOrResumeVideoHearingAsync(TestConference.Id, It.IsAny <StartHearingRequest>()), Times.Never);
        }
Ejemplo n.º 7
0
        public async Task should_return_unauthorised_if_participant_is_not_a_witness()
        {
            var participant = TestConference.Participants.First(x => x.Role == Role.Individual);
            var user        = new ClaimsPrincipalBuilder()
                              .WithUsername(participant.Username)
                              .WithRole(AppRoles.CitizenRole).Build();

            Controller = SetupControllerWithClaims(user);

            var result = await Controller.DismissWitnessAsync(TestConference.Id, participant.Id);

            var typedResult = (UnauthorizedObjectResult)result;

            typedResult.Should().NotBeNull();

            VideoApiClientMock.Verify(
                x => x.TransferParticipantAsync(TestConference.Id,
                                                It.Is <TransferParticipantRequest>(r => r.Participant_id == participant.Id)), Times.Never);
        }
        public async Task should_return_unauthorised_if_user_not_judge()
        {
            var participant = TestConference.Participants.First(x => x.Role == Role.Individual);
            var user        = new ClaimsPrincipalBuilder()
                              .WithUsername(participant.Username)
                              .WithRole(AppRoles.CitizenRole).Build();

            Controller = SetupControllerWithClaims(user);

            var result = await Controller.StartOrResumeVideoHearingAsync(TestConference.Id,
                                                                         new StartHearingRequest { Layout = HearingLayout.Dynamic });

            var typedResult = (UnauthorizedObjectResult)result;

            typedResult.Should().NotBeNull();
            typedResult.Value.Should().Be("User must be a Judge");

            VideoApiClientMock.Verify(
                x => x.StartOrResumeVideoHearingAsync(TestConference.Id,
                                                      It.Is <StartHearingRequest>(r => r.Layout == HearingLayout.Dynamic)), Times.Never);
        }
Ejemplo n.º 9
0
        public async Task should_return_unauthorised_if_not_judge_conference()
        {
            var participant = TestConference.Participants.First(x => !x.IsJudge());
            var user        = new ClaimsPrincipalBuilder()
                              .WithUsername(participant.Username)
                              .WithRole(AppRoles.CitizenRole).Build();

            Controller = SetupControllerWithClaims(user);

            var result = await Controller.CallWitnessAsync(TestConference.Id, participant.Id);

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

            typedResult.Should().NotBeNull();
            typedResult.Value.Should().Be("User must be a Judge");

            VideoApiClientMock.Verify(
                x => x.TransferParticipantAsync(TestConference.Id,
                                                It.Is <TransferParticipantRequest>(r => r.ParticipantId == participant.Id)), Times.Never);
        }
Ejemplo n.º 10
0
        public async Task should_return_unauthorised_if_participant_does_not_exists()
        {
            var judge = TestConference.GetJudge();
            var user  = new ClaimsPrincipalBuilder()
                        .WithUsername(judge.Username)
                        .WithRole(AppRoles.JudgeRole).Build();

            Controller = SetupControllerWithClaims(user);

            var result = await Controller.CallWitnessAsync(TestConference.Id, Guid.NewGuid());

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

            typedResult.Should().NotBeNull();
            typedResult.Value.Should().Be("Participant is not a witness");

            VideoApiClientMock.Verify(
                x => x.TransferParticipantAsync(TestConference.Id,
                                                It.IsAny <TransferParticipantRequest>()), Times.Never);
        }
Ejemplo n.º 11
0
        public async Task Should_throw_error_on_send_heartbeat()
        {
            var conferenceId  = Guid.NewGuid();
            var participantId = Guid.NewGuid();
            var heartbeat     = new Heartbeat
            {
                BrowserName = "test_browser", BrowserVersion = "1",
                IncomingAudioPercentageLostRecent = 10.3m,
                OperatingSystem        = "Mac OS X",
                OperatingSystemVersion = "10.15"
            };

            var mockClient = new Mock <IEventHubClient>();

            EventHubClientMock.Setup(x => x.Group(EventHub.Hub.EventHub.VhOfficersGroupName)).Returns(mockClient.Object);
            HeartbeatMapper.Setup(x => x.MapToHealth(heartbeat)).Returns(HeartbeatHealth.Good);
            mockClient.Setup
            (
                x => x.ReceiveHeartbeat(conferenceId, participantId,
                                        HeartbeatHealth.Good, heartbeat.BrowserName, heartbeat.BrowserVersion,
                                        heartbeat.OperatingSystem, heartbeat.OperatingSystemVersion)
            ).Throws <Exception>();

            var addHeartbeatRequest = new AddHeartbeatRequest
            {
                Browser_name = heartbeat.BrowserName, Browser_version = heartbeat.BrowserVersion,
                Incoming_audio_percentage_lost_recent = 10.3
            };

            HeartbeatMapper.Setup(x => x.MapToRequest(heartbeat)).Returns(addHeartbeatRequest);
            await Hub.SendHeartbeat(conferenceId, participantId, heartbeat);

            VideoApiClientMock.Verify
            (
                x => x.SaveHeartbeatDataForParticipantAsync(conferenceId, participantId, addHeartbeatRequest),
                Times.Never
            );
        }
Ejemplo n.º 12
0
        private void AssertMessageSentStatusToHubAndApi(string fromUsername, string toUsername, string message,
                                                        Guid messageUuid,
                                                        Mock <IEventHubClient> userChannel, Times times)
        {
            ConferenceGroupChannel.Verify(
                x =>
                x.ReceiveMessage(Conference.Id, fromUsername, toUsername, message, It.IsAny <DateTime>(),
                                 messageUuid),
                times);

            userChannel.Verify(
                x =>
                x.ReceiveMessage(Conference.Id, fromUsername, toUsername, message, It.IsAny <DateTime>(),
                                 messageUuid),
                times);

            VideoApiClientMock.Verify(x => x.AddInstantMessageToConferenceAsync(
                                          It.Is <Guid>(c => c == Conference.Id),
                                          It.Is <AddInstantMessageRequest>(
                                              r => r.From == fromUsername && r.To == toUsername && r.Message_text == message
                                              ))
                                      , times);
        }
Ejemplo n.º 13
0
        public async Task Should_send_heartbeat_to_vhofficers_group_from_judge()
        {
            const string participantUsername = "******";
            var          conference          = InitConference(participantUsername);
            var          judge         = conference.Participants.First(x => x.Role == Role.Judge);
            var          judgeUserName = judge.Username;

            var conferenceId = conference.Id;
            var judgeId      = judge.Id;
            var heartbeat    = new Heartbeat
            {
                BrowserName = "test_browser", BrowserVersion = "1",
                IncomingAudioPercentageLostRecent = 10.3m,
                OperatingSystem        = "Mac OS X",
                OperatingSystemVersion = "10.15"
            };

            ConferenceCacheMock.Setup(cache =>
                                      cache.GetOrAddConferenceAsync(conference.Id, It.IsAny <Func <Task <ConferenceDetailsResponse> > >()))
            .Callback(async(Guid anyGuid, Func <Task <ConferenceDetailsResponse> > factory) => await factory())
            .ReturnsAsync(conference);

            var mockAdminClient       = new Mock <IEventHubClient>();
            var mockParticipantClient = new Mock <IEventHubClient>();
            var mockJudgeClient       = new Mock <IEventHubClient>();

            EventHubClientMock.Setup(x => x.Group(EventHub.Hub.EventHub.VhOfficersGroupName)).Returns(mockAdminClient.Object);
            EventHubClientMock.Setup(x => x.Group(participantUsername.ToLowerInvariant())).Returns(mockParticipantClient.Object);
            EventHubClientMock.Setup(x => x.Group(judgeUserName.ToLowerInvariant())).Returns(mockJudgeClient.Object);
            HeartbeatMapper.Setup(x => x.MapToHealth(heartbeat)).Returns(HeartbeatHealth.Good);
            var addHeartbeatRequest = new AddHeartbeatRequest
            {
                Browser_name = heartbeat.BrowserName, Browser_version = heartbeat.BrowserVersion,
                Incoming_audio_percentage_lost_recent = 10.3
            };

            HeartbeatMapper.Setup(x => x.MapToRequest(heartbeat)).Returns(addHeartbeatRequest);
            await Hub.SendHeartbeat(conferenceId, judgeId, heartbeat);

            mockAdminClient.Verify
            (
                x => x.ReceiveHeartbeat
                (
                    conferenceId, judgeId, HeartbeatHealth.Good, heartbeat.BrowserName, heartbeat.BrowserVersion,
                    heartbeat.OperatingSystem, heartbeat.OperatingSystemVersion
                ),
                Times.Once
            );

            mockParticipantClient.Verify
            (
                x => x.ReceiveHeartbeat
                (
                    conferenceId, judgeId, HeartbeatHealth.Good, heartbeat.BrowserName, heartbeat.BrowserVersion,
                    heartbeat.OperatingSystem, heartbeat.OperatingSystemVersion
                ),
                Times.Never
            );

            VideoApiClientMock.Verify
            (
                x => x.SaveHeartbeatDataForParticipantAsync(conferenceId, judgeId, addHeartbeatRequest),
                Times.Once
            );
        }