Skip to content

Commit

Permalink
feat: implement serialization for Start on ExperienceComposer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 25, 2024
1 parent ab9490e commit 5b91318
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"sessionId": "flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN",
"token": "830c9c9d-d09e-4513-9cc8-29c90a760248",
"url": "https://example.com/",
"maxDuration": 1800,
"resolution": "640x480",
"properties": {
"name": "Composed stream for Live event #1"
}
}
53 changes: 53 additions & 0 deletions Vonage.Test/Video/ExperienceComposer/Start/SerializationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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.Start;
using Xunit;

namespace Vonage.Test.Video.ExperienceComposer.Start;

[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<Session>(this.helper.GetResponseJson())
.Should()
.BeSuccess(BuildExpectedSession());

[Fact]
public void ShouldSerialize() => StartRequest
.Build()
.WithApplicationId(Guid.NewGuid())
.WithSessionId("flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN")
.WithToken("830c9c9d-d09e-4513-9cc8-29c90a760248")
.WithUrl(new Uri("https://example.com/"))
.WithResolution(RenderResolution.StandardDefinitionLandscape)
.WithName("Composed stream for Live event #1")
.WithMaxDuration(1800)
.Create()
.GetStringContent()
.Should()
.BeSuccess(this.helper.GetRequestJson());

internal static Session BuildExpectedSession() =>
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");
}
7 changes: 6 additions & 1 deletion Vonage.Test/Vonage.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Video\ExperienceComposer\Start\Data\"/>
<None Update="Data\NccoTests\TestRecord-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -1240,6 +1239,12 @@
<None Update="Video\ExperienceComposer\GetSessions\Data\ShouldDeserialize200-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Video\ExperienceComposer\Start\Data\ShouldDeserialize200-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Video\ExperienceComposer\Start\Data\ShouldSerialize-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
Expand Down
23 changes: 20 additions & 3 deletions Vonage/Video/ExperienceComposer/Start/StartRequest.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json.Serialization;
using Vonage.Common.Client;
using Vonage.Serialization;
using Vonage.Server;

namespace Vonage.Video.ExperienceComposer.Start;

/// <inheritdoc />
public struct StartRequest : IVonageRequest
public readonly struct StartRequest : IVonageRequest
{
/// <summary>
/// </summary>
[JsonIgnore]
public Guid ApplicationId { get; internal init; }

/// <summary>
/// </summary>
///
[JsonPropertyOrder(0)]
public string SessionId { get; internal init; }

/// <summary>
/// </summary>
[JsonPropertyOrder(1)]
public string Token { get; internal init; }

/// <summary>
/// </summary>
[JsonPropertyOrder(2)]
public Uri Url { get; internal init; }

/// <summary>
/// </summary>
[JsonPropertyOrder(3)]
public int MaxDuration { get; internal init; }

/// <summary>
/// </summary>
[JsonPropertyOrder(4)]
public RenderResolution Resolution { get; internal init; }

/// <summary>
/// </summary>
[JsonPropertyOrder(5)]
public StartProperties Properties { get; internal init; }

/// <inheritdoc />
public HttpRequestMessage BuildRequestMessage() => throw new NotImplementedException();
public HttpRequestMessage BuildRequestMessage() => VonageRequestBuilder
.Initialize(HttpMethod.Post, this.GetEndpointPath())
.WithContent(this.GetRequestContent())
.Build();

private StringContent GetRequestContent() =>
new StringContent(JsonSerializerBuilder.BuildWithCamelCase().SerializeObject(this), Encoding.UTF8,
"application/json");

/// <inheritdoc />
public string GetEndpointPath() => $"/v2/project/{this.ApplicationId}/render";
Expand Down

0 comments on commit 5b91318

Please sign in to comment.