diff --git a/Vonage.Server.Test/TestHelpers/E2EHelper.cs b/Vonage.Server.Test/TestHelpers/E2EHelper.cs new file mode 100644 index 000000000..9bff6b865 --- /dev/null +++ b/Vonage.Server.Test/TestHelpers/E2EHelper.cs @@ -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")); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerialize-request.json new file mode 100644 index 000000000..3f55eec82 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerialize-request.json @@ -0,0 +1,5 @@ +{ + "addStream": "12312312-3811-4726-b508-e41a0f96c68f", + "hasAudio": true, + "hasVideo": true +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerializeWithoutAudio-request.json b/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerializeWithoutAudio-request.json new file mode 100644 index 000000000..636afcfef --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerializeWithoutAudio-request.json @@ -0,0 +1,5 @@ +{ + "addStream": "12312312-3811-4726-b508-e41a0f96c68f", + "hasAudio": false, + "hasVideo": true +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerializeWithoutVideo-request.json b/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerializeWithoutVideo-request.json new file mode 100644 index 000000000..63c70b4ab --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/AddStream/Data/ShouldSerializeWithoutVideo-request.json @@ -0,0 +1,5 @@ +{ + "addStream": "12312312-3811-4726-b508-e41a0f96c68f", + "hasAudio": true, + "hasVideo": false +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/AddStream/E2ETest.cs b/Vonage.Server.Test/Video/Archives/AddStream/E2ETest.cs new file mode 100644 index 000000000..130f108e3 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/AddStream/E2ETest.cs @@ -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)); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/AddStream/SerializationTest.cs b/Vonage.Server.Test/Video/Archives/AddStream/SerializationTest.cs new file mode 100644 index 000000000..e6c20697e --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/AddStream/SerializationTest.cs @@ -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()); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/AddStream/UseCaseTest.cs b/Vonage.Server.Test/Video/Archives/AddStream/UseCaseTest.cs deleted file mode 100644 index 6ce719252..000000000 --- a/Vonage.Server.Test/Video/Archives/AddStream/UseCaseTest.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using AutoFixture; -using AutoFixture.Kernel; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common.Client; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.TestHelpers; -using Vonage.Server.Video.Archives; -using Vonage.Server.Video.Archives.AddStream; -using Xunit; - -namespace Vonage.Server.Test.Video.Archives.AddStream -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new ArchiveClient(configuration).AddStreamAsync(this.request); - - private readonly Result request; - - public UseCaseTest() => this.request = BuildRequest(this.Helper.Fixture); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new ArchiveClient(configuration).AddStreamAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => - await this.Helper.VerifyReturnsUnitGivenApiResponseIsSuccess(this.BuildExpectedRequest(), this.Operation); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = new HttpMethod("PATCH"), - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - Content = this.request - .Map(value => this.Helper.Serializer.SerializeObject(new - {AddStream = value.StreamId, value.HasAudio, value.HasVideo})) - .IfFailure(string.Empty), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - AddStreamRequest.Build() - .WithApplicationId(fixture.Create()) - .WithArchiveId(fixture.Create()) - .WithStreamId(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/ChangeLayout/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Archives/ChangeLayout/Data/ShouldSerialize-request.json new file mode 100644 index 000000000..68d0ff128 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/ChangeLayout/Data/ShouldSerialize-request.json @@ -0,0 +1,5 @@ +{ + "type": "bestFit", + "stylesheet": "stream.instructor {position: absolute; width: 100%; height:50%;}", + "screenshareType": "pip" +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/ChangeLayout/E2ETest.cs b/Vonage.Server.Test/Video/Archives/ChangeLayout/E2ETest.cs new file mode 100644 index 000000000..df2aebc5d --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/ChangeLayout/E2ETest.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/ChangeLayout/SerializationTest.cs b/Vonage.Server.Test/Video/Archives/ChangeLayout/SerializationTest.cs new file mode 100644 index 000000000..05031bb12 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/ChangeLayout/SerializationTest.cs @@ -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()); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/ChangeLayout/UseCaseTest.cs b/Vonage.Server.Test/Video/Archives/ChangeLayout/UseCaseTest.cs deleted file mode 100644 index 124de6834..000000000 --- a/Vonage.Server.Test/Video/Archives/ChangeLayout/UseCaseTest.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using AutoFixture; -using AutoFixture.Kernel; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common.Client; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.TestHelpers; -using Vonage.Server.Video.Archives; -using Vonage.Server.Video.Archives.ChangeLayout; -using Xunit; - -namespace Vonage.Server.Test.Video.Archives.ChangeLayout -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new ArchiveClient(configuration).ChangeLayoutAsync(this.request); - - private readonly Result request; - - public UseCaseTest() => this.request = BuildRequest(this.Helper.Fixture); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new ArchiveClient(configuration).ChangeLayoutAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => - await this.Helper.VerifyReturnsUnitGivenApiResponseIsSuccess(this.BuildExpectedRequest(), this.Operation); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = HttpMethod.Put, - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - Content = this.request - .Map(value => this.Helper.Serializer.SerializeObject(new {value.Layout})) - .IfFailure(string.Empty), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - ChangeLayoutRequest.Build() - .WithApplicationId(fixture.Create()) - .WithArchiveId(fixture.Create()) - .WithLayout(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/CreateArchive/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Archives/CreateArchive/Data/ShouldSerialize-request.json new file mode 100644 index 000000000..b599a44dd --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/CreateArchive/Data/ShouldSerialize-request.json @@ -0,0 +1,14 @@ +{ + "sessionId": "flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN", + "hasAudio": false, + "hasVideo": false, + "layout": { + "type": "bestFit", + "stylesheet": "stream.instructor {position: absolute; width: 100%; height:50%;}", + "screenshareType": "pip" + }, + "name": "Foo", + "outputMode": "individual", + "resolution": "1280x720", + "streamMode": "manual" +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/CreateArchive/Data/ShouldSerializeDefault-request.json b/Vonage.Server.Test/Video/Archives/CreateArchive/Data/ShouldSerializeDefault-request.json new file mode 100644 index 000000000..dd87fb985 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/CreateArchive/Data/ShouldSerializeDefault-request.json @@ -0,0 +1,8 @@ +{ + "sessionId": "flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN", + "hasAudio": true, + "hasVideo": true, + "outputMode": "composed", + "resolution": "640x480", + "streamMode": "auto" +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/CreateArchive/E2ETest.cs b/Vonage.Server.Test/Video/Archives/CreateArchive/E2ETest.cs new file mode 100644 index 000000000..faf776728 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/CreateArchive/E2ETest.cs @@ -0,0 +1,60 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Archives.CreateArchive; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Archives.CreateArchive +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task CreateArchive() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath("/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/archive") + .WithHeader("Authorization", "Bearer *") + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.ArchiveClient.CreateArchiveAsync(CreateArchiveRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithArchiveLayout(new Layout(LayoutType.Pip, + "stream.instructor {position: absolute; width: 100%; height:50%;}", LayoutType.BestFit)) + .WithName("Foo") + .WithOutputMode(OutputMode.Individual) + .WithRenderResolution(RenderResolution.HighDefinitionLandscape) + .WithStreamMode(StreamMode.Manual) + .DisableVideo() + .DisableAudio() + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyArchive); + } + + [Fact] + public async Task CreateDefaultArchive() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath("/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/archive") + .WithHeader("Authorization", "Bearer *") + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.ArchiveClient.CreateArchiveAsync(CreateArchiveRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyArchive); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/CreateArchive/SerializationTest.cs b/Vonage.Server.Test/Video/Archives/CreateArchive/SerializationTest.cs index d32e55f36..027982c1e 100644 --- a/Vonage.Server.Test/Video/Archives/CreateArchive/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Archives/CreateArchive/SerializationTest.cs @@ -1,8 +1,10 @@ -using FluentAssertions; +using System; +using FluentAssertions; using Vonage.Common.Test; using Vonage.Common.Test.Extensions; using Vonage.Server.Serialization; using Vonage.Server.Video.Archives; +using Vonage.Server.Video.Archives.CreateArchive; using Xunit; namespace Vonage.Server.Test.Video.Archives.CreateArchive @@ -20,28 +22,60 @@ public void ShouldDeserialize200() => this.helper.Serializer .DeserializeObject(this.helper.GetResponseJson()) .Should() - .BeSuccess(success => - { - success.Id.Should().Be("b40ef09b-3811-4726-b508-e41a0f96c68f"); - success.Name.Should().Be("Foo"); - success.CreatedAt.Should().Be(1384221730000); - success.Duration.Should().Be(5049); - success.HasAudio.Should().BeTrue(); - success.HasVideo.Should().BeTrue(); - success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); - success.Reason.Should().Be("random"); - success.Resolution.Should().Be(RenderResolution.FullHighDefinitionLandscape); - success.SessionId.Should().Be("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"); - success.Size.Should().Be(247748791); - success.Status.Should().Be("available"); - success.StreamMode.Should().Be("manual"); - success.Url.Should() - .Be( - "https://tokbox.com.archive2.s3.amazonaws.com/123456/09141e29-8770-439b-b180-337d7e637545/archive.mp4"); - success.Streams.Length.Should().Be(1); - success.Streams[0].StreamId.Should().Be("abc123"); - success.Streams[0].HasAudio.Should().BeTrue(); - success.Streams[0].HasVideo.Should().BeTrue(); - }); + .BeSuccess(VerifyArchive); + + [Fact] + public void ShouldSerialize() => + CreateArchiveRequest + .Build() + .WithApplicationId(Guid.NewGuid()) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithArchiveLayout(new Layout(LayoutType.Pip, + "stream.instructor {position: absolute; width: 100%; height:50%;}", LayoutType.BestFit)) + .WithName("Foo") + .WithOutputMode(OutputMode.Individual) + .WithRenderResolution(RenderResolution.HighDefinitionLandscape) + .WithStreamMode(StreamMode.Manual) + .DisableVideo() + .DisableAudio() + .Create() + .GetStringContent() + .Should() + .BeSuccess(this.helper.GetRequestJson()); + + [Fact] + public void ShouldSerializeDefault() => + CreateArchiveRequest + .Build() + .WithApplicationId(Guid.NewGuid()) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .Create() + .GetStringContent() + .Should() + .BeSuccess(this.helper.GetRequestJson()); + + internal static void VerifyArchive(Archive success) + { + success.Id.Should().Be("b40ef09b-3811-4726-b508-e41a0f96c68f"); + success.Name.Should().Be("Foo"); + success.CreatedAt.Should().Be(1384221730000); + success.Duration.Should().Be(5049); + success.HasAudio.Should().BeTrue(); + success.HasVideo.Should().BeTrue(); + success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); + success.Reason.Should().Be("random"); + success.Resolution.Should().Be(RenderResolution.FullHighDefinitionLandscape); + success.SessionId.Should().Be("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"); + success.Size.Should().Be(247748791); + success.Status.Should().Be("available"); + success.StreamMode.Should().Be("manual"); + success.Url.Should() + .Be( + "https://tokbox.com.archive2.s3.amazonaws.com/123456/09141e29-8770-439b-b180-337d7e637545/archive.mp4"); + success.Streams.Length.Should().Be(1); + success.Streams[0].StreamId.Should().Be("abc123"); + success.Streams[0].HasAudio.Should().BeTrue(); + success.Streams[0].HasVideo.Should().BeTrue(); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/CreateArchive/UseCaseTest.cs b/Vonage.Server.Test/Video/Archives/CreateArchive/UseCaseTest.cs deleted file mode 100644 index 174744a13..000000000 --- a/Vonage.Server.Test/Video/Archives/CreateArchive/UseCaseTest.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using AutoFixture; -using AutoFixture.Kernel; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common.Client; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.TestHelpers; -using Vonage.Server.Video.Archives; -using Vonage.Server.Video.Archives.CreateArchive; -using Xunit; - -namespace Vonage.Server.Test.Video.Archives.CreateArchive -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new ArchiveClient(configuration).CreateArchiveAsync(this.request); - - private readonly Result request; - - public UseCaseTest() => this.request = BuildRequest(this.Helper.Fixture); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenApiResponseCannotBeParsed() => - await this.Helper.VerifyReturnsFailureGivenApiResponseCannotBeParsed(this.BuildExpectedRequest(), - this.Operation); - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new ArchiveClient(configuration).CreateArchiveAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => - await this.Helper.VerifyReturnsExpectedValueGivenApiResponseIsSuccess(this.BuildExpectedRequest(), - this.Operation); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = HttpMethod.Post, - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - Content = this.request - .Map(value => this.Helper.Serializer.SerializeObject(value)) - .IfFailure(string.Empty), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - CreateArchiveRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/DeleteArchive/E2ETest.cs b/Vonage.Server.Test/Video/Archives/DeleteArchive/E2ETest.cs new file mode 100644 index 000000000..51608075b --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/DeleteArchive/E2ETest.cs @@ -0,0 +1,35 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Archives.DeleteArchive; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Archives.DeleteArchive +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task DeleteArchive() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/archive/97425ae1-4722-4dbf-b395-6169f08ebab3") + .WithHeader("Authorization", "Bearer *") + .UsingDelete()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + await this.Helper.VonageClient.ArchiveClient.DeleteArchiveAsync(DeleteArchiveRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithArchiveId(Guid.Parse("97425ae1-4722-4dbf-b395-6169f08ebab3")) + .Create()) + .Should() + .BeSuccessAsync(); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/DeleteArchive/UseCaseTest.cs b/Vonage.Server.Test/Video/Archives/DeleteArchive/UseCaseTest.cs deleted file mode 100644 index ba9eb5837..000000000 --- a/Vonage.Server.Test/Video/Archives/DeleteArchive/UseCaseTest.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using AutoFixture; -using AutoFixture.Kernel; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common.Client; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.TestHelpers; -using Vonage.Server.Video.Archives; -using Vonage.Server.Video.Archives.DeleteArchive; -using Xunit; - -namespace Vonage.Server.Test.Video.Archives.DeleteArchive -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new ArchiveClient(configuration).DeleteArchiveAsync(this.request); - - private readonly Result request; - - public UseCaseTest() => this.request = BuildRequest(this.Helper.Fixture); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new ArchiveClient(configuration).DeleteArchiveAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => - await this.Helper.VerifyReturnsUnitGivenApiResponseIsSuccess(this.BuildExpectedRequest(), this.Operation); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = HttpMethod.Delete, - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - DeleteArchiveRequest.Build() - .WithApplicationId(fixture.Create()) - .WithArchiveId(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/GetArchive/E2ETest.cs b/Vonage.Server.Test/Video/Archives/GetArchive/E2ETest.cs new file mode 100644 index 000000000..8521d0817 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/GetArchive/E2ETest.cs @@ -0,0 +1,36 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Archives.GetArchive; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Archives.GetArchive +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task GetArchive() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/archive/97425ae1-4722-4dbf-b395-6169f08ebab3") + .WithHeader("Authorization", "Bearer *") + .UsingGet()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.ArchiveClient.GetArchiveAsync(GetArchiveRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithArchiveId(Guid.Parse("97425ae1-4722-4dbf-b395-6169f08ebab3")) + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyArchive); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/GetArchive/SerializationTest.cs b/Vonage.Server.Test/Video/Archives/GetArchive/SerializationTest.cs index 72c483da7..4e24588f0 100644 --- a/Vonage.Server.Test/Video/Archives/GetArchive/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Archives/GetArchive/SerializationTest.cs @@ -20,28 +20,30 @@ public void ShouldDeserialize200() => this.helper.Serializer .DeserializeObject(this.helper.GetResponseJson()) .Should() - .BeSuccess(success => - { - success.Id.Should().Be("b40ef09b-3811-4726-b508-e41a0f96c68f"); - success.Name.Should().Be("Foo"); - success.CreatedAt.Should().Be(1384221730000); - success.Duration.Should().Be(5049); - success.HasAudio.Should().BeTrue(); - success.HasVideo.Should().BeTrue(); - success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); - success.Reason.Should().Be("random"); - success.Resolution.Should().Be(RenderResolution.FullHighDefinitionLandscape); - success.SessionId.Should().Be("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"); - success.Size.Should().Be(247748791); - success.Status.Should().Be("available"); - success.StreamMode.Should().Be("manual"); - success.Url.Should() - .Be( - "https://tokbox.com.archive2.s3.amazonaws.com/123456/09141e29-8770-439b-b180-337d7e637545/archive.mp4"); - success.Streams.Length.Should().Be(1); - success.Streams[0].StreamId.Should().Be("abc123"); - success.Streams[0].HasAudio.Should().BeTrue(); - success.Streams[0].HasVideo.Should().BeTrue(); - }); + .BeSuccess(VerifyArchive); + + internal static void VerifyArchive(Archive success) + { + success.Id.Should().Be("b40ef09b-3811-4726-b508-e41a0f96c68f"); + success.Name.Should().Be("Foo"); + success.CreatedAt.Should().Be(1384221730000); + success.Duration.Should().Be(5049); + success.HasAudio.Should().BeTrue(); + success.HasVideo.Should().BeTrue(); + success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); + success.Reason.Should().Be("random"); + success.Resolution.Should().Be(RenderResolution.FullHighDefinitionLandscape); + success.SessionId.Should().Be("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"); + success.Size.Should().Be(247748791); + success.Status.Should().Be("available"); + success.StreamMode.Should().Be("manual"); + success.Url.Should() + .Be( + "https://tokbox.com.archive2.s3.amazonaws.com/123456/09141e29-8770-439b-b180-337d7e637545/archive.mp4"); + success.Streams.Length.Should().Be(1); + success.Streams[0].StreamId.Should().Be("abc123"); + success.Streams[0].HasAudio.Should().BeTrue(); + success.Streams[0].HasVideo.Should().BeTrue(); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/GetArchive/UseCaseTest.cs b/Vonage.Server.Test/Video/Archives/GetArchive/UseCaseTest.cs deleted file mode 100644 index 4c91fc910..000000000 --- a/Vonage.Server.Test/Video/Archives/GetArchive/UseCaseTest.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using AutoFixture; -using AutoFixture.Kernel; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common.Client; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.TestHelpers; -using Vonage.Server.Video.Archives; -using Vonage.Server.Video.Archives.GetArchive; -using Xunit; - -namespace Vonage.Server.Test.Video.Archives.GetArchive -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new ArchiveClient(configuration).GetArchiveAsync(this.request); - - private readonly Result request; - - public UseCaseTest() => this.request = BuildRequest(this.Helper.Fixture); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenApiResponseCannotBeParsed() => - await this.Helper.VerifyReturnsFailureGivenApiResponseCannotBeParsed(this.BuildExpectedRequest(), - this.Operation); - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new ArchiveClient(configuration).GetArchiveAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => - await this.Helper.VerifyReturnsExpectedValueGivenApiResponseIsSuccess(this.BuildExpectedRequest(), - this.Operation); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = HttpMethod.Get, - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - GetArchiveRequest.Build().WithApplicationId(fixture.Create()).WithArchiveId(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/GetArchives/E2ETest.cs b/Vonage.Server.Test/Video/Archives/GetArchives/E2ETest.cs new file mode 100644 index 000000000..8b66e45aa --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/GetArchives/E2ETest.cs @@ -0,0 +1,41 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Archives.GetArchives; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Archives.GetArchives +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task GetArchives() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/archive") + .WithParam("offset", "1000") + .WithParam("count", "100") + .WithParam("sessionId", "flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithHeader("Authorization", "Bearer *") + .UsingGet()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.ArchiveClient.GetArchivesAsync(GetArchivesRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithOffset(1000) + .WithCount(100) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyArchives); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/GetArchives/SerializationTest.cs b/Vonage.Server.Test/Video/Archives/GetArchives/SerializationTest.cs index 6e915b41d..347cf9c00 100644 --- a/Vonage.Server.Test/Video/Archives/GetArchives/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Archives/GetArchives/SerializationTest.cs @@ -20,30 +20,32 @@ public void ShouldDeserialize200() => this.helper.Serializer .DeserializeObject(this.helper.GetResponseJson()) .Should() - .BeSuccess(success => - { - success.Count.Should().Be(1); - success.Items.Length.Should().Be(1); - success.Items[0].Id.Should().Be("b40ef09b-3811-4726-b508-e41a0f96c68f"); - success.Items[0].Name.Should().Be("Foo"); - success.Items[0].CreatedAt.Should().Be(1384221730000); - success.Items[0].Duration.Should().Be(5049); - success.Items[0].HasAudio.Should().BeTrue(); - success.Items[0].HasVideo.Should().BeTrue(); - success.Items[0].ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); - success.Items[0].Reason.Should().Be("random"); - success.Items[0].Resolution.Should().Be(RenderResolution.FullHighDefinitionLandscape); - success.Items[0].SessionId.Should().Be("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"); - success.Items[0].Size.Should().Be(247748791); - success.Items[0].Status.Should().Be("available"); - success.Items[0].StreamMode.Should().Be("manual"); - success.Items[0].Url.Should() - .Be( - "https://tokbox.com.archive2.s3.amazonaws.com/123456/09141e29-8770-439b-b180-337d7e637545/archive.mp4"); - success.Items[0].Streams.Length.Should().Be(1); - success.Items[0].Streams[0].StreamId.Should().Be("abc123"); - success.Items[0].Streams[0].HasAudio.Should().BeTrue(); - success.Items[0].Streams[0].HasVideo.Should().BeTrue(); - }); + .BeSuccess(VerifyArchives); + + internal static void VerifyArchives(GetArchivesResponse success) + { + success.Count.Should().Be(1); + success.Items.Length.Should().Be(1); + success.Items[0].Id.Should().Be("b40ef09b-3811-4726-b508-e41a0f96c68f"); + success.Items[0].Name.Should().Be("Foo"); + success.Items[0].CreatedAt.Should().Be(1384221730000); + success.Items[0].Duration.Should().Be(5049); + success.Items[0].HasAudio.Should().BeTrue(); + success.Items[0].HasVideo.Should().BeTrue(); + success.Items[0].ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); + success.Items[0].Reason.Should().Be("random"); + success.Items[0].Resolution.Should().Be(RenderResolution.FullHighDefinitionLandscape); + success.Items[0].SessionId.Should().Be("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"); + success.Items[0].Size.Should().Be(247748791); + success.Items[0].Status.Should().Be("available"); + success.Items[0].StreamMode.Should().Be("manual"); + success.Items[0].Url.Should() + .Be( + "https://tokbox.com.archive2.s3.amazonaws.com/123456/09141e29-8770-439b-b180-337d7e637545/archive.mp4"); + success.Items[0].Streams.Length.Should().Be(1); + success.Items[0].Streams[0].StreamId.Should().Be("abc123"); + success.Items[0].Streams[0].HasAudio.Should().BeTrue(); + success.Items[0].Streams[0].HasVideo.Should().BeTrue(); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/GetArchives/UseCaseTest.cs b/Vonage.Server.Test/Video/Archives/GetArchives/UseCaseTest.cs deleted file mode 100644 index 87ac2af0d..000000000 --- a/Vonage.Server.Test/Video/Archives/GetArchives/UseCaseTest.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using AutoFixture; -using AutoFixture.Kernel; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common.Client; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.TestHelpers; -using Vonage.Server.Video.Archives; -using Vonage.Server.Video.Archives.GetArchives; -using Xunit; - -namespace Vonage.Server.Test.Video.Archives.GetArchives -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new ArchiveClient(configuration).GetArchivesAsync(this.request); - - private readonly Result request; - - public UseCaseTest() => this.request = BuildRequest(this.Helper.Fixture); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenApiResponseCannotBeParsed() => - await this.Helper.VerifyReturnsFailureGivenApiResponseCannotBeParsed(this.BuildExpectedRequest(), - this.Operation); - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new ArchiveClient(configuration).GetArchivesAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => - await this.Helper.VerifyReturnsExpectedValueGivenApiResponseIsSuccess(this.BuildExpectedRequest(), - this.Operation); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = HttpMethod.Get, - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - GetArchivesRequest.Build().WithApplicationId(fixture.Create()).Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/RemoveStream/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Archives/RemoveStream/Data/ShouldSerialize-request.json new file mode 100644 index 000000000..9db985ce5 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/RemoveStream/Data/ShouldSerialize-request.json @@ -0,0 +1,3 @@ +{ + "removeStream": "12312312-3811-4726-b508-e41a0f96c68f" +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/RemoveStream/E2ETest.cs b/Vonage.Server.Test/Video/Archives/RemoveStream/E2ETest.cs new file mode 100644 index 000000000..ceb83ceba --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/RemoveStream/E2ETest.cs @@ -0,0 +1,38 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Archives.RemoveStream; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Archives.RemoveStream +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task RemoveStream() + { + 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(nameof(SerializationTest.ShouldSerialize))) + .UsingPatch()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + await this.Helper.VonageClient.ArchiveClient.RemoveStreamAsync(RemoveStreamRequest + .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")) + .Create()) + .Should() + .BeSuccessAsync(); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/RemoveStream/SerializationTest.cs b/Vonage.Server.Test/Video/Archives/RemoveStream/SerializationTest.cs new file mode 100644 index 000000000..66fefb39c --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/RemoveStream/SerializationTest.cs @@ -0,0 +1,30 @@ +using System; +using Vonage.Common; +using Vonage.Common.Test; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Archives.RemoveStream; +using Xunit; + +namespace Vonage.Server.Test.Video.Archives.RemoveStream +{ + public class SerializationTest + { + private readonly SerializationTestHelper helper; + + public SerializationTest() => + this.helper = new SerializationTestHelper(typeof(SerializationTest).Namespace, + JsonSerializer.BuildWithCamelCase()); + + [Fact] + public void ShouldSerialize() => + RemoveStreamRequest + .Build() + .WithApplicationId(Guid.NewGuid()) + .WithArchiveId(Guid.NewGuid()) + .WithStreamId(Guid.Parse("12312312-3811-4726-b508-e41a0f96c68f")) + .Create() + .GetStringContent() + .Should() + .BeSuccess(this.helper.GetRequestJson()); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/RemoveStream/UseCaseTest.cs b/Vonage.Server.Test/Video/Archives/RemoveStream/UseCaseTest.cs deleted file mode 100644 index baf1a0229..000000000 --- a/Vonage.Server.Test/Video/Archives/RemoveStream/UseCaseTest.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using AutoFixture; -using AutoFixture.Kernel; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common.Client; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.TestHelpers; -using Vonage.Server.Video.Archives; -using Vonage.Server.Video.Archives.RemoveStream; -using Xunit; - -namespace Vonage.Server.Test.Video.Archives.RemoveStream -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new ArchiveClient(configuration).RemoveStreamAsync(this.request); - - private readonly Result request; - - public UseCaseTest() => this.request = BuildRequest(this.Helper.Fixture); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new ArchiveClient(configuration).RemoveStreamAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => - await this.Helper.VerifyReturnsUnitGivenApiResponseIsSuccess(this.BuildExpectedRequest(), this.Operation); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = new HttpMethod("PATCH"), - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - Content = this.request - .Map(value => this.Helper.Serializer.SerializeObject(new {RemoveStream = value.StreamId})) - .IfFailure(string.Empty), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - RemoveStreamRequest.Build() - .WithApplicationId(fixture.Create()) - .WithArchiveId(fixture.Create()) - .WithStreamId(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/StopArchive/E2ETest.cs b/Vonage.Server.Test/Video/Archives/StopArchive/E2ETest.cs new file mode 100644 index 000000000..e1b9f1f72 --- /dev/null +++ b/Vonage.Server.Test/Video/Archives/StopArchive/E2ETest.cs @@ -0,0 +1,37 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Archives.StopArchive; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Archives.StopArchive +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task RemoveStream() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/archive/97425ae1-4722-4dbf-b395-6169f08ebab3/stop") + .WithHeader("Authorization", "Bearer *") + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.ArchiveClient.StopArchiveAsync(StopArchiveRequest + .Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithArchiveId(Guid.Parse("97425ae1-4722-4dbf-b395-6169f08ebab3")) + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyArchive); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/StopArchive/SerializationTest.cs b/Vonage.Server.Test/Video/Archives/StopArchive/SerializationTest.cs index 2fd433c75..5a7e66f5e 100644 --- a/Vonage.Server.Test/Video/Archives/StopArchive/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Archives/StopArchive/SerializationTest.cs @@ -20,28 +20,30 @@ public void ShouldDeserialize200() => this.helper.Serializer .DeserializeObject(this.helper.GetResponseJson()) .Should() - .BeSuccess(success => - { - success.Id.Should().Be("b40ef09b-3811-4726-b508-e41a0f96c68f"); - success.Name.Should().Be("Foo"); - success.CreatedAt.Should().Be(1384221730000); - success.Duration.Should().Be(5049); - success.HasAudio.Should().BeTrue(); - success.HasVideo.Should().BeTrue(); - success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); - success.Reason.Should().Be("random"); - success.Resolution.Should().Be(RenderResolution.FullHighDefinitionLandscape); - success.SessionId.Should().Be("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"); - success.Size.Should().Be(247748791); - success.Status.Should().Be("available"); - success.StreamMode.Should().Be("manual"); - success.Url.Should() - .Be( - "https://tokbox.com.archive2.s3.amazonaws.com/123456/09141e29-8770-439b-b180-337d7e637545/archive.mp4"); - success.Streams.Length.Should().Be(1); - success.Streams[0].StreamId.Should().Be("abc123"); - success.Streams[0].HasAudio.Should().BeTrue(); - success.Streams[0].HasVideo.Should().BeTrue(); - }); + .BeSuccess(VerifyArchive); + + internal static void VerifyArchive(Archive success) + { + success.Id.Should().Be("b40ef09b-3811-4726-b508-e41a0f96c68f"); + success.Name.Should().Be("Foo"); + success.CreatedAt.Should().Be(1384221730000); + success.Duration.Should().Be(5049); + success.HasAudio.Should().BeTrue(); + success.HasVideo.Should().BeTrue(); + success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); + success.Reason.Should().Be("random"); + success.Resolution.Should().Be(RenderResolution.FullHighDefinitionLandscape); + success.SessionId.Should().Be("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"); + success.Size.Should().Be(247748791); + success.Status.Should().Be("available"); + success.StreamMode.Should().Be("manual"); + success.Url.Should() + .Be( + "https://tokbox.com.archive2.s3.amazonaws.com/123456/09141e29-8770-439b-b180-337d7e637545/archive.mp4"); + success.Streams.Length.Should().Be(1); + success.Streams[0].StreamId.Should().Be("abc123"); + success.Streams[0].HasAudio.Should().BeTrue(); + success.Streams[0].HasVideo.Should().BeTrue(); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Archives/StopArchive/UseCaseTest.cs b/Vonage.Server.Test/Video/Archives/StopArchive/UseCaseTest.cs deleted file mode 100644 index 27ca295fe..000000000 --- a/Vonage.Server.Test/Video/Archives/StopArchive/UseCaseTest.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using AutoFixture; -using AutoFixture.Kernel; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common.Client; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.TestHelpers; -using Vonage.Server.Video.Archives; -using Vonage.Server.Video.Archives.StopArchive; -using Xunit; - -namespace Vonage.Server.Test.Video.Archives.StopArchive -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new ArchiveClient(configuration).StopArchiveAsync(this.request); - - private readonly Result request; - - public UseCaseTest() => this.request = BuildRequest(this.Helper.Fixture); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenApiResponseCannotBeParsed() => - await this.Helper.VerifyReturnsFailureGivenApiResponseCannotBeParsed(this.BuildExpectedRequest(), - this.Operation); - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new ArchiveClient(configuration).StopArchiveAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => - await this.Helper.VerifyReturnsExpectedValueGivenApiResponseIsSuccess(this.BuildExpectedRequest(), - this.Operation); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = HttpMethod.Post, - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - StopArchiveRequest.Build() - .WithApplicationId(fixture.Create()) - .WithArchiveId(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Broadcast/ChangeBroadcastLayout/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Broadcast/ChangeBroadcastLayout/Data/ShouldSerialize-request.json index f3039ea94..68d0ff128 100644 --- a/Vonage.Server.Test/Video/Broadcast/ChangeBroadcastLayout/Data/ShouldSerialize-request.json +++ b/Vonage.Server.Test/Video/Broadcast/ChangeBroadcastLayout/Data/ShouldSerialize-request.json @@ -1,5 +1,5 @@ { - "screenshareType": "pip", + "type": "bestFit", "stylesheet": "stream.instructor {position: absolute; width: 100%; height:50%;}", - "type": "bestFit" + "screenshareType": "pip" } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Broadcast/StartBroadcast/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Broadcast/StartBroadcast/Data/ShouldSerialize-request.json index 2171613bd..29f731e74 100644 --- a/Vonage.Server.Test/Video/Broadcast/StartBroadcast/Data/ShouldSerialize-request.json +++ b/Vonage.Server.Test/Video/Broadcast/StartBroadcast/Data/ShouldSerialize-request.json @@ -1,8 +1,8 @@ { "sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4", "layout": { - "screenshareType": "horizontalPresentation", - "type": "bestFit" + "type": "bestFit", + "screenshareType": "horizontalPresentation" }, "maxDuration": 20000, "maxBitrate": 500, diff --git a/Vonage.Server.Test/Video/Broadcast/StartBroadcast/Data/ShouldSerializeWithDefaultValues-request.json b/Vonage.Server.Test/Video/Broadcast/StartBroadcast/Data/ShouldSerializeWithDefaultValues-request.json index 38e8876c1..3ad2d4b11 100644 --- a/Vonage.Server.Test/Video/Broadcast/StartBroadcast/Data/ShouldSerializeWithDefaultValues-request.json +++ b/Vonage.Server.Test/Video/Broadcast/StartBroadcast/Data/ShouldSerializeWithDefaultValues-request.json @@ -1,8 +1,8 @@ { "sessionId": "2_MX4xMDBfjE0Mzc2NzY1NDgwMTJ-TjMzfn4", "layout": { - "stylesheet": "the layout stylesheet (only used with type == custom)", - "type": "custom" + "type": "custom", + "stylesheet": "the layout stylesheet (only used with type == custom)" }, "maxDuration": 14400, "maxBitrate": 1000, diff --git a/Vonage.Server.Test/Video/E2EBase.cs b/Vonage.Server.Test/Video/E2EBase.cs new file mode 100644 index 000000000..9d9745200 --- /dev/null +++ b/Vonage.Server.Test/Video/E2EBase.cs @@ -0,0 +1,17 @@ +using Vonage.Common; +using Vonage.Common.Test; +using Vonage.Server.Test.TestHelpers; + +namespace Vonage.Server.Test.Video +{ + public abstract class E2EBase + { + private E2EBase() => this.Helper = E2EHelper.WithBearerCredentials("Vonage.Url.Api.Video"); + + protected E2EBase(string serializationNamespace) : this() => this.Serialization = + new SerializationTestHelper(serializationNamespace, JsonSerializer.BuildWithCamelCase()); + + internal readonly E2EHelper Helper; + internal readonly SerializationTestHelper Serialization; + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Vonage.Server.Test.csproj b/Vonage.Server.Test/Vonage.Server.Test.csproj index c089711c1..2270de29c 100644 --- a/Vonage.Server.Test/Vonage.Server.Test.csproj +++ b/Vonage.Server.Test/Vonage.Server.Test.csproj @@ -127,6 +127,27 @@ Always + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/Vonage.Server/Layout.cs b/Vonage.Server/Layout.cs index 609853f88..099a464c9 100644 --- a/Vonage.Server/Layout.cs +++ b/Vonage.Server/Layout.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Text.Json.Serialization; namespace Vonage.Server; @@ -22,9 +23,9 @@ namespace Vonage.Server; /// stylesheet property.). /// public record Layout( - LayoutType? ScreenshareType, - string Stylesheet, - LayoutType Type); + [property: JsonPropertyOrder(2)] LayoutType? ScreenshareType, + [property: JsonPropertyOrder(1)] string Stylesheet, + [property: JsonPropertyOrder(0)] LayoutType Type); /// /// Represents the layout type. diff --git a/Vonage.Server/Video/Archives/ChangeLayout/ChangeLayoutRequest.cs b/Vonage.Server/Video/Archives/ChangeLayout/ChangeLayoutRequest.cs index f0a59ec3e..1c0329f68 100644 --- a/Vonage.Server/Video/Archives/ChangeLayout/ChangeLayoutRequest.cs +++ b/Vonage.Server/Video/Archives/ChangeLayout/ChangeLayoutRequest.cs @@ -40,7 +40,7 @@ public HttpRequestMessage BuildRequestMessage() => public string GetEndpointPath() => $"/v2/project/{this.ApplicationId}/archive/{this.ArchiveId}/layout"; private StringContent GetRequestContent() => - new(JsonSerializerBuilder.Build().SerializeObject(new {this.Layout}), + new(JsonSerializerBuilder.Build().SerializeObject(this.Layout), Encoding.UTF8, "application/json"); } \ No newline at end of file diff --git a/Vonage.Server/Video/Archives/CreateArchive/CreateArchiveRequest.cs b/Vonage.Server/Video/Archives/CreateArchive/CreateArchiveRequest.cs index 3c797636a..7585d096e 100644 --- a/Vonage.Server/Video/Archives/CreateArchive/CreateArchiveRequest.cs +++ b/Vonage.Server/Video/Archives/CreateArchive/CreateArchiveRequest.cs @@ -5,6 +5,7 @@ using Vonage.Common.Client; using Vonage.Common.Client.Builders; using Vonage.Common.Monads; +using Vonage.Common.Serialization; using Vonage.Server.Serialization; namespace Vonage.Server.Video.Archives.CreateArchive; @@ -22,28 +23,35 @@ namespace Vonage.Server.Video.Archives.CreateArchive; /// Whether the archive will record audio (true, the default) or not (false). If you set both hasAudio and hasVideo to /// false, the call to this method results in an error. /// + [JsonPropertyOrder(1)] public bool HasAudio { get; internal init; } /// /// Whether the archive will record video (true, the default) or not (false). If you set both hasAudio and hasVideo to /// false, the call to this method results in an error. /// + [JsonPropertyOrder(2)] public bool HasVideo { get; internal init; } /// /// Represents the archive's layout. /// + [JsonPropertyOrder(3)] public Layout Layout { get; internal init; } /// /// The name of the archive (for your own identification). /// + [JsonPropertyOrder(4)] + [JsonConverter(typeof(MaybeJsonConverter))] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public Maybe Name { get; internal init; } /// /// Whether all streams in the archive are recorded to a single file ("composed", the default) or to individual files /// ("individual"). /// + [JsonPropertyOrder(5)] public OutputMode OutputMode { get; internal init; } /// @@ -53,9 +61,11 @@ namespace Vonage.Server.Video.Archives.CreateArchive; /// portrait aspect ratio). This property only applies to composed archives. If you set this property and set the /// outputMode property to "individual", the call to the REST method results in an error. /// + [JsonPropertyOrder(6)] public RenderResolution Resolution { get; internal init; } /// + [JsonPropertyOrder(0)] public string SessionId { get; internal init; } /// @@ -65,6 +75,7 @@ namespace Vonage.Server.Video.Archives.CreateArchive; /// You can specify whether a stream's audio, video, or both are included in the archive. In composed archives, in both /// automatic and manual modes, the archive composer includes streams based on stream prioritization rules. /// + [JsonPropertyOrder(7)] public StreamMode StreamMode { get; internal init; } /// diff --git a/Vonage.Server/Video/VideoClient.cs b/Vonage.Server/Video/VideoClient.cs index 45c3771e5..541a498d4 100644 --- a/Vonage.Server/Video/VideoClient.cs +++ b/Vonage.Server/Video/VideoClient.cs @@ -1,5 +1,7 @@ -using System.Net.Http; +using System; +using System.Net.Http; using Vonage.Common.Client; +using Vonage.Common.Monads; using Vonage.Request; using Vonage.Server.Video.Archives; using Vonage.Server.Video.Broadcast; @@ -14,6 +16,7 @@ namespace Vonage.Server.Video; public class VideoClient : IVideoClient { private Credentials credentials; + private readonly Maybe configuration = Maybe.None; /// public ArchiveClient ArchiveClient { get; private set; } @@ -51,28 +54,36 @@ public Credentials Credentials /// Credentials to be used for further clients. public VideoClient(Credentials credentials) => this.Credentials = credentials; + internal VideoClient(Credentials credentials, Configuration configuration) + { + this.configuration = configuration; + this.Credentials = credentials; + } + private VonageHttpClientConfiguration BuildClientConfiguration() => new( - InitializeHttpClient(), + InitializeHttpClient(this.GetConfiguration().VideoApiUrl), this.Credentials.GetAuthenticationHeader(), this.Credentials.GetUserAgent()); + private Configuration GetConfiguration() => this.configuration.IfNone(Configuration.Instance); + private void InitializeClients() { - var configuration = this.BuildClientConfiguration(); - this.SessionClient = new SessionClient(configuration); - this.SignalingClient = new SignalingClient(configuration); - this.ModerationClient = new ModerationClient(configuration); - this.ArchiveClient = new ArchiveClient(configuration); - this.BroadcastClient = new BroadcastClient(configuration); - this.SipClient = new SipClient(configuration); + var videoConfiguration = this.BuildClientConfiguration(); + this.SessionClient = new SessionClient(videoConfiguration); + this.SignalingClient = new SignalingClient(videoConfiguration); + this.ModerationClient = new ModerationClient(videoConfiguration); + this.ArchiveClient = new ArchiveClient(videoConfiguration); + this.BroadcastClient = new BroadcastClient(videoConfiguration); + this.SipClient = new SipClient(videoConfiguration); } - private static HttpClient InitializeHttpClient() + private static HttpClient InitializeHttpClient(Uri baseUri) { var client = new HttpClient(new HttpClientHandler()) { - BaseAddress = Configuration.Instance.VideoApiUrl, + BaseAddress = baseUri, }; client.DefaultRequestHeaders.Add("Accept", "application/json"); return client; diff --git a/Vonage.Server/Vonage.Server.csproj b/Vonage.Server/Vonage.Server.csproj index 59f266ec1..88e28e7a1 100644 --- a/Vonage.Server/Vonage.Server.csproj +++ b/Vonage.Server/Vonage.Server.csproj @@ -50,8 +50,9 @@ false + - + @@ -75,4 +76,7 @@ lib\netstandard2.0 + + + \ No newline at end of file diff --git a/Vonage.Test.Unit/SubAccounts/GetSubAccounts/UseCaseTest.cs b/Vonage.Test.Unit/SubAccounts/GetSubAccounts/UseCaseTest.cs deleted file mode 100644 index ba931057e..000000000 --- a/Vonage.Test.Unit/SubAccounts/GetSubAccounts/UseCaseTest.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using AutoFixture; -using FluentAssertions; -using FsCheck; -using FsCheck.Xunit; -using Vonage.Common; -using Vonage.Common.Client; -using Vonage.Common.Failures; -using Vonage.Common.Monads; -using Vonage.Common.Test; -using Vonage.Common.Test.Extensions; -using Vonage.Common.Test.TestHelpers; -using Vonage.SubAccounts; -using Vonage.SubAccounts.GetSubAccounts; -using Xunit; - -namespace Vonage.Test.Unit.SubAccounts.GetSubAccounts -{ - public class UseCaseTest : BaseUseCase - { - private static Func>> Operation => - configuration => new SubAccountsClient(configuration, ApiKey).GetSubAccountsAsync(); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.helper.VerifyReturnsFailureGivenErrorCannotBeParsed(BuildExpectedRequest(), Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenApiResponseCannotBeParsed() - { - var body = this.helper.Fixture.Create(); - var messageHandler = FakeHttpRequestHandler - .Build(HttpStatusCode.OK) - .WithExpectedRequest(BuildExpectedRequest()) - .WithResponseContent(body); - var result = await Operation(this.BuildConfiguration(messageHandler)); - result.Should() - .BeFailure(DeserializationFailure.From(typeof(EmbeddedResponse), body)); - } - - [Property] - public Property ShouldReturnFailure_GivenApiResponseIsError() => - this.helper.VerifyReturnsFailureGivenApiResponseIsError(BuildExpectedRequest(), Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.helper.VerifyReturnsFailureGivenTokenGenerationFails(Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() - { - var expectedResponse = this.helper.Fixture.Create>(); - var messageHandler = FakeHttpRequestHandler - .Build(HttpStatusCode.OK) - .WithExpectedRequest(BuildExpectedRequest()) - .WithResponseContent(this.helper.Serializer.SerializeObject(expectedResponse)); - var result = await Operation(this.BuildConfiguration(messageHandler)); - result.Should().BeSuccess(success => - { - success.PrimaryAccount.Should().Be(expectedResponse.Content.PrimaryAccount); - success.SubAccounts.Should().BeEquivalentTo(expectedResponse.Content.SubAccounts); - }); - } - - private VonageHttpClientConfiguration BuildConfiguration(FakeHttpRequestHandler handler) => - new VonageHttpClientConfiguration( - handler.ToHttpClient(), - new AuthenticationHeaderValue("Basic", this.helper.Fixture.Create()), - this.helper.Fixture.Create()); - - private static ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = HttpMethod.Get, - RequestUri = new Uri(GetSubAccountsRequest.Build(ApiKey).GetEndpointPath(), UriKind.Relative), - }; - } -} \ No newline at end of file diff --git a/Vonage/Vonage.csproj b/Vonage/Vonage.csproj index 3120c08e3..8baedf662 100644 --- a/Vonage/Vonage.csproj +++ b/Vonage/Vonage.csproj @@ -87,4 +87,7 @@ lib\netstandard2.0 + + + \ No newline at end of file