From 90f31d7e815146a0e7aa1473ecfcad3edd08e1e7 Mon Sep 17 00:00:00 2001 From: Mike Hamer Date: Wed, 16 Jun 2021 10:50:59 -0400 Subject: [PATCH] Add create session and participant test for WebRTC --- .../WebRtc/SessionTests.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Bandwidth.StandardTests/WebRtc/SessionTests.cs diff --git a/Bandwidth.StandardTests/WebRtc/SessionTests.cs b/Bandwidth.StandardTests/WebRtc/SessionTests.cs new file mode 100644 index 00000000..07625ceb --- /dev/null +++ b/Bandwidth.StandardTests/WebRtc/SessionTests.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Bandwidth.Standard; +using Bandwidth.Standard.WebRtc.Models; +using Xunit; + +namespace Bandwidth.StandardTests.WebRtc +{ + public class SessionTests + { + private BandwidthClient _client; + + public SessionTests() + { + _client = new BandwidthClient.Builder() + .Environment(Bandwidth.Standard.Environment.Production) + .WebRtcBasicAuthCredentials(TestConstants.Username, TestConstants.Password) + .Build(); + } + + [Fact] + public async Task CreateSessionAndAddParticipant() + { + var accountId = TestConstants.AccountId; + + var session = new Session(); + session.Tag = "new-session"; + + var createSessionResponse = await _client.WebRtc.APIController.CreateSessionAsync(accountId, session); + + Assert.NotEmpty(createSessionResponse.Data.Id); + Assert.Equal("new-session", createSessionResponse.Data.Tag); + + var sessionId = createSessionResponse.Data.Id; + + var publishPermissions = new List() { PublishPermissionEnum.AUDIO, PublishPermissionEnum.VIDEO }; + var callbackUrl = string.Concat(TestConstants.BaseCallbackUrl, "/callbacks/participant"); + + var participant = new Participant() + { + PublishPermissions = publishPermissions, + CallbackUrl = callbackUrl + }; + + var createParticipantResponse = await _client.WebRtc.APIController.CreateParticipantAsync(accountId, participant); + + Assert.NotEmpty(createParticipantResponse.Data.Token); + Assert.NotNull(createParticipantResponse.Data.Participant); + Assert.NotEmpty(createParticipantResponse.Data.Participant.Id); + + Assert.True(createParticipantResponse.Data.Participant.PublishPermissions.Count == 2); + Assert.Contains(PublishPermissionEnum.AUDIO, createParticipantResponse.Data.Participant.PublishPermissions); + Assert.Contains(PublishPermissionEnum.VIDEO, createParticipantResponse.Data.Participant.PublishPermissions); + + var participantId = createParticipantResponse.Data.Participant.Id; + + await _client.WebRtc.APIController.AddParticipantToSessionAsync(accountId, sessionId, participantId); + await _client.WebRtc.APIController.RemoveParticipantFromSessionAsync(accountId, participantId, sessionId); + + await _client.WebRtc.APIController.DeleteParticipantAsync(accountId, participantId); + await _client.WebRtc.APIController.DeleteSessionAsync(accountId, sessionId); + } + } +}