public void Should_throw_exception_when_transfer_cannot_be_mapped_to_participant_status()
        {
            _eventHandler = new TransferEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                     VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantForEvent = conference.Participants.First(x => x.Role == Role.Individual);

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

            Assert.ThrowsAsync <RoomTransferException>(() =>
                                                       _eventHandler.HandleAsync(callbackEvent));

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(
                x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Id, _eventHandler.SourceParticipant.Username, conference.Id,
                                                It.IsAny <ParticipantState>()), Times.Never);
        }
        public async Task Should_send_not_signed_in_message_to_participants_and_service_bus_when_a_participant_is_signed_off()
        {
            _eventHandler = new ParticipantNotSignedInEventHandler(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.ParticipantNotSignedIn,
                EventId       = Guid.NewGuid().ToString(),
                ConferenceId  = conference.Id,
                ParticipantId = participantForEvent.Id,
                TimeStampUtc  = DateTime.UtcNow
            };

            await _eventHandler.HandleAsync(callbackEvent);

            Assert.AreEqual(_eventHandler.EventType, EventType.ParticipantNotSignedIn);

            EventHubClientMock.Verify(
                x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Id, _eventHandler.SourceParticipant.Username, conference.Id,
                                                ParticipantState.NotSignedIn), Times.Exactly(participantCount));
        }
        public async Task Should_send_disconnect_messages_to_participants_and_service_bus_on_participant_disconnect()
        {
            _eventHandler = new DisconnectedEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                         VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantCount    = conference.Participants.Count + 1; // plus one for admin
            var participantForEvent = conference.Participants.First(x => x.Role == Role.Individual);
            var callbackEvent       = new CallbackEvent
            {
                EventType     = EventType.Disconnected,
                EventId       = Guid.NewGuid().ToString(),
                ParticipantId = participantForEvent.Id,
                ConferenceId  = conference.Id,
                Reason        = "Unexpected drop",
                TimeStampUtc  = DateTime.UtcNow
            };

            await _eventHandler.HandleAsync(callbackEvent);

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(
                x => x.ParticipantStatusMessage(participantForEvent.Id, participantForEvent.Username, conference.Id, ParticipantState.Disconnected),
                Times.Exactly(participantCount));
        }
        public async Task should_send_participant_status_when_transferring_from_new_consultation_room()
        {
            _eventHandler = new TransferEventHandler(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.Transfer,
                EventId       = Guid.NewGuid().ToString(),
                ConferenceId  = conference.Id,
                ParticipantId = participantForEvent.Id,
                TransferFrom  = "JudgeConsultationRoom3",
                TransferTo    = RoomType.WaitingRoom.ToString(),
                TimeStampUtc  = DateTime.UtcNow
            };

            var expectedStatus = ParticipantState.Available;

            await _eventHandler.HandleAsync(callbackEvent);

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(
                x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Id, _eventHandler.SourceParticipant.Username, conference.Id,
                                                expectedStatus), Times.Exactly(participantCount));
        }
