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

refactor: video e2e refactoring #473

Merged
merged 10 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
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
39 changes: 39 additions & 0 deletions Vonage.Server.Test/TestHelpers/E2EHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Vonage.Request;
using Vonage.Server.Video;
using WireMock.Server;

namespace Vonage.Server.Test.TestHelpers
{
public class E2EHelper : IDisposable
{
private E2EHelper(string appSettingsKey, Credentials credentials)
{
this.Server = WireMockServer.Start();
var configuration = new Configuration
{
Settings =
{
[$"appSettings:{appSettingsKey}"] = this.Server.Url,
},
};
this.VonageClient = new VideoClient(credentials, configuration);
}

public WireMockServer Server { get; }
public VideoClient VonageClient { get; }

public void Dispose()
{
this.Server.Stop();
this.Server.Dispose();
}

public static E2EHelper WithBearerCredentials(string appSettingsKey) =>
new E2EHelper(appSettingsKey, CreateBearerCredentials());

private static Credentials CreateBearerCredentials() => Credentials.FromAppIdAndPrivateKey(
Guid.NewGuid().ToString(),
Environment.GetEnvironmentVariable("Vonage.Test.RsaPrivateKey"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"addStream": "12312312-3811-4726-b508-e41a0f96c68f",
"hasAudio": true,
"hasVideo": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"addStream": "12312312-3811-4726-b508-e41a0f96c68f",
"hasAudio": false,
"hasVideo": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"addStream": "12312312-3811-4726-b508-e41a0f96c68f",
"hasAudio": true,
"hasVideo": false
}
63 changes: 63 additions & 0 deletions Vonage.Server.Test/Video/Archives/AddStream/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Video.Archives.AddStream;
using WireMock.ResponseBuilders;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.AddStream
{
[Trait("Category", "E2E")]
public class E2ETest : E2EBase
{
public E2ETest() : base(typeof(E2ETest).Namespace)
{
}

[Fact]
public async Task AddStream()
{
this.SetUpServer(nameof(SerializationTest.ShouldSerialize));
await this.Helper.VonageClient.ArchiveClient.AddStreamAsync(GetRequestBuilder().Create())
.Should()
.BeSuccessAsync();
}

[Fact]
public async Task AddStreamWithoutAudio()
{
this.SetUpServer(nameof(SerializationTest.ShouldSerializeWithoutAudio));
await this.Helper.VonageClient.ArchiveClient.AddStreamAsync(GetRequestBuilder().DisableAudio().Create())
.Should()
.BeSuccessAsync();
}

[Fact]
public async Task AddStreamWithoutVideo()
{
this.SetUpServer(nameof(SerializationTest.ShouldSerializeWithoutVideo));
await this.Helper.VonageClient.ArchiveClient.AddStreamAsync(GetRequestBuilder().DisableVideo().Create())
.Should()
.BeSuccessAsync();
}

private static IBuilderForOptional GetRequestBuilder() =>
AddStreamRequest
.Build()
.WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd"))
.WithArchiveId(Guid.Parse("97425ae1-4722-4dbf-b395-6169f08ebab3"))
.WithStreamId(Guid.Parse("12312312-3811-4726-b508-e41a0f96c68f"));

private void SetUpServer(string request)
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath(
"/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/archive/97425ae1-4722-4dbf-b395-6169f08ebab3/streams")
.WithHeader("Authorization", "Bearer *")
.WithBody(this.Serialization.GetRequestJson(request))
.UsingPatch())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));
}
}
}
56 changes: 56 additions & 0 deletions Vonage.Server.Test/Video/Archives/AddStream/SerializationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using Vonage.Common;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Video.Archives.AddStream;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.AddStream
{
public class SerializationTest
{
private readonly SerializationTestHelper helper;

public SerializationTest() =>
this.helper = new SerializationTestHelper(typeof(SerializationTest).Namespace,
JsonSerializer.BuildWithCamelCase());

[Fact]
public void ShouldSerialize() =>
AddStreamRequest
.Build()
.WithApplicationId(Guid.NewGuid())
.WithArchiveId(Guid.NewGuid())
.WithStreamId(Guid.Parse("12312312-3811-4726-b508-e41a0f96c68f"))
.Create()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());

[Fact]
public void ShouldSerializeWithoutAudio() =>
AddStreamRequest
.Build()
.WithApplicationId(Guid.NewGuid())
.WithArchiveId(Guid.NewGuid())
.WithStreamId(Guid.Parse("12312312-3811-4726-b508-e41a0f96c68f"))
.DisableAudio()
.Create()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());

[Fact]
public void ShouldSerializeWithoutVideo() =>
AddStreamRequest
.Build()
.WithApplicationId(Guid.NewGuid())
.WithArchiveId(Guid.NewGuid())
.WithStreamId(Guid.Parse("12312312-3811-4726-b508-e41a0f96c68f"))
.DisableVideo()
.Create()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());
}
}
67 changes: 0 additions & 67 deletions Vonage.Server.Test/Video/Archives/AddStream/UseCaseTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bestFit",
"stylesheet": "stream.instructor {position: absolute; width: 100%; height:50%;}",
"screenshareType": "pip"
}
39 changes: 39 additions & 0 deletions Vonage.Server.Test/Video/Archives/ChangeLayout/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Video.Archives.ChangeLayout;
using WireMock.ResponseBuilders;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.ChangeLayout
{
[Trait("Category", "E2E")]
public class E2ETest : E2EBase
{
public E2ETest() : base(typeof(E2ETest).Namespace)
{
}

[Fact]
public async Task ChangeLayout()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath(
"/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/archive/97425ae1-4722-4dbf-b395-6169f08ebab3/layout")
.WithHeader("Authorization", "Bearer *")
.WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerialize)))
.UsingPut())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));
await this.Helper.VonageClient.ArchiveClient.ChangeLayoutAsync(ChangeLayoutRequest
.Build()
.WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd"))
.WithArchiveId(Guid.Parse("97425ae1-4722-4dbf-b395-6169f08ebab3"))
.WithLayout(new Layout(LayoutType.Pip,
"stream.instructor {position: absolute; width: 100%; height:50%;}", LayoutType.BestFit))
.Create())
.Should()
.BeSuccessAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Vonage.Common;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Video.Archives.ChangeLayout;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.ChangeLayout
{
public class SerializationTest
{
private readonly SerializationTestHelper helper;

public SerializationTest() =>
this.helper = new SerializationTestHelper(typeof(SerializationTest).Namespace,
JsonSerializer.BuildWithCamelCase());

[Fact]
public void ShouldSerialize() =>
ChangeLayoutRequest
.Build()
.WithApplicationId(Guid.NewGuid())
.WithArchiveId(Guid.NewGuid())
.WithLayout(new Layout(LayoutType.Pip,
"stream.instructor {position: absolute; width: 100%; height:50%;}", LayoutType.BestFit))
.Create()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());
}
}
Loading
Loading