-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement GetSessions on ExperienceComposer
- Loading branch information
Showing
10 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Vonage.Test/Video/ExperienceComposer/GetSessions/Data/ShouldDeserialize200-response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"count": 1, | ||
"items": [ | ||
{ | ||
"id": "1248e7070b81464c9789f46ad10e7764", | ||
"sessionId": "flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN", | ||
"applicationId": "93e36bb9-b72c-45b6-a9ea-5c37dbc49906", | ||
"createdAt": 1437676551000, | ||
"callbackUrl": "https://example.com/video/events", | ||
"updatedAt": 1437676551000, | ||
"name": "Composed stream for Live event #1", | ||
"url": "https://example.com/", | ||
"resolution": "720x1280", | ||
"status": "failed", | ||
"streamId": "e32445b743678c98230f238", | ||
"reason": "Could not load URL" | ||
} | ||
] | ||
} |
59 changes: 59 additions & 0 deletions
59
Vonage.Test/Video/ExperienceComposer/GetSessions/E2ETest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.Video.ExperienceComposer.GetSessions; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Video.ExperienceComposer.GetSessions; | ||
|
||
[Trait("Category", "E2E")] | ||
public class E2ETest : E2EBase | ||
{ | ||
public E2ETest() : base(typeof(E2ETest).Namespace) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task GetSessions() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render") | ||
.WithParam("offset", "150") | ||
.WithParam("count", "150") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingGet()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); | ||
await this.Helper.VonageClient.VideoClient.ExperienceComposerClient | ||
.GetSessionsAsync(GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(new Guid("e3e78a75-221d-41ec-8846-25ae3db1943a")) | ||
.WithCount(150) | ||
.WithOffset(150) | ||
.Create()) | ||
.Should() | ||
.BeSuccessAsync(SerializationTest.BuildExpectedResponse()); | ||
} | ||
|
||
[Fact] | ||
public async Task GetSessionsWithDefaultParameters() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render") | ||
.WithParam("offset", "0") | ||
.WithParam("count", "50") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingGet()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); | ||
await this.Helper.VonageClient.VideoClient.ExperienceComposerClient | ||
.GetSessionsAsync(GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(new Guid("e3e78a75-221d-41ec-8846-25ae3db1943a")) | ||
.Create()) | ||
.Should() | ||
.BeSuccessAsync(SerializationTest.BuildExpectedResponse()); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
Vonage.Test/Video/ExperienceComposer/GetSessions/RequestBuilderTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.Video.ExperienceComposer.GetSessions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Video.ExperienceComposer.GetSessions; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestBuilderTest | ||
{ | ||
private const int ValidOffset = 100; | ||
private const int ValidCount = 100; | ||
private readonly Guid validApplicationId = Guid.NewGuid(); | ||
|
||
[Fact] | ||
public void Build_ShouldHaveDefaultOffset() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(this.validApplicationId) | ||
.Create() | ||
.Map(request => request.Offset) | ||
.Should() | ||
.BeSuccess(0); | ||
|
||
[Fact] | ||
public void Build_ShouldHaveDefaultCount() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(this.validApplicationId) | ||
.Create() | ||
.Map(request => request.Count) | ||
.Should() | ||
.BeSuccess(50); | ||
|
||
[Fact] | ||
public void Build_ShouldReturnFailure_GivenCountIsHigherThanOneThousand() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(this.validApplicationId) | ||
.WithCount(1001) | ||
.Create() | ||
.Should() | ||
.BeParsingFailure("Count cannot be higher than 1000."); | ||
|
||
[Fact] | ||
public void Build_ShouldReturnFailure_GivenCountIsLowerThanFifty() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(this.validApplicationId) | ||
.WithCount(49) | ||
.Create() | ||
.Should() | ||
.BeParsingFailure("Count cannot be lower than 50."); | ||
|
||
[Fact] | ||
public void Build_ShouldReturnFailure_GivenApplicationIdIsEmpty() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(Guid.Empty) | ||
.Create() | ||
.Should() | ||
.BeParsingFailure("ApplicationId cannot be empty."); | ||
|
||
[Fact] | ||
public void Build_ShouldReturnFailure_GivenOffsetIsLowerThanZero() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(this.validApplicationId) | ||
.WithOffset(-1) | ||
.Create() | ||
.Should() | ||
.BeParsingFailure("Offset cannot be lower than 0."); | ||
|
||
[Fact] | ||
public void Build_ShouldSetApplicationId() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(this.validApplicationId) | ||
.Create() | ||
.Map(request => request.ApplicationId) | ||
.Should() | ||
.BeSuccess(this.validApplicationId); | ||
|
||
[Fact] | ||
public void Build_ShouldSetCount() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(this.validApplicationId) | ||
.WithCount(ValidCount) | ||
.Create() | ||
.Map(request => request.Count) | ||
.Should() | ||
.BeSuccess(ValidCount); | ||
|
||
[Fact] | ||
public void Build_ShouldSetOffset() => | ||
GetSessionsRequest | ||
.Build() | ||
.WithApplicationId(this.validApplicationId) | ||
.WithOffset(ValidOffset) | ||
.Create() | ||
.Map(request => request.Offset) | ||
.Should() | ||
.BeSuccess(ValidOffset); | ||
} |
31 changes: 31 additions & 0 deletions
31
Vonage.Test/Video/ExperienceComposer/GetSessions/RequestTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.Video.ExperienceComposer.GetSessions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Video.ExperienceComposer.GetSessions; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestTest | ||
{ | ||
[Theory] | ||
[InlineData(null, null, "/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render?offset=0&count=50")] | ||
[InlineData(100, null, "/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render?offset=0&count=100")] | ||
[InlineData(null, 100, "/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render?offset=100&count=50")] | ||
[InlineData(100, 100, "/v2/project/e3e78a75-221d-41ec-8846-25ae3db1943a/render?offset=100&count=100")] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint(int? count, int? offset, string expectedEndpoint) | ||
{ | ||
var builder = GetSessionsRequest.Build().WithApplicationId(new Guid("e3e78a75-221d-41ec-8846-25ae3db1943a")); | ||
if (count.HasValue) | ||
{ | ||
builder = builder.WithCount(count.Value); | ||
} | ||
|
||
if (offset.HasValue) | ||
{ | ||
builder = builder.WithOffset(offset.Value); | ||
} | ||
|
||
builder.Create().Map(request => request.GetEndpointPath()).Should().BeSuccess(expectedEndpoint); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
Vonage.Test/Video/ExperienceComposer/GetSessions/SerializationTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using Vonage.Serialization; | ||
using Vonage.Server; | ||
using Vonage.Test.Common; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.Video.ExperienceComposer; | ||
using Vonage.Video.ExperienceComposer.GetSessions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Video.ExperienceComposer.GetSessions; | ||
|
||
[Trait("Category", "Serialization")] | ||
public class SerializationTest | ||
{ | ||
private readonly SerializationTestHelper helper = new SerializationTestHelper( | ||
typeof(SerializationTest).Namespace, | ||
JsonSerializerBuilder.BuildWithCamelCase()); | ||
|
||
[Fact] | ||
public void ShouldDeserialize200() => this.helper.Serializer | ||
.DeserializeObject<GetSessionsResponse>(this.helper.GetResponseJson()) | ||
.Should() | ||
.BeSuccess(BuildExpectedResponse()); | ||
|
||
internal static GetSessionsResponse BuildExpectedResponse() => new GetSessionsResponse(1, new[] | ||
{ | ||
new Session("1248e7070b81464c9789f46ad10e7764", | ||
"flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN", | ||
new Guid("93e36bb9-b72c-45b6-a9ea-5c37dbc49906"), | ||
1437676551000, | ||
new Uri("https://example.com/video/events"), | ||
1437676551000, | ||
"Composed stream for Live event #1", | ||
new Uri("https://example.com/"), | ||
RenderResolution.HighDefinitionPortrait, | ||
SessionStatus.Failed, | ||
"e32445b743678c98230f238", | ||
"Could not load URL"), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Vonage/Video/ExperienceComposer/GetSessions/GetSessionsRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Net.Http; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Client.Builders; | ||
|
||
namespace Vonage.Video.ExperienceComposer.GetSessions; | ||
|
||
/// <summary> | ||
/// Represents a request to retrieve sessions. | ||
/// </summary> | ||
public readonly struct GetSessionsRequest : IVonageRequest, IHasApplicationId | ||
{ | ||
/// <inheritdoc /> | ||
public Guid ApplicationId { get; internal init; } | ||
|
||
/// <summary> | ||
/// Set a count query parameter to limit the number of experience composers to be returned. The default number of | ||
/// archives returned is 50 (or fewer, if there are fewer than 50 archives). The default is 50 and the maximum is 1000 | ||
/// </summary> | ||
public int Count { get; internal init; } | ||
|
||
/// <summary> | ||
/// Set an offset query parameters to specify the index offset of the first experience composer. 0 is offset of the | ||
/// most recently started archive (excluding deleted archive). 1 is the offset of the experience composer that started | ||
/// prior to the most recent composer. The default value is 0. | ||
/// </summary> | ||
public int Offset { get; internal init; } | ||
|
||
/// <inheritdoc /> | ||
public HttpRequestMessage BuildRequestMessage() => | ||
VonageRequestBuilder | ||
.Initialize(HttpMethod.Get, this.GetEndpointPath()) | ||
.Build(); | ||
|
||
/// <summary> | ||
/// Initializes a builder. | ||
/// </summary> | ||
/// <returns>The builder.</returns> | ||
public static IBuilderForApplicationId Build() => new GetSessionsRequestBuilder(); | ||
|
||
/// <inheritdoc /> | ||
public string GetEndpointPath() => | ||
$"/v2/project/{this.ApplicationId}/render?offset={this.Offset}&count={this.Count}"; | ||
} |
Oops, something went wrong.