Ejemplo n.º 5
0
        public async Task Should_send_endpoint_status_messages_to_clients(RoomType from, RoomType to,
                                                                          EndpointState status)
        {
            _eventHandler = new EndpointTransferEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                             VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantCount    = conference.Participants.Count + 1; // plus one for admin
            var participantForEvent = conference.Endpoints.First();
            var callbackEvent       = new CallbackEvent
            {
                EventType     = EventType.EndpointTransfer,
                EventId       = Guid.NewGuid().ToString(),
                ParticipantId = participantForEvent.Id,
                TransferFrom  = from.ToString(),
                TransferTo    = to.ToString(),
                ConferenceId  = conference.Id,
                Reason        = "JVC Connection",
                TimeStampUtc  = DateTime.UtcNow
            };

            await _eventHandler.HandleAsync(callbackEvent);

            EventHubClientMock.Verify(x => x.EndpointStatusMessage(participantForEvent.Id, conference.Id, status),
                                      Times.Exactly(participantCount));
        }
        public async Task Should_send_participant__status_messages_to_clients_and_asb_when_transfer_occurs(
            RoomType from, RoomType to, ParticipantState status)
        {
            _eventHandler = new TransferEventHandler(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.Transfer,
                EventId       = Guid.NewGuid().ToString(),
                ConferenceId  = conference.Id,
                ParticipantId = participantForEvent.Id,
                TransferFrom  = from.ToString(),
                TransferTo    = to.ToString(),
                TimeStampUtc  = DateTime.UtcNow
            };
            await _eventHandler.HandleAsync(callbackEvent);

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(
                x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Id, _eventHandler.SourceParticipant.Username, conference.Id,
                                                status), Times.Exactly(participantCount));
        }
        public async Task Should_send_available_message_to_participants_and_service_bus_when_participant_leaves()
        {
            _eventHandler = new LeaveEventHandler(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.Leave,
                EventId       = Guid.NewGuid().ToString(),
                ConferenceId  = conference.Id,
                ParticipantId = participantForEvent.Id,
                TimeStampUtc  = DateTime.UtcNow,
                Reason        = "Automated"
            };

            await _eventHandler.HandleAsync(callbackEvent);

            EventHubClientMock.Verify(
                x => x.ParticipantStatusMessage(_eventHandler.SourceParticipant.Id, _eventHandler.SourceParticipant.Username, conference.Id,
                                                ParticipantState.Disconnected), Times.Exactly(participantCount));
        }
