コード例 #1
0
        public async Task <IList <ParticipantMediaStreamObject> > GetMediaStreams(string id)
        {
            var stringTask = await _httpClient.GetAsync(new Uri(ApiUri + _apiParticipants + id + "/media_stream/"));

            ParticipantMediaStreamResponse      participantMediaStreamResponse = new ParticipantMediaStreamResponse();
            List <ParticipantMediaStreamObject> participantMediaStreamList     = new List <ParticipantMediaStreamObject>();

            participantMediaStreamResponse = JsonConvert.DeserializeObject <ParticipantMediaStreamResponse>(stringTask.Content.ReadAsStringAsync().Result);

            // Add all the participant objects to the list
            foreach (var stream in participantMediaStreamResponse.ParticipantMediaStreamObject)
            {
                participantMediaStreamList.Add(stream);
            }

            return(participantMediaStreamList);
        }
コード例 #2
0
        public void TestGettingParticipantMediaStreams()
        {
            // Arrange

            // The URI we are using in the test
            var requestUri = new Uri("https://localhost/api/admin/status/v1/participant/f2e8df3d-cbb4-43bd-be19-e4f5633393d3/media_stream/");

            List <ParticipantMediaStreamObject> streams = new List <ParticipantMediaStreamObject>();

            streams.Add(new ParticipantMediaStreamObject {
                RxJitter     = 55,
                RxPacketLoss = 10,
                TxCodec      = "opus",
                TxPacketLoss = 0.02,
                TxJitter     = 1.49
            });
            streams.Add(new ParticipantMediaStreamObject {
                RxJitter     = 55,
                RxPacketLoss = 10,
                RxCodec      = "opus",
                TxPacketLoss = 0.02,
                TxJitter     = 1.49
            });

            MetaObject MetaObject = new MetaObject
            {
                Next = null
            };

            ParticipantMediaStreamResponse participantsMediaStreamModel = new ParticipantMediaStreamResponse
            {
                MetaObject = MetaObject,
                ParticipantMediaStreamObject = streams
            };

            // Serialise the object
            var expectedResponse = JsonConvert.SerializeObject(participantsMediaStreamModel);

            // Set up the mock with the expected response
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(expectedResponse)
            };
            var mockHandler = new Mock <HttpClientHandler>();

            mockHandler
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(message => message.RequestUri == requestUri),
                ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(mockResponse));

            // Set up the HttpClient using the mock handler object
            HttpClient client = new HttpClient(mockHandler.Object);

            // Initialise an instance of the Participants class for testing using the HttpClient
            IParticipants participants = new Participants(client, "https://localhost");

            // Act

            var participantMediaStreamResult = participants.GetMediaStreams("f2e8df3d-cbb4-43bd-be19-e4f5633393d3").Result;

            // Assert

            // Assert that a List of participants was returned with 1 item
            Assert.True(participantMediaStreamResult.Count == 2);
        }