From 4f44d01e0e343a1af02238184ec92aece47319db Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 08:42:20 +0200 Subject: [PATCH 01/11] Add E2E for DisconnectConnection --- .../DisconnectConnection/E2ETest.cs | 37 +++++++++++ .../DisconnectConnection/UseCaseTest.cs | 63 ------------------- 2 files changed, 37 insertions(+), 63 deletions(-) create mode 100644 Vonage.Server.Test/Video/Moderation/DisconnectConnection/E2ETest.cs delete mode 100644 Vonage.Server.Test/Video/Moderation/DisconnectConnection/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Moderation/DisconnectConnection/E2ETest.cs b/Vonage.Server.Test/Video/Moderation/DisconnectConnection/E2ETest.cs new file mode 100644 index 000000000..f0221e468 --- /dev/null +++ b/Vonage.Server.Test/Video/Moderation/DisconnectConnection/E2ETest.cs @@ -0,0 +1,37 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Moderation.DisconnectConnection; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Moderation.DisconnectConnection +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task DisconnectConnection() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/connection/97425ae1-4722-4dbf-b395-6169f08ebab3") + .WithHeader("Authorization", "Bearer *") + .UsingDelete()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + await this.Helper.VonageClient.ModerationClient.DisconnectConnectionAsync(DisconnectConnectionRequest + .Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithConnectionId("97425ae1-4722-4dbf-b395-6169f08ebab3") + .Create()) + .Should() + .BeSuccessAsync(); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Moderation/DisconnectConnection/UseCaseTest.cs b/Vonage.Server.Test/Video/Moderation/DisconnectConnection/UseCaseTest.cs deleted file mode 100644 index d99bbfb08..000000000 --- a/Vonage.Server.Test/Video/Moderation/DisconnectConnection/UseCaseTest.cs +++ /dev/null @@ -1,63 +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.Moderation; -using Vonage.Server.Video.Moderation.DisconnectConnection; -using Xunit; - -namespace Vonage.Server.Test.Video.Moderation.DisconnectConnection -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new ModerationClient(configuration).DisconnectConnectionAsync(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 ModerationClient(configuration).DisconnectConnectionAsync(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) => - DisconnectConnectionRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithConnectionId(fixture.Create()) - .Create(); - } -} \ No newline at end of file From 161e5ec691534c90300b63004312bec1bf19175d Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 08:49:34 +0200 Subject: [PATCH 02/11] Add E2E for MuteStream --- .../Video/Moderation/MuteStream/EETest.cs | 37 ++++++++++ .../MuteStream/SerializationTest.cs | 18 ++--- .../Moderation/MuteStream/UseCaseTest.cs | 69 ------------------- 3 files changed, 47 insertions(+), 77 deletions(-) create mode 100644 Vonage.Server.Test/Video/Moderation/MuteStream/EETest.cs delete mode 100644 Vonage.Server.Test/Video/Moderation/MuteStream/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Moderation/MuteStream/EETest.cs b/Vonage.Server.Test/Video/Moderation/MuteStream/EETest.cs new file mode 100644 index 000000000..e3c7f0237 --- /dev/null +++ b/Vonage.Server.Test/Video/Moderation/MuteStream/EETest.cs @@ -0,0 +1,37 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Moderation.MuteStream; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Moderation.MuteStream +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task MuteStream() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/stream/97425ae1-4722-4dbf-b395-6169f08ebab3/mute") + .WithHeader("Authorization", "Bearer *") + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.ModerationClient.MuteStreamAsync(MuteStreamRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithStreamId("97425ae1-4722-4dbf-b395-6169f08ebab3") + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyResponse); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Moderation/MuteStream/SerializationTest.cs b/Vonage.Server.Test/Video/Moderation/MuteStream/SerializationTest.cs index 2644227e7..87663453c 100644 --- a/Vonage.Server.Test/Video/Moderation/MuteStream/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Moderation/MuteStream/SerializationTest.cs @@ -21,13 +21,15 @@ public SerializationTest() public void ShouldDeserialize200() => this.helper.Serializer.DeserializeObject(this.helper.GetResponseJson()) .Should() - .BeSuccess(success => - { - success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); - success.Status.Should().Be("ACTIVE"); - success.Name.Should().Be("Joe Montana"); - success.Environment.Should().Be("standard"); - success.CreatedAt.Should().Be(1414642898000); - }); + .BeSuccess(VerifyResponse); + + internal static void VerifyResponse(MuteStreamResponse success) + { + success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); + success.Status.Should().Be("ACTIVE"); + success.Name.Should().Be("Joe Montana"); + success.Environment.Should().Be("standard"); + success.CreatedAt.Should().Be(1414642898000); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Moderation/MuteStream/UseCaseTest.cs b/Vonage.Server.Test/Video/Moderation/MuteStream/UseCaseTest.cs deleted file mode 100644 index 9b867f3f6..000000000 --- a/Vonage.Server.Test/Video/Moderation/MuteStream/UseCaseTest.cs +++ /dev/null @@ -1,69 +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.Moderation; -using Vonage.Server.Video.Moderation.MuteStream; -using Xunit; - -namespace Vonage.Server.Test.Video.Moderation.MuteStream -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new ModerationClient(configuration).MuteStreamAsync(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 ModerationClient(configuration).MuteStreamAsync(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) => - MuteStreamRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithStreamId(fixture.Create()) - .Create(); - } -} \ No newline at end of file From 4a99dbdfc2613a28f1cd80de793e895c7dff76d7 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 09:12:29 +0200 Subject: [PATCH 03/11] Add E2E for MuteStreams --- .../Data/ShouldSerialize-request.json | 7 ++ .../Video/Moderation/MuteStreams/E2ETest.cs | 39 ++++++++++ .../MuteStreams/RequestBuilderTest.cs | 75 +++++++++++++++++++ .../Moderation/MuteStreams/RequestTest.cs | 60 +-------------- .../MuteStreams/SerializationTest.cs | 41 ++++++---- .../Moderation/MuteStreams/UseCaseTest.cs | 72 ------------------ Vonage.Server.Test/Vonage.Server.Test.csproj | 3 + 7 files changed, 155 insertions(+), 142 deletions(-) create mode 100644 Vonage.Server.Test/Video/Moderation/MuteStreams/Data/ShouldSerialize-request.json create mode 100644 Vonage.Server.Test/Video/Moderation/MuteStreams/E2ETest.cs create mode 100644 Vonage.Server.Test/Video/Moderation/MuteStreams/RequestBuilderTest.cs delete mode 100644 Vonage.Server.Test/Video/Moderation/MuteStreams/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Moderation/MuteStreams/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Moderation/MuteStreams/Data/ShouldSerialize-request.json new file mode 100644 index 000000000..9c42dd5a2 --- /dev/null +++ b/Vonage.Server.Test/Video/Moderation/MuteStreams/Data/ShouldSerialize-request.json @@ -0,0 +1,7 @@ +{ + "active": true, + "excludedStreamIds": [ + "excludedStream1", + "excludedStream2" + ] +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Moderation/MuteStreams/E2ETest.cs b/Vonage.Server.Test/Video/Moderation/MuteStreams/E2ETest.cs new file mode 100644 index 000000000..b340074da --- /dev/null +++ b/Vonage.Server.Test/Video/Moderation/MuteStreams/E2ETest.cs @@ -0,0 +1,39 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Moderation.MuteStreams; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Moderation.MuteStreams +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task MuteStreams() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/mute") + .WithHeader("Authorization", "Bearer *") + .WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerialize))) + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.ModerationClient.MuteStreamsAsync(MuteStreamsRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithConfiguration(new MuteStreamsRequest.MuteStreamsConfiguration(true, + new[] {"excludedStream1", "excludedStream2"})) + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyResponse); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Moderation/MuteStreams/RequestBuilderTest.cs b/Vonage.Server.Test/Video/Moderation/MuteStreams/RequestBuilderTest.cs new file mode 100644 index 000000000..26e54ab79 --- /dev/null +++ b/Vonage.Server.Test/Video/Moderation/MuteStreams/RequestBuilderTest.cs @@ -0,0 +1,75 @@ +using System; +using AutoFixture; +using FluentAssertions; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Moderation.MuteStreams; +using Xunit; + +namespace Vonage.Server.Test.Video.Moderation.MuteStreams +{ + public class RequestBuilderTest + { + private readonly Fixture fixture; + private readonly Guid applicationId; + private readonly MuteStreamsRequest.MuteStreamsConfiguration configuration; + private readonly string sessionId; + + public RequestBuilderTest() + { + this.fixture = new Fixture(); + this.applicationId = this.fixture.Create(); + this.sessionId = this.fixture.Create(); + this.configuration = this.fixture.Create(); + } + + [Fact] + public void Build_ShouldReturnFailure_GivenApplicationIdIsNullOrWhitespace() => + MuteStreamsRequest.Build() + .WithApplicationId(Guid.Empty) + .WithSessionId(this.sessionId) + .WithConfiguration(this.configuration) + .Create() + .Should() + .BeParsingFailure("ApplicationId cannot be empty."); + + [Fact] + public void Build_ShouldReturnFailure_GivenExcludedStreamsIdsAreNull() => + MuteStreamsRequest.Build() + .WithApplicationId(this.applicationId) + .WithSessionId(this.sessionId) + .WithConfiguration(new MuteStreamsRequest.MuteStreamsConfiguration(this.fixture.Create(), null)) + .Create() + .Should() + .BeParsingFailure("ExcludedStreamIds cannot be null."); + + [Theory] + [InlineData("")] + [InlineData(" ")] + [InlineData(null)] + public void Build_ShouldReturnFailure_GivenSessionIdIsNullOrWhitespace(string value) => + MuteStreamsRequest.Build() + .WithApplicationId(this.applicationId) + .WithSessionId(value) + .WithConfiguration(this.configuration) + .Create() + .Should() + .BeParsingFailure("SessionId cannot be null or whitespace."); + + [Fact] + public void Build_ShouldReturnSuccess_GivenValuesAreProvided() => + MuteStreamsRequest.Build() + .WithApplicationId(this.applicationId) + .WithSessionId(this.sessionId) + .WithConfiguration(this.configuration) + .Create() + .Should() + .BeSuccess(request => + { + request.ApplicationId.Should().Be(this.applicationId); + request.SessionId.Should().Be(this.sessionId); + request.Configuration.Active.Should().Be(this.configuration.Active); + request.Configuration.ExcludedStreamIds.Should() + .BeEquivalentTo(this.configuration.ExcludedStreamIds); + }); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Moderation/MuteStreams/RequestTest.cs b/Vonage.Server.Test/Video/Moderation/MuteStreams/RequestTest.cs index 92ad5f93a..ddddac0a3 100644 --- a/Vonage.Server.Test/Video/Moderation/MuteStreams/RequestTest.cs +++ b/Vonage.Server.Test/Video/Moderation/MuteStreams/RequestTest.cs @@ -1,6 +1,5 @@ using System; using AutoFixture; -using FluentAssertions; using Vonage.Common.Test.Extensions; using Vonage.Server.Video.Moderation.MuteStreams; using Xunit; @@ -9,17 +8,16 @@ namespace Vonage.Server.Test.Video.Moderation.MuteStreams { public class RequestTest { - private readonly Fixture fixture; private readonly Guid applicationId; private readonly MuteStreamsRequest.MuteStreamsConfiguration configuration; private readonly string sessionId; public RequestTest() { - this.fixture = new Fixture(); - this.applicationId = this.fixture.Create(); - this.sessionId = this.fixture.Create(); - this.configuration = this.fixture.Create(); + var fixture = new Fixture(); + this.applicationId = fixture.Create(); + this.sessionId = fixture.Create(); + this.configuration = fixture.Create(); } [Fact] @@ -33,55 +31,5 @@ public void GetEndpointPath_ShouldReturnApiEndpoint() => .Should() .BeSuccess( $"/v2/project/{this.applicationId}/session/{this.sessionId}/mute"); - - [Fact] - public void Parse_ShouldReturnFailure_GivenApplicationIdIsNullOrWhitespace() => - MuteStreamsRequest.Build() - .WithApplicationId(Guid.Empty) - .WithSessionId(this.sessionId) - .WithConfiguration(this.configuration) - .Create() - .Should() - .BeParsingFailure("ApplicationId cannot be empty."); - - [Fact] - public void Parse_ShouldReturnFailure_GivenExcludedStreamsIdsAreNull() => - MuteStreamsRequest.Build() - .WithApplicationId(this.applicationId) - .WithSessionId(this.sessionId) - .WithConfiguration(new MuteStreamsRequest.MuteStreamsConfiguration(this.fixture.Create(), null)) - .Create() - .Should() - .BeParsingFailure("ExcludedStreamIds cannot be null."); - - [Theory] - [InlineData("")] - [InlineData(" ")] - [InlineData(null)] - public void Parse_ShouldReturnFailure_GivenSessionIdIsNullOrWhitespace(string value) => - MuteStreamsRequest.Build() - .WithApplicationId(this.applicationId) - .WithSessionId(value) - .WithConfiguration(this.configuration) - .Create() - .Should() - .BeParsingFailure("SessionId cannot be null or whitespace."); - - [Fact] - public void Parse_ShouldReturnSuccess_GivenValuesAreProvided() => - MuteStreamsRequest.Build() - .WithApplicationId(this.applicationId) - .WithSessionId(this.sessionId) - .WithConfiguration(this.configuration) - .Create() - .Should() - .BeSuccess(request => - { - request.ApplicationId.Should().Be(this.applicationId); - request.SessionId.Should().Be(this.sessionId); - request.Configuration.Active.Should().Be(this.configuration.Active); - request.Configuration.ExcludedStreamIds.Should() - .BeEquivalentTo(this.configuration.ExcludedStreamIds); - }); } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Moderation/MuteStreams/SerializationTest.cs b/Vonage.Server.Test/Video/Moderation/MuteStreams/SerializationTest.cs index 451a277d0..ce68f240e 100644 --- a/Vonage.Server.Test/Video/Moderation/MuteStreams/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Moderation/MuteStreams/SerializationTest.cs @@ -1,4 +1,5 @@ -using FluentAssertions; +using System; +using FluentAssertions; using Vonage.Common.Test; using Vonage.Common.Test.Extensions; using Vonage.Server.Serialization; @@ -11,23 +12,35 @@ public class SerializationTest { private readonly SerializationTestHelper helper; - public SerializationTest() - { - this.helper = new SerializationTestHelper(typeof(SerializationTest).Namespace, - JsonSerializerBuilder.Build()); - } + public SerializationTest() => + this.helper = + new SerializationTestHelper(typeof(SerializationTest).Namespace, JsonSerializerBuilder.Build()); [Fact] public void ShouldDeserialize200() => this.helper.Serializer.DeserializeObject(this.helper.GetResponseJson()) .Should() - .BeSuccess(success => - { - success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); - success.Status.Should().Be("ACTIVE"); - success.Name.Should().Be("Joe Montana"); - success.Environment.Should().Be("standard"); - success.CreatedAt.Should().Be(1414642898000); - }); + .BeSuccess(VerifyResponse); + + [Fact] + public void ShouldSerialize() => + MuteStreamsRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithConfiguration( + new MuteStreamsRequest.MuteStreamsConfiguration(true, new[] {"excludedStream1", "excludedStream2"})) + .Create() + .GetStringContent() + .Should() + .BeSuccess(this.helper.GetRequestJson()); + + internal static void VerifyResponse(MuteStreamsResponse success) + { + success.ApplicationId.Should().Be("78d335fa-323d-0114-9c3d-d6f0d48968cf"); + success.Status.Should().Be("ACTIVE"); + success.Name.Should().Be("Joe Montana"); + success.Environment.Should().Be("standard"); + success.CreatedAt.Should().Be(1414642898000); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Moderation/MuteStreams/UseCaseTest.cs b/Vonage.Server.Test/Video/Moderation/MuteStreams/UseCaseTest.cs deleted file mode 100644 index 407e458cc..000000000 --- a/Vonage.Server.Test/Video/Moderation/MuteStreams/UseCaseTest.cs +++ /dev/null @@ -1,72 +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.Moderation; -using Vonage.Server.Video.Moderation.MuteStreams; -using Xunit; - -namespace Vonage.Server.Test.Video.Moderation.MuteStreams -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new ModerationClient(configuration).MuteStreamsAsync(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 ModerationClient(configuration).MuteStreamsAsync(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.Configuration)) - .IfFailure(string.Empty), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - MuteStreamsRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithConfiguration(fixture.Create()) - .Create(); - } -} \ 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 2270de29c..f0af0f5ce 100644 --- a/Vonage.Server.Test/Vonage.Server.Test.csproj +++ b/Vonage.Server.Test/Vonage.Server.Test.csproj @@ -148,6 +148,9 @@ PreserveNewest + + PreserveNewest + From 30635b71e55c596f0f2c5545fd110396f44e2f69 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 11:01:11 +0200 Subject: [PATCH 04/11] Add E2E to ChangeStreamLayout --- .../Data/ShouldSerialize-request.json | 10 +++ .../Sessions/ChangeStreamLayout/E2ETest.cs | 38 +++++++++++ .../ChangeStreamLayout/SerializationTest.cs | 29 ++++++++ .../ChangeStreamLayout/UseCaseTest.cs | 66 ------------------- Vonage.Server.Test/Vonage.Server.Test.csproj | 3 + 5 files changed, 80 insertions(+), 66 deletions(-) create mode 100644 Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/Data/ShouldSerialize-request.json create mode 100644 Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/E2ETest.cs create mode 100644 Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/SerializationTest.cs delete mode 100644 Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/Data/ShouldSerialize-request.json new file mode 100644 index 000000000..ee4dcc8b8 --- /dev/null +++ b/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/Data/ShouldSerialize-request.json @@ -0,0 +1,10 @@ +{ + "items": [ + { + "id": "8b732909-0a06-46a2-8ea8-074e64d43422", + "layoutClassList": [ + "full" + ] + } + ] +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/E2ETest.cs b/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/E2ETest.cs new file mode 100644 index 000000000..3daa552f8 --- /dev/null +++ b/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/E2ETest.cs @@ -0,0 +1,38 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Sessions.ChangeStreamLayout; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Sessions.ChangeStreamLayout +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task ChangeStreamLayout() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/stream") + .WithHeader("Authorization", "Bearer *") + .WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerialize))) + .UsingPut()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + await this.Helper.VonageClient.SessionClient.ChangeStreamLayoutAsync(ChangeStreamLayoutRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithItem(new ChangeStreamLayoutRequest.LayoutItem("8b732909-0a06-46a2-8ea8-074e64d43422", + new[] {"full"})) + .Create()) + .Should() + .BeSuccessAsync(); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/SerializationTest.cs b/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/SerializationTest.cs new file mode 100644 index 000000000..bff33e5fc --- /dev/null +++ b/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/SerializationTest.cs @@ -0,0 +1,29 @@ +using System; +using Vonage.Common.Test; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Serialization; +using Vonage.Server.Video.Sessions.ChangeStreamLayout; +using Xunit; + +namespace Vonage.Server.Test.Video.Sessions.ChangeStreamLayout +{ + public class SerializationTest + { + private readonly SerializationTestHelper helper; + + public SerializationTest() => this.helper = + new SerializationTestHelper(typeof(SerializationTest).Namespace, JsonSerializerBuilder.Build()); + + [Fact] + public void ShouldSerialize() => + ChangeStreamLayoutRequest.Build() + .WithApplicationId(Guid.NewGuid()) + .WithSessionId("SomeSessionId") + .WithItem(new ChangeStreamLayoutRequest.LayoutItem("8b732909-0a06-46a2-8ea8-074e64d43422", + new[] {"full"})) + .Create() + .GetStringContent() + .Should() + .BeSuccess(this.helper.GetRequestJson()); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/UseCaseTest.cs b/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/UseCaseTest.cs deleted file mode 100644 index 0b82e7d40..000000000 --- a/Vonage.Server.Test/Video/Sessions/ChangeStreamLayout/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.Sessions; -using Vonage.Server.Video.Sessions.ChangeStreamLayout; -using Xunit; - -namespace Vonage.Server.Test.Video.Sessions.ChangeStreamLayout -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new SessionClient(configuration).ChangeStreamLayoutAsync(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 SessionClient(configuration).ChangeStreamLayoutAsync(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.Items})) - .IfFailure(string.Empty), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - ChangeStreamLayoutRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithItem(fixture.Create()) - .Create(); - } -} \ 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 f0af0f5ce..e32813261 100644 --- a/Vonage.Server.Test/Vonage.Server.Test.csproj +++ b/Vonage.Server.Test/Vonage.Server.Test.csproj @@ -151,6 +151,9 @@ PreserveNewest + + PreserveNewest + From 738ce8aee816e35c89c0bc340f8ab750356c13c2 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 11:25:44 +0200 Subject: [PATCH 05/11] Add E2E for CreateSession --- .../Video/Sessions/CreateSession/E2ETest.cs | 45 +++++++++ .../CreateSession/SerializationTest.cs | 32 +++--- .../Sessions/CreateSession/UseCaseTest.cs | 98 ------------------- 3 files changed, 61 insertions(+), 114 deletions(-) create mode 100644 Vonage.Server.Test/Video/Sessions/CreateSession/E2ETest.cs delete mode 100644 Vonage.Server.Test/Video/Sessions/CreateSession/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Sessions/CreateSession/E2ETest.cs b/Vonage.Server.Test/Video/Sessions/CreateSession/E2ETest.cs new file mode 100644 index 000000000..5cf81ad37 --- /dev/null +++ b/Vonage.Server.Test/Video/Sessions/CreateSession/E2ETest.cs @@ -0,0 +1,45 @@ +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Failures; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Sessions.CreateSession; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Sessions.CreateSession +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task CreateDefaultSession() + { + this.SetUpServer(nameof(SerializationTest.ShouldDeserialize200)); + await this.Helper.VonageClient.SessionClient.CreateSessionAsync(CreateSessionRequest.Default) + .Should() + .BeSuccessAsync(session => SerializationTest.VerifySessions(new[] {session})); + } + + [Fact] + public async Task CreateSession_ShouldReturnFailure_GivenResponseContainsNoSession() + { + this.SetUpServer(nameof(SerializationTest.ShouldDeserialize200_GivenEmptyArray)); + await this.Helper.VonageClient.SessionClient.CreateSessionAsync(CreateSessionRequest.Default) + .Should() + .BeFailureAsync(ResultFailure.FromErrorMessage(CreateSessionResponse.NoSessionCreated)); + } + + private void SetUpServer(string requestNamespace) => + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath("/session/create") + .WithHeader("Authorization", "Bearer *") + .WithBody("location=&archiveMode=manual&p2p.preference=enabled") + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(requestNamespace))); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/CreateSession/SerializationTest.cs b/Vonage.Server.Test/Video/Sessions/CreateSession/SerializationTest.cs index b18e4fd7e..619732eb6 100644 --- a/Vonage.Server.Test/Video/Sessions/CreateSession/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Sessions/CreateSession/SerializationTest.cs @@ -1,6 +1,6 @@ -using System; -using FluentAssertions; +using FluentAssertions; using Vonage.Common.Test; +using Vonage.Common.Test.Extensions; using Vonage.Server.Serialization; using Vonage.Server.Video.Sessions.CreateSession; using Xunit; @@ -18,23 +18,23 @@ public SerializationTest() } [Fact] - public void ShouldDeserialize200() - { - const string expectedId = - "2_MX5hOThlMTJjYS1mM2U1LTRkZjgtYmM2Ni1mZDRiNWYzMGI5ZTl-fjE2NzI3MzY4NzgxNjJ-bi9OeFVLbkNaVjBUUnpVSmxjbURqQ3J4flB-fg"; - var response = - this.helper.Serializer.DeserializeObject(this.helper.GetResponseJson()); - var content = response.IfFailure(_ => throw new InvalidOperationException()); - content.Length.Should().Be(1); - content[0].SessionId.Should().Be(expectedId); - } + public void ShouldDeserialize200() => + this.helper.Serializer.DeserializeObject(this.helper.GetResponseJson()) + .Should() + .BeSuccess(VerifySessions); [Fact] - public void ShouldDeserialize200_GivenEmptyArray() + public void ShouldDeserialize200_GivenEmptyArray() => + this.helper.Serializer.DeserializeObject(this.helper.GetResponseJson()) + .Should() + .BeSuccess(value => value.Should().BeEmpty()); + + internal static void VerifySessions(CreateSessionResponse[] content) { - var response = - this.helper.Serializer.DeserializeObject(this.helper.GetResponseJson()); - response.IfFailure(_ => throw new InvalidOperationException()).Should().BeEmpty(); + content.Length.Should().Be(1); + content[0].SessionId.Should() + .Be( + "2_MX5hOThlMTJjYS1mM2U1LTRkZjgtYmM2Ni1mZDRiNWYzMGI5ZTl-fjE2NzI3MzY4NzgxNjJ-bi9OeFVLbkNaVjBUUnpVSmxjbURqQ3J4flB-fg"); } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/CreateSession/UseCaseTest.cs b/Vonage.Server.Test/Video/Sessions/CreateSession/UseCaseTest.cs deleted file mode 100644 index c52fa67aa..000000000 --- a/Vonage.Server.Test/Video/Sessions/CreateSession/UseCaseTest.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using AutoFixture; -using FsCheck; -using FsCheck.Xunit; -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.Server.Video.Sessions; -using Vonage.Server.Video.Sessions.CreateSession; -using Xunit; - -namespace Vonage.Server.Test.Video.Sessions.CreateSession -{ - public class UseCaseTest : BaseUseCase - { - private readonly CreateSessionRequest request = CreateSessionRequest.Default; - private readonly CreateSessionResponse session; - - private Func>> Operation => - configuration => new SessionClient(configuration).CreateSessionAsync(this.request); - - public UseCaseTest() => this.session = this.Helper.Fixture.Create(); - - [Property] - public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => - this.Helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenRequestIsFailure() => - await this.Helper.VerifyReturnsFailureGivenRequestIsFailure( - (configuration, failureRequest) => - new SessionClient(configuration).CreateSessionAsync(failureRequest)); - - [Fact] - public async Task ShouldReturnFailure_GivenResponseContainsNoSession() - { - var expectedResponse = this.Helper.Serializer.SerializeObject(Array.Empty()); - var configuration = this.BuildConfigurationWithOkResponse(expectedResponse); - var result = await this.Operation(configuration); - result.Should().BeFailure(ResultFailure.FromErrorMessage(CreateSessionResponse.NoSessionCreated)); - } - - [Property] - public Property ShouldReturnFailure_GivenStatusCodeIsFailure() => - this.Helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); - - [Fact] - public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => - await this.Helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); - - [Fact] - public async Task ShouldReturnSuccess_GivenMultipleSessionsAreCreated() - { - var expectedResponse = this.Helper.Serializer.SerializeObject(new[] - { - this.session, this.Helper.Fixture.Create(), - this.Helper.Fixture.Create(), - }); - var configuration = this.BuildConfigurationWithOkResponse(expectedResponse); - var result = await this.Operation(configuration); - result.Should().BeSuccess(this.session); - } - - [Fact] - public async Task ShouldReturnSuccess_GivenSessionIsCreated() - { - var expectedResponse = this.Helper.Serializer.SerializeObject(new[] {this.session}); - var configuration = this.BuildConfigurationWithOkResponse(expectedResponse); - var result = await this.Operation(configuration); - result.Should().BeSuccess(this.session); - } - - private VonageHttpClientConfiguration BuildConfigurationWithOkResponse(string expectedResponse) => - new VonageHttpClientConfiguration( - FakeHttpRequestHandler - .Build(HttpStatusCode.OK) - .WithExpectedRequest(this.BuildExpectedRequest()) - .WithResponseContent(expectedResponse) - .ToHttpClient(), - new AuthenticationHeaderValue("Bearer", this.Helper.Fixture.Create()), - this.Helper.Fixture.Create()); - - private ExpectedRequest BuildExpectedRequest() => - new ExpectedRequest - { - Method = HttpMethod.Post, - RequestUri = new Uri(this.request.GetEndpointPath(), UriKind.Relative), - Content = this.request.GetUrlEncoded(), - }; - } -} \ No newline at end of file From 5825abfa3bfa375fb2c6c29f50a606469d2e1fb7 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 11:29:22 +0200 Subject: [PATCH 06/11] Add E2E for GetStream --- .../Video/Sessions/GetStream/E2ETest.cs | 37 ++++++++++ .../Sessions/GetStream/SerializationTest.cs | 18 ++--- .../Video/Sessions/GetStream/UseCaseTest.cs | 69 ------------------- 3 files changed, 47 insertions(+), 77 deletions(-) create mode 100644 Vonage.Server.Test/Video/Sessions/GetStream/E2ETest.cs delete mode 100644 Vonage.Server.Test/Video/Sessions/GetStream/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Sessions/GetStream/E2ETest.cs b/Vonage.Server.Test/Video/Sessions/GetStream/E2ETest.cs new file mode 100644 index 000000000..a0483bd1e --- /dev/null +++ b/Vonage.Server.Test/Video/Sessions/GetStream/E2ETest.cs @@ -0,0 +1,37 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Sessions.GetStream; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Sessions.GetStream +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task GetStream() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/stream/stream99") + .WithHeader("Authorization", "Bearer *") + .UsingGet()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.SessionClient.GetStreamAsync(GetStreamRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithStreamId("stream99") + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyStream); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/GetStream/SerializationTest.cs b/Vonage.Server.Test/Video/Sessions/GetStream/SerializationTest.cs index 9912af0ee..733467e0f 100644 --- a/Vonage.Server.Test/Video/Sessions/GetStream/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Sessions/GetStream/SerializationTest.cs @@ -20,13 +20,15 @@ public void ShouldDeserialize200() => this.helper.Serializer .DeserializeObject(this.helper.GetResponseJson()) .Should() - .BeSuccess(success => - { - success.Id.Should().Be("8b732909-0a06-46a2-8ea8-074e64d43422"); - success.VideoType.Should().Be("camera"); - success.Name.Should().Be("random"); - success.LayoutClassList.Length.Should().Be(1); - success.LayoutClassList[0].Should().Be("full"); - }); + .BeSuccess(VerifyStream); + + internal static void VerifyStream(GetStreamResponse success) + { + success.Id.Should().Be("8b732909-0a06-46a2-8ea8-074e64d43422"); + success.VideoType.Should().Be("camera"); + success.Name.Should().Be("random"); + success.LayoutClassList.Length.Should().Be(1); + success.LayoutClassList[0].Should().Be("full"); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/GetStream/UseCaseTest.cs b/Vonage.Server.Test/Video/Sessions/GetStream/UseCaseTest.cs deleted file mode 100644 index ea1743483..000000000 --- a/Vonage.Server.Test/Video/Sessions/GetStream/UseCaseTest.cs +++ /dev/null @@ -1,69 +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.Sessions; -using Vonage.Server.Video.Sessions.GetStream; -using Xunit; - -namespace Vonage.Server.Test.Video.Sessions.GetStream -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new SessionClient(configuration).GetStreamAsync(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 SessionClient(configuration).GetStreamAsync(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) => - GetStreamRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithStreamId(fixture.Create()) - .Create(); - } -} \ No newline at end of file From c54c736ad4a60f4f229c756139ddce7abd4fbffa Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 11:32:00 +0200 Subject: [PATCH 07/11] Add E2E for GetStreams --- .../Video/Sessions/GetStreams/E2ETest.cs | 36 ++++++++++ .../Sessions/GetStreams/SerializationTest.cs | 22 +++--- .../Video/Sessions/GetStreams/UseCaseTest.cs | 68 ------------------- 3 files changed, 48 insertions(+), 78 deletions(-) create mode 100644 Vonage.Server.Test/Video/Sessions/GetStreams/E2ETest.cs delete mode 100644 Vonage.Server.Test/Video/Sessions/GetStreams/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Sessions/GetStreams/E2ETest.cs b/Vonage.Server.Test/Video/Sessions/GetStreams/E2ETest.cs new file mode 100644 index 000000000..255a9cb1c --- /dev/null +++ b/Vonage.Server.Test/Video/Sessions/GetStreams/E2ETest.cs @@ -0,0 +1,36 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Sessions.GetStreams; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Sessions.GetStreams +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task GetStreams() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/stream") + .WithHeader("Authorization", "Bearer *") + .UsingGet()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.SessionClient.GetStreamsAsync(GetStreamsRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyStream); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/GetStreams/SerializationTest.cs b/Vonage.Server.Test/Video/Sessions/GetStreams/SerializationTest.cs index 8b4f72bd4..6f8baaa3a 100644 --- a/Vonage.Server.Test/Video/Sessions/GetStreams/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Sessions/GetStreams/SerializationTest.cs @@ -20,15 +20,17 @@ 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("8b732909-0a06-46a2-8ea8-074e64d43422"); - success.Items[0].VideoType.Should().Be("camera"); - success.Items[0].Name.Should().Be("random"); - success.Items[0].LayoutClassList.Length.Should().Be(1); - success.Items[0].LayoutClassList[0].Should().Be("full"); - }); + .BeSuccess(success => { VerifyStream(success); }); + + internal static void VerifyStream(GetStreamsResponse success) + { + success.Count.Should().Be(1); + success.Items.Length.Should().Be(1); + success.Items[0].Id.Should().Be("8b732909-0a06-46a2-8ea8-074e64d43422"); + success.Items[0].VideoType.Should().Be("camera"); + success.Items[0].Name.Should().Be("random"); + success.Items[0].LayoutClassList.Length.Should().Be(1); + success.Items[0].LayoutClassList[0].Should().Be("full"); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sessions/GetStreams/UseCaseTest.cs b/Vonage.Server.Test/Video/Sessions/GetStreams/UseCaseTest.cs deleted file mode 100644 index a4a9c99fa..000000000 --- a/Vonage.Server.Test/Video/Sessions/GetStreams/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.Sessions; -using Vonage.Server.Video.Sessions.GetStreams; -using Xunit; - -namespace Vonage.Server.Test.Video.Sessions.GetStreams -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new SessionClient(configuration).GetStreamsAsync(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 SessionClient(configuration).GetStreamsAsync(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) => - GetStreamsRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .Create(); - } -} \ No newline at end of file From 0294dc5f93d1fc4b0748124da0ab0c9a98d3a222 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 11:40:42 +0200 Subject: [PATCH 08/11] Add E2E for SendSignal --- .../Data/ShouldSerialize-request.json | 4 ++ .../Video/Signaling/SendSignal/E2ETest.cs | 39 +++++++++++ .../Signaling/SendSignal/SerializationTest.cs | 30 +++++++++ .../Video/Signaling/SendSignal/UseCaseTest.cs | 67 ------------------- Vonage.Server.Test/Vonage.Server.Test.csproj | 3 + .../Video/Signaling/SignalContent.cs | 6 +- 6 files changed, 81 insertions(+), 68 deletions(-) create mode 100644 Vonage.Server.Test/Video/Signaling/SendSignal/Data/ShouldSerialize-request.json create mode 100644 Vonage.Server.Test/Video/Signaling/SendSignal/E2ETest.cs create mode 100644 Vonage.Server.Test/Video/Signaling/SendSignal/SerializationTest.cs delete mode 100644 Vonage.Server.Test/Video/Signaling/SendSignal/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Signaling/SendSignal/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Signaling/SendSignal/Data/ShouldSerialize-request.json new file mode 100644 index 000000000..2af11b8e2 --- /dev/null +++ b/Vonage.Server.Test/Video/Signaling/SendSignal/Data/ShouldSerialize-request.json @@ -0,0 +1,4 @@ +{ + "type": "chat", + "data": "Text of the chat message" +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Signaling/SendSignal/E2ETest.cs b/Vonage.Server.Test/Video/Signaling/SendSignal/E2ETest.cs new file mode 100644 index 000000000..3a824872d --- /dev/null +++ b/Vonage.Server.Test/Video/Signaling/SendSignal/E2ETest.cs @@ -0,0 +1,39 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Signaling; +using Vonage.Server.Video.Signaling.SendSignal; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Signaling.SendSignal +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task SendSignal() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/connection/f0f01910-8797-4a22-aeb3-fcd5edb55ebe/signal") + .WithHeader("Authorization", "Bearer *") + .WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerialize))) + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + await this.Helper.VonageClient.SignalingClient.SendSignalAsync(SendSignalRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithConnectionId("f0f01910-8797-4a22-aeb3-fcd5edb55ebe") + .WithContent(new SignalContent("chat", "Text of the chat message")) + .Create()) + .Should() + .BeSuccessAsync(); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Signaling/SendSignal/SerializationTest.cs b/Vonage.Server.Test/Video/Signaling/SendSignal/SerializationTest.cs new file mode 100644 index 000000000..bf78f362e --- /dev/null +++ b/Vonage.Server.Test/Video/Signaling/SendSignal/SerializationTest.cs @@ -0,0 +1,30 @@ +using System; +using Vonage.Common.Test; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Serialization; +using Vonage.Server.Video.Signaling; +using Vonage.Server.Video.Signaling.SendSignal; +using Xunit; + +namespace Vonage.Server.Test.Video.Signaling.SendSignal +{ + public class SerializationTest + { + private readonly SerializationTestHelper helper; + + public SerializationTest() => this.helper = + new SerializationTestHelper(typeof(SerializationTest).Namespace, JsonSerializerBuilder.Build()); + + [Fact] + public void ShouldSerialize() => + SendSignalRequest.Build() + .WithApplicationId(Guid.NewGuid()) + .WithSessionId("Some session Id") + .WithConnectionId("Some connection Id") + .WithContent(new SignalContent("chat", "Text of the chat message")) + .Create() + .GetStringContent() + .Should() + .BeSuccess(this.helper.GetRequestJson()); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Signaling/SendSignal/UseCaseTest.cs b/Vonage.Server.Test/Video/Signaling/SendSignal/UseCaseTest.cs deleted file mode 100644 index d127ea08a..000000000 --- a/Vonage.Server.Test/Video/Signaling/SendSignal/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.Signaling; -using Vonage.Server.Video.Signaling.SendSignal; -using Xunit; - -namespace Vonage.Server.Test.Video.Signaling.SendSignal -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new SignalingClient(configuration).SendSignalAsync(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 SignalingClient(configuration).SendSignalAsync(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.Post, - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - Content = this.request - .Map(value => this.Helper.Serializer.SerializeObject(value.Content)) - .IfFailure(string.Empty), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - SendSignalRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithConnectionId(fixture.Create()) - .WithContent(fixture.Create()) - .Create(); - } -} \ 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 e32813261..711eefe15 100644 --- a/Vonage.Server.Test/Vonage.Server.Test.csproj +++ b/Vonage.Server.Test/Vonage.Server.Test.csproj @@ -154,6 +154,9 @@ PreserveNewest + + PreserveNewest + diff --git a/Vonage.Server/Video/Signaling/SignalContent.cs b/Vonage.Server/Video/Signaling/SignalContent.cs index cfd28bc81..3ca6609f2 100644 --- a/Vonage.Server/Video/Signaling/SignalContent.cs +++ b/Vonage.Server/Video/Signaling/SignalContent.cs @@ -1,4 +1,6 @@ -namespace Vonage.Server.Video.Signaling; +using System.Text.Json.Serialization; + +namespace Vonage.Server.Video.Signaling; /// /// Represents a signal to be sent. @@ -8,11 +10,13 @@ public readonly struct SignalContent /// /// Payload that is being sent to the client. This cannot exceed 8kb. /// + [JsonPropertyOrder(1)] public string Data { get; } /// /// Type of data that is being sent to the client. This cannot exceed 128 bytes. /// + [JsonPropertyOrder(0)] public string Type { get; } /// From f3916777a1dbe2d3a8c40777fdc60e60ea3a9463 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 11:43:56 +0200 Subject: [PATCH 09/11] Add E2E for SendSignals --- .../Data/ShouldSerialize-request.json | 4 ++ .../Video/Signaling/SendSignals/E2ETest.cs | 38 +++++++++++ .../SendSignals/SerializationTest.cs | 29 ++++++++ .../Signaling/SendSignals/UseCaseTest.cs | 67 ------------------- Vonage.Server.Test/Vonage.Server.Test.csproj | 3 + 5 files changed, 74 insertions(+), 67 deletions(-) create mode 100644 Vonage.Server.Test/Video/Signaling/SendSignals/Data/ShouldSerialize-request.json create mode 100644 Vonage.Server.Test/Video/Signaling/SendSignals/E2ETest.cs create mode 100644 Vonage.Server.Test/Video/Signaling/SendSignals/SerializationTest.cs delete mode 100644 Vonage.Server.Test/Video/Signaling/SendSignals/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Signaling/SendSignals/Data/ShouldSerialize-request.json b/Vonage.Server.Test/Video/Signaling/SendSignals/Data/ShouldSerialize-request.json new file mode 100644 index 000000000..2af11b8e2 --- /dev/null +++ b/Vonage.Server.Test/Video/Signaling/SendSignals/Data/ShouldSerialize-request.json @@ -0,0 +1,4 @@ +{ + "type": "chat", + "data": "Text of the chat message" +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Signaling/SendSignals/E2ETest.cs b/Vonage.Server.Test/Video/Signaling/SendSignals/E2ETest.cs new file mode 100644 index 000000000..fab0ec6a7 --- /dev/null +++ b/Vonage.Server.Test/Video/Signaling/SendSignals/E2ETest.cs @@ -0,0 +1,38 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Signaling; +using Vonage.Server.Video.Signaling.SendSignals; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Signaling.SendSignals +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task SendSignals() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/signal") + .WithHeader("Authorization", "Bearer *") + .WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerialize))) + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + await this.Helper.VonageClient.SignalingClient.SendSignalsAsync(SendSignalsRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithContent(new SignalContent("chat", "Text of the chat message")) + .Create()) + .Should() + .BeSuccessAsync(); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Signaling/SendSignals/SerializationTest.cs b/Vonage.Server.Test/Video/Signaling/SendSignals/SerializationTest.cs new file mode 100644 index 000000000..e8d5071f3 --- /dev/null +++ b/Vonage.Server.Test/Video/Signaling/SendSignals/SerializationTest.cs @@ -0,0 +1,29 @@ +using System; +using Vonage.Common.Test; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Serialization; +using Vonage.Server.Video.Signaling; +using Vonage.Server.Video.Signaling.SendSignals; +using Xunit; + +namespace Vonage.Server.Test.Video.Signaling.SendSignals +{ + public class SerializationTest + { + private readonly SerializationTestHelper helper; + + public SerializationTest() => this.helper = + new SerializationTestHelper(typeof(SerializationTest).Namespace, JsonSerializerBuilder.Build()); + + [Fact] + public void ShouldSerialize() => + SendSignalsRequest.Build() + .WithApplicationId(Guid.NewGuid()) + .WithSessionId("Some session Id") + .WithContent(new SignalContent("chat", "Text of the chat message")) + .Create() + .GetStringContent() + .Should() + .BeSuccess(this.helper.GetRequestJson()); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Signaling/SendSignals/UseCaseTest.cs b/Vonage.Server.Test/Video/Signaling/SendSignals/UseCaseTest.cs deleted file mode 100644 index 79c75f2ff..000000000 --- a/Vonage.Server.Test/Video/Signaling/SendSignals/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.Signaling; -using Vonage.Server.Video.Signaling.SendSignals; -using Xunit; - -namespace Vonage.Server.Test.Video.Signaling.SendSignals - -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new SignalingClient(configuration).SendSignalsAsync(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 SignalingClient(configuration).SendSignalsAsync(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.Post, - RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), - Content = this.request - .Map(value => this.Helper.Serializer.SerializeObject(value.Content)) - .IfFailure(string.Empty), - }; - - private static Result BuildRequest(ISpecimenBuilder fixture) => - SendSignalsRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithContent(fixture.Create()) - .Create(); - } -} \ 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 711eefe15..d1589cc02 100644 --- a/Vonage.Server.Test/Vonage.Server.Test.csproj +++ b/Vonage.Server.Test/Vonage.Server.Test.csproj @@ -157,6 +157,9 @@ PreserveNewest + + PreserveNewest + From c153a03521dce85a9d18f4a5c1346605c90dfae2 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 11:51:21 +0200 Subject: [PATCH 10/11] Add E2E for InitiateCall --- .../Video/Sip/InitiateCall/E2ETest.cs | 61 ++++++++++++++++ .../Sip/InitiateCall/SerializationTest.cs | 14 ++-- .../Video/Sip/InitiateCall/UseCaseTest.cs | 72 ------------------- .../Video/Sip/PlayToneIntoCall/UseCaseTest.cs | 66 ----------------- .../Sip/PlayToneIntoConnection/UseCaseTest.cs | 67 ----------------- 5 files changed, 69 insertions(+), 211 deletions(-) create mode 100644 Vonage.Server.Test/Video/Sip/InitiateCall/E2ETest.cs delete mode 100644 Vonage.Server.Test/Video/Sip/InitiateCall/UseCaseTest.cs delete mode 100644 Vonage.Server.Test/Video/Sip/PlayToneIntoCall/UseCaseTest.cs delete mode 100644 Vonage.Server.Test/Video/Sip/PlayToneIntoConnection/UseCaseTest.cs diff --git a/Vonage.Server.Test/Video/Sip/InitiateCall/E2ETest.cs b/Vonage.Server.Test/Video/Sip/InitiateCall/E2ETest.cs new file mode 100644 index 000000000..d1dcc8ec7 --- /dev/null +++ b/Vonage.Server.Test/Video/Sip/InitiateCall/E2ETest.cs @@ -0,0 +1,61 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Sip.InitiateCall; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Sip.InitiateCall +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task InitiateCall() + { + this.SetUpServer(nameof(SerializationTest.ShouldSerialize)); + await this.Helper.VonageClient.SipClient.InitiateCallAsync(InitiateCallRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("b40ef09b-3811-4726-b508-e41a0f96c68f") + .WithToken("78d335fa-323d-0114-9c3d-d6f0d48968cf") + .WithSipUri(new Uri("sip:user@sip.partner.com;transport=tls")) + .EnableVideo() + .EnableForceMute() + .EnableEncryptedMedia() + .WithAuthentication(new SipElement.SipAuthentication("username", "p@ssw0rd")) + .WithFrom("from@example.com") + .WithHeader("headerKey", "some-value") + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyCall); + } + + [Fact] + public async Task InitiateDefaultCall() + { + this.SetUpServer(nameof(SerializationTest.ShouldSerializeWithDefaultValues)); + await this.Helper.VonageClient.SipClient.InitiateCallAsync(InitiateCallRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("b40ef09b-3811-4726-b508-e41a0f96c68f") + .WithToken("78d335fa-323d-0114-9c3d-d6f0d48968cf") + .WithSipUri(new Uri("sip:user@sip.partner.com;transport=tls")) + .Create()) + .Should() + .BeSuccessAsync(SerializationTest.VerifyCall); + } + + private void SetUpServer(string requestNamespace) => + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath("/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/dial") + .WithHeader("Authorization", "Bearer *") + .WithBody(this.Serialization.GetRequestJson(requestNamespace)) + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sip/InitiateCall/SerializationTest.cs b/Vonage.Server.Test/Video/Sip/InitiateCall/SerializationTest.cs index 05fb3b3b8..007bd62e8 100644 --- a/Vonage.Server.Test/Video/Sip/InitiateCall/SerializationTest.cs +++ b/Vonage.Server.Test/Video/Sip/InitiateCall/SerializationTest.cs @@ -21,12 +21,7 @@ public void ShouldDeserialize200() => this.helper.Serializer .DeserializeObject(this.helper.GetResponseJson()) .Should() - .BeSuccess(success => - { - success.Id.Should().Be("8d78f9ca-c336-497e-9264-05aa2a442dcc"); - success.ConnectionId.Should().Be(new Guid("5fb383d1-a70f-4153-b009-2ef0429bf08f")); - success.StreamId.Should().Be("1b934954-f1b4-406a-8bb8-7cde7a8be2a3"); - }); + .BeSuccess(VerifyCall); [Fact] public void ShouldSerialize() => @@ -57,5 +52,12 @@ public void ShouldSerializeWithDefaultValues() => .GetStringContent() .Should() .BeSuccess(this.helper.GetRequestJson()); + + internal static void VerifyCall(InitiateCallResponse success) + { + success.Id.Should().Be("8d78f9ca-c336-497e-9264-05aa2a442dcc"); + success.ConnectionId.Should().Be(new Guid("5fb383d1-a70f-4153-b009-2ef0429bf08f")); + success.StreamId.Should().Be("1b934954-f1b4-406a-8bb8-7cde7a8be2a3"); + } } } \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sip/InitiateCall/UseCaseTest.cs b/Vonage.Server.Test/Video/Sip/InitiateCall/UseCaseTest.cs deleted file mode 100644 index b2e6f88eb..000000000 --- a/Vonage.Server.Test/Video/Sip/InitiateCall/UseCaseTest.cs +++ /dev/null @@ -1,72 +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.Sip; -using Vonage.Server.Video.Sip.InitiateCall; -using Xunit; - -namespace Vonage.Server.Test.Video.Sip.InitiateCall -{ - public class UseCaseTest : BaseUseCase, IUseCaseWithResponse - { - private Func>> Operation => - configuration => new SipClient(configuration).InitiateCallAsync(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 SipClient(configuration).InitiateCallAsync(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) => - InitiateCallRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithToken(fixture.Create()) - .WithSipUri(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sip/PlayToneIntoCall/UseCaseTest.cs b/Vonage.Server.Test/Video/Sip/PlayToneIntoCall/UseCaseTest.cs deleted file mode 100644 index 9b971d4e7..000000000 --- a/Vonage.Server.Test/Video/Sip/PlayToneIntoCall/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.Sip; -using Vonage.Server.Video.Sip.PlayToneIntoCall; -using Xunit; - -namespace Vonage.Server.Test.Video.Sip.PlayToneIntoCall -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new SipClient(configuration).PlayToneIntoCallAsync(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 SipClient(configuration).PlayToneIntoCallAsync(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.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) => - PlayToneIntoCallRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithDigits(fixture.Create()) - .Create(); - } -} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sip/PlayToneIntoConnection/UseCaseTest.cs b/Vonage.Server.Test/Video/Sip/PlayToneIntoConnection/UseCaseTest.cs deleted file mode 100644 index 0b520005e..000000000 --- a/Vonage.Server.Test/Video/Sip/PlayToneIntoConnection/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.Sip; -using Vonage.Server.Video.Sip.PlayToneIntoConnection; -using Xunit; - -namespace Vonage.Server.Test.Video.Sip.PlayToneIntoConnection -{ - public class UseCaseTest : BaseUseCase, IUseCase - { - private Func>> Operation => - configuration => new SipClient(configuration).PlayToneIntoConnectionAsync(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 SipClient(configuration).PlayToneIntoConnectionAsync(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.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) => - PlayToneIntoConnectionRequest.Build() - .WithApplicationId(fixture.Create()) - .WithSessionId(fixture.Create()) - .WithConnectionId(fixture.Create()) - .WithDigits(fixture.Create()) - .Create(); - } -} \ No newline at end of file From 27c836869c346746e0de1e9ab2499c8c2cf03a4d Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 2 Aug 2023 12:18:14 +0200 Subject: [PATCH 11/11] Add E2E for PLayTone --- .../Video/Sip/PlayToneIntoCall/E2ETest.cs | 37 ++++++++++++++++++ .../Sip/PlayToneIntoConnection/E2ETest.cs | 38 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 Vonage.Server.Test/Video/Sip/PlayToneIntoCall/E2ETest.cs create mode 100644 Vonage.Server.Test/Video/Sip/PlayToneIntoConnection/E2ETest.cs diff --git a/Vonage.Server.Test/Video/Sip/PlayToneIntoCall/E2ETest.cs b/Vonage.Server.Test/Video/Sip/PlayToneIntoCall/E2ETest.cs new file mode 100644 index 000000000..6cdc40977 --- /dev/null +++ b/Vonage.Server.Test/Video/Sip/PlayToneIntoCall/E2ETest.cs @@ -0,0 +1,37 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Sip.PlayToneIntoCall; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Sip.PlayToneIntoCall +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task PLayToneIntoCall() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/play-dtmf") + .WithHeader("Authorization", "Bearer *") + .WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerialize))) + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + await this.Helper.VonageClient.SipClient.PlayToneIntoCallAsync(PlayToneIntoCallRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithDigits("1713") + .Create()) + .Should() + .BeSuccessAsync(); + } + } +} \ No newline at end of file diff --git a/Vonage.Server.Test/Video/Sip/PlayToneIntoConnection/E2ETest.cs b/Vonage.Server.Test/Video/Sip/PlayToneIntoConnection/E2ETest.cs new file mode 100644 index 000000000..c755a32e3 --- /dev/null +++ b/Vonage.Server.Test/Video/Sip/PlayToneIntoConnection/E2ETest.cs @@ -0,0 +1,38 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Test.Extensions; +using Vonage.Server.Video.Sip.PlayToneIntoConnection; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Server.Test.Video.Sip.PlayToneIntoConnection +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task PLayToneIntoConnection() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath( + "/v2/project/5e782e3b-9f63-426f-bd2e-b7d618d546cd/session/flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN/connection/414ac9c2-9a6f-4f4b-aad4-202dbe7b1d8d/play-dtmf") + .WithHeader("Authorization", "Bearer *") + .WithBody(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerialize))) + .UsingPost()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); + await this.Helper.VonageClient.SipClient.PlayToneIntoConnectionAsync(PlayToneIntoConnectionRequest.Build() + .WithApplicationId(Guid.Parse("5e782e3b-9f63-426f-bd2e-b7d618d546cd")) + .WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN") + .WithConnectionId("414ac9c2-9a6f-4f4b-aad4-202dbe7b1d8d") + .WithDigits("1713") + .Create()) + .Should() + .BeSuccessAsync(); + } + } +} \ No newline at end of file