Ejemplo n.º 8
0
        public async Task should_publish_remote_mute_status_to_participants_and_linked()
        {
            var participantUsername = "******";
            var conference          = CreateTestConference(participantUsername, true);
            var conferenceId        = conference.Id;
            var participant         = conference.Participants.First(x => x.Username == participantUsername);
            var isRemoteMuted       = true;

            SetupEventHubClientsForAllParticipantsInConference(conference, false);

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

            await Hub.UpdateParticipantRemoteMuteStatus(conferenceId, participant.Id, isRemoteMuted);

            EventHubClientMock.Verify(
                x => x.Group(participant.Username.ToLowerInvariant())
                .ParticipantRemoteMuteMessage(participant.Id, conference.Id, isRemoteMuted), Times.Once);

            foreach (var lp in participant.LinkedParticipants)
            {
                var linkedPat = conference.Participants.Single(p => p.Id == lp.LinkedId);
                EventHubClientMock.Verify(
                    x => x.Group(linkedPat.Username.ToLowerInvariant())
                    .ParticipantRemoteMuteMessage(lp.LinkedId, conference.Id, isRemoteMuted), Times.Once);
            }
        }
        public async Task should_send_endpoint_connected_message_to_participants_and_admin()
        {
            _eventHandler = new EndpointJoinedEventHandler(EventHubContextMock.Object, ConferenceCache,
                                                           LoggerMock.Object, VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantCount    = conference.Participants.Count + 1; // plus one for admin
            var participantForEvent = conference.Endpoints.First();
            var callbackEvent       = new CallbackEvent
            {
                EventType     = EventType.EndpointJoined,
                EventId       = Guid.NewGuid().ToString(),
                ParticipantId = participantForEvent.Id,
                ConferenceId  = conference.Id,
                Reason        = "JVC Connection",
                TimeStampUtc  = DateTime.UtcNow
            };

            await _eventHandler.HandleAsync(callbackEvent);

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(
                x => x.EndpointStatusMessage(participantForEvent.Id, conference.Id, EndpointState.Connected),
                Times.Exactly(participantCount));
        }
        public async Task should_publish_hand_raised_to_all_johs_when_one_joh_is_is_raised()
        {
            var participantUsername = "******";
            var conference          = CreateTestConference(participantUsername, true);
            var conferenceId        = conference.Id;
            var allJohs             = conference.Participants.Where(x => x.IsJudicialOfficeHolder()).ToList();
            var participant         = conference.Participants.First(x => x.IsJudicialOfficeHolder());
            var handRaised          = true;

            SetupEventHubClientsForAllParticipantsInConference(conference, false);

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

            await Hub.UpdateParticipantHandStatus(conferenceId, participant.Id, handRaised);


            var judge = conference.Participants.Single(x => x.IsJudge());

            EventHubClientMock.Verify(
                x => x.Group(judge.Username.ToLowerInvariant())
                .ParticipantHandRaiseMessage(participant.Id, conference.Id, handRaised), Times.Once);

            foreach (var joh in allJohs)
            {
                EventHubClientMock.Verify(
                    x => x.Group(joh.Username.ToLowerInvariant())
                    .ParticipantHandRaiseMessage(joh.Id, conference.Id, handRaised), Times.Once);
            }
        }
Ejemplo n.º 11
0
        public async Task Should_Throw_ParticipantNotFoundException_With_No_ParticipantId()
        {
            var participantUsername = "******";
            var conference          = CreateTestConference(participantUsername);

            var conferenceId      = conference.Id;
            var participantId     = Guid.Empty;
            var transferDirection = TransferDirection.In;

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

            SetupEventHubClientsForAllParticipantsInConference(conference, true);

            await Hub.SendTransferRequest(conferenceId, participantId, transferDirection);

            foreach (var p in conference.Participants)
            {
                EventHubClientMock.Verify(
                    x => x.Group(p.Username.ToLowerInvariant())
                    .HearingTransfer(conferenceId, participantId, transferDirection), Times.Never);
            }

            EventHubClientMock.Verify(
                x => x.Group(EventHub.Hub.EventHub.VhOfficersGroupName)
                .HearingTransfer(conferenceId, participantId, transferDirection), Times.Never);
        }
        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);
        }
        public async Task should_send_consultation_message_when_vho_call_starts()
        {
            _eventHandler = new VhOfficerCallEventHandler(EventHubContextMock.Object, ConferenceCache,
                                                          LoggerMock.Object, VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantForEvent = conference.Participants.First(x => x.Role == Role.Individual);


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

            await _eventHandler.HandleAsync(callbackEvent);

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(
                x => x.RequestedConsultationMessage(conference.Id, callbackEvent.TransferTo, It.IsAny <Guid>(),
                                                    _eventHandler.SourceParticipant.Id), Times.Once);
        }
Ejemplo n.º 14
0
        public async Task Should_raise_admin_consultation_message(RoomType?transferTo)
        {
            _eventHandler = new VhOfficerCallEventHandler(EventHubContextMock.Object, ConferenceCache,
                                                          LoggerMock.Object, VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantForEvent = conference.Participants.First(x => x.Role == Role.Individual);


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

            await _eventHandler.HandleAsync(callbackEvent);

            EventHubClientMock.Verify(x =>
                                      x.AdminConsultationMessage(conference.Id, transferTo.Value,
                                                                 participantForEvent.Username.ToLowerInvariant(), null),
                                      Times.Once);
        }
Ejemplo n.º 15
0
        public async Task Should_Send_TransferRequest_To_VhoOfficers_Group_And_Judge()
        {
            var participantUsername = "******";
            var conference          = InitConference(participantUsername);
            var participant         = conference.Participants.First(x => x.Username == participantUsername);
            var judge     = conference.Participants.First(x => x.Role == Role.Judge);
            var judgeName = judge.Username;

            var conferenceId      = conference.Id;
            var participantId     = participant.Id;
            var transferDirection = TransferDirection.In;

            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(judgeName.ToLowerInvariant())).Returns(mockJudgeClient.Object);

            await Hub.SendTransferRequest(conferenceId, participantId, transferDirection);

            mockAdminClient.Verify
            (
                x => x.HearingTransfer
                (
                    conferenceId, participantId, transferDirection
                ),
                Times.Once
            );

            mockParticipantClient.Verify
            (
                x => x.HearingTransfer
                (
                    conferenceId, participantId, transferDirection
                ),
                Times.Once
            );

            mockJudgeClient.Verify
            (
                x => x.HearingTransfer
                (
                    conferenceId, participantId, transferDirection
                ),
                Times.Once
            );
        }
        private void SetupSendMessageTests()
        {
            Conference                = InitConference();
            AdminUserProfile          = InitProfile(AdminUsername, "VhOfficer");
            JudgeUserProfile          = InitProfile(JudgeUsername, Role.Judge.ToString());
            IndividualUserProfile     = InitProfile(IndividualUsername, Role.Individual.ToString());
            RepresentativeUserProfile = InitProfile(RepresentativeUsername, Role.Representative.ToString());

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

            ConferenceGroupChannel     = new Mock <IEventHubClient>(); // only admins register to this
            JudgeGroupChannel          = new Mock <IEventHubClient>();
            IndividualGroupChannel     = new Mock <IEventHubClient>();
            RepresentativeGroupChannel = new Mock <IEventHubClient>();
            AdminGroupChannel          = new Mock <IEventHubClient>();
            ConferenceCache            = new Mock <IConferenceCache>();

            UserProfileServiceMock.Setup(x => x.GetUserAsync(JudgeUsername)).ReturnsAsync(JudgeUserProfile);
            UserProfileServiceMock.Setup(x => x.GetUserAsync(IndividualUsername)).ReturnsAsync(IndividualUserProfile);
            UserProfileServiceMock.Setup(x => x.GetUserAsync(RepresentativeUsername))
            .ReturnsAsync(RepresentativeUserProfile);
            UserProfileServiceMock.Setup(x => x.GetUserAsync(AdminUsername)).ReturnsAsync(AdminUserProfile);

            var judge          = Conference.GetJudge();
            var individual     = Conference.Participants.First(p => p.Role == Role.Individual);
            var representative = Conference.Participants.First(p => p.Role == Role.Representative);

            IndividualParticipantId     = individual.Id;
            JudgeParticipantId          = judge.Id;
            RepresentativeParticipantId = representative.Id;

            EventHubClientMock.Setup(x => x.Group(EventHub.Hub.EventHub.VhOfficersGroupName))
            .Returns(AdminGroupChannel.Object);
            EventHubClientMock.Setup(x => x.Group(Conference.Id.ToString())).Returns(ConferenceGroupChannel.Object);
            EventHubClientMock.Setup(x => x.Group(judge.Username.ToLowerInvariant())).Returns(JudgeGroupChannel.Object);
            EventHubClientMock.Setup(x => x.Group(individual.Username.ToLowerInvariant()))
            .Returns(IndividualGroupChannel.Object);
            EventHubClientMock.Setup(x => x.Group(representative.Username.ToLowerInvariant()))
            .Returns(RepresentativeGroupChannel.Object);

            ConferenceCache
            .Setup(x => x.GetOrAddConferenceAsync(Conference.Id, It.IsAny <Func <Task <ConferenceDetailsResponse> > >()))
            .Callback(async(Guid anyGuid, Func <Task <ConferenceDetailsResponse> > factory) => await factory())
            .ReturnsAsync(Conference);
        }
        private void VerifyMessageCallCount(Conference conference, Guid participantId, ParticipantMediaStatus message,
                                            Times times)
        {
            var judge = conference.Participants.Single(x => x.IsJudge());

            EventHubClientMock.Verify(
                x => x.Group(judge.Username.ToLowerInvariant())
                .ParticipantMediaStatusMessage(participantId, conference.Id,
                                               It.Is <ParticipantMediaStatus>(s =>
                                                                              s.IsLocalAudioMuted == message.IsLocalAudioMuted &&
                                                                              s.IsLocalVideoMuted == message.IsLocalVideoMuted)), times);


            EventHubClientMock.Verify(
                x => x.Group(EventHub.Hub.EventHub.VhOfficersGroupName)
                .ParticipantMediaStatusMessage(participantId, conference.Id, message), times);
        }
Ejemplo n.º 18
0
        public async Task should_not_publish_when_participant_does_not_exist()
        {
            var participantUsername = "******";
            var conference          = CreateTestConference(participantUsername, true);
            var conferenceId        = conference.Id;
            var participantId       = Guid.NewGuid();
            var isRemoteMuted       = true;

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

            await Hub.UpdateParticipantRemoteMuteStatus(conferenceId, participantId, isRemoteMuted);

            EventHubClientMock.Verify(
                x => x.Group(It.IsAny <string>())
                .ParticipantRemoteMuteMessage(participantId, conference.Id, isRemoteMuted), Times.Never);
        }
        public async Task Should_send_messages_to_participants_on_help()
        {
            _eventHandler = new HelpEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                 VideoApiClientMock.Object);

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

            await _eventHandler.HandleAsync(callbackEvent);

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(x => x.HelpMessage(conference.Id, conference.Participants.First().DisplayName));
        }
