Exemplo n.º 1
0
        public void SetHeartbeatDataRequest()
        {
            var participantId = _context.Test.ConferenceResponse.Participants.First(x => x.UserRole == UserRole.Individual).Id;
            var request       = new AddHeartbeatRequest()
            {
                OutgoingAudioPercentageLost       = LossPercentage,
                OutgoingAudioPercentageLostRecent = LossPercentage,
                IncomingAudioPercentageLost       = LossPercentage,
                IncomingAudioPercentageLostRecent = LossPercentage,
                OutgoingVideoPercentageLost       = LossPercentage,
                OutgoingVideoPercentageLostRecent = LossPercentage,
                IncomingVideoPercentageLost       = LossPercentage,
                IncomingVideoPercentageLostRecent = LossPercentage,
                BrowserName            = "Chrome",
                BrowserVersion         = "80.0",
                OperatingSystem        = "Mac OS X",
                OperatingSystemVersion = "10.15.7"
            };

            _context.Test.HeartbeatData = request;
            _context.Request            = _context.Post(SetHeartbeats(_context.Test.ConferenceResponse.Id, participantId), request);
        }
Exemplo n.º 2
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
            );
        }
Exemplo n.º 3
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
            );
        }
Exemplo n.º 4
0
        public async Task <IActionResult> SaveHeartbeatDataForParticipantAsync(Guid conferenceId, Guid participantId, AddHeartbeatRequest request)
        {
            _logger.LogDebug("SaveHeartbeatDataForParticipantAsync");

            if (request == null)
            {
                _logger.LogWarning("AddHeartbeatRequest is null");
                return(BadRequest());
            }

            var command = new SaveHeartbeatCommand
                          (
                conferenceId, participantId, request.OutgoingAudioPercentageLost,
                request.OutgoingAudioPercentageLostRecent, request.IncomingAudioPercentageLost,
                request.IncomingAudioPercentageLostRecent, request.OutgoingVideoPercentageLost,
                request.OutgoingVideoPercentageLostRecent, request.IncomingVideoPercentageLost,
                request.IncomingVideoPercentageLostRecent, DateTime.UtcNow, request.BrowserName, request.BrowserVersion,
                request.OperatingSystem, request.OperatingSystemVersion
                          );

            await _commandHandler.Handle(command);

            return(NoContent());
        }