Esempio n. 1
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
            );
        }
Esempio n. 2
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
            );
        }