Ejemplo n.º 20
0
        public async Task Should_send_do_nothing_when_countdown_has_finished()
        {
            _eventHandler = new CountdownFinishedEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                              VideoApiClientMock.Object);

            var conference       = TestConference;
            var participantCount = conference.Participants.Count + 1; // plus one for admin
            var callbackEvent    = new CallbackEvent
            {
                EventType    = EventType.CountdownFinished,
                EventId      = Guid.NewGuid().ToString(),
                ConferenceId = conference.Id,
                TimeStampUtc = DateTime.UtcNow
            };

            await _eventHandler.HandleAsync(callbackEvent);

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(x => x.CountdownFinished(conference.Id),
                                      Times.Exactly(participantCount));
        }
Ejemplo n.º 21
0
        public async Task Should_send_messages_to_participants_on_start()
        {
            _eventHandler = new StartEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                  VideoApiClientMock.Object);

            var conference       = TestConference;
            var participantCount = conference.Participants.Count + 1; // plus one for admin
            var callbackEvent    = new CallbackEvent
            {
                EventType    = EventType.Start,
                EventId      = Guid.NewGuid().ToString(),
                ConferenceId = conference.Id,
                TimeStampUtc = DateTime.UtcNow
            };

            await _eventHandler.HandleAsync(callbackEvent);

            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(x => x.ConferenceStatusMessage(conference.Id, ConferenceStatus.InSession),
                                      Times.Exactly(participantCount));
        }
