Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create session and participant test for WebRTC #23

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Bandwidth.StandardTests/WebRtc/SessionTests.cs
Original file line number Diff line number Diff line change
@@ -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>() { 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);
}
}
}