Ejemplo n.º 22
0
        public void Should_throw_exception_when_transfer_cannot_be_mapped_to_endpoint_status_cannot_be_derived()
        {
            _eventHandler = new EndpointTransferEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                             VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantForEvent = conference.Endpoints.First();
            var callbackEvent       = new CallbackEvent
            {
                EventType     = EventType.EndpointTransfer,
                EventId       = Guid.NewGuid().ToString(),
                ParticipantId = participantForEvent.Id,
                ConferenceId  = conference.Id,
                Reason        = "JVC Connection",
                TimeStampUtc  = DateTime.UtcNow
            };

            Assert.ThrowsAsync <ArgumentException>(() => _eventHandler.HandleAsync(callbackEvent)).Message.Should()
            .Be($"Unable to derive state, no {nameof(callbackEvent.TransferTo)} provided (Parameter '{nameof(callbackEvent.TransferTo)}')");
            EventHubClientMock.Verify(x => x.EndpointStatusMessage(participantForEvent.Id, conference.Id, It.IsAny <EndpointState>()),
                                      Times.Never);
        }
Ejemplo n.º 23
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.º 24
0
        public void Should_throw_exception_when_transfer_cannot_be_mapped_to_endpoint_status_cannot_be_derived()
        {
            _eventHandler = new EndpointTransferEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object,
                                                             VideoApiClientMock.Object);

            var conference          = TestConference;
            var participantForEvent = conference.Endpoints.First();
            var callbackEvent       = new CallbackEvent
            {
                EventType     = EventType.EndpointTransfer,
                EventId       = Guid.NewGuid().ToString(),
                ParticipantId = participantForEvent.Id,
                ConferenceId  = conference.Id,
                Reason        = "JVC Connection",
                TimeStampUtc  = DateTime.UtcNow
            };

            Assert.ThrowsAsync <RoomTransferException>(() => _eventHandler.HandleAsync(callbackEvent)).Message.Should()
            .StartWith("Unable to process TransferEvent from").And.EndWith("to a status");
            // Verify messages sent to event hub clients
            EventHubClientMock.Verify(x => x.EndpointStatusMessage(participantForEvent.Id, conference.Id, It.IsAny <EndpointState>()),
                                      Times.Never);
        }
Ejemplo n.º 25
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
            );
        }