Skip to content

Commit

Permalink
[Video] DEVX-6861 Broadcasts (#356)
Browse files Browse the repository at this point in the history
* Implement GetBroadcasts

* Fix merge conflicts

* Fix merge conflicts

* Fill Xml Documentation on Broadcast

* Implement StartBroadcastRequest

* Implement StartBroadcast

* Implement GetBroadcast

* Implement StopBroadcast

* Implement AddStreamToBroadcast

* Implement AddStreamToBroadcast http content and serialization

* Implement RemoveStreamFromBroadcast

* Implement ChangeBroadcastLayout

* Use enums for BroadcastStatus and RtmpStatus

* Use Guids on most identifiers

* Remove unnecessary using

* Add missing XmlDocumentation

* Rename ArchiveLayout to Layout, given it's not specific to Archive anymore

* Convert Layout to a record

* Replace structs by records

* Apply PR suggestions

* Fix broadcast layout creation
  • Loading branch information
Tr00d authored Feb 24, 2023
1 parent 6e5506e commit e203bfc
Show file tree
Hide file tree
Showing 82 changed files with 3,712 additions and 132 deletions.
8 changes: 7 additions & 1 deletion Vonage.Common.Test/Failures/ResultFailureTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using FluentAssertions;
using Vonage.Common.Failures;
using Vonage.Common.Test.Extensions;

namespace Vonage.Common.Test.Failures
{
public class ResultFailureTest
{
[Fact]
public void FromError_ShouldReturnFailure() =>
public void FromErrorMessage_ShouldReturnFailure() =>
ResultFailure.FromErrorMessage("Some error.").GetFailureMessage().Should().Be("Some error.");

[Fact]
public void ToResult_ShouldReturnFailure() =>
ResultFailure.ToResult<int>("Some error.").Should()
.BeFailure(failure => failure.GetFailureMessage().Should().Be("Some error."));
}
}
16 changes: 13 additions & 3 deletions Vonage.Common/Failures/ResultFailure.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
namespace Vonage.Common.Failures;
using Vonage.Common.Monads;

namespace Vonage.Common.Failures;

/// <inheritdoc />
public readonly struct ResultFailure : IResultFailure
{
private ResultFailure(string error) => this.error = error;
private readonly string error;
private ResultFailure(string error) => this.error = error;

/// <summary>
/// Create a failure from an error message.
/// Creates a failure from an error message.
/// </summary>
/// <param name="error">The error message.</param>
/// <returns>The failure.</returns>
public static ResultFailure FromErrorMessage(string error) => new(error);

/// <inheritdoc />
public string GetFailureMessage() => this.error;

/// <summary>
/// Creates a result failure from an error message.
/// </summary>
/// <param name="error">The error message.</param>
/// <typeparam name="T">Type of the result.</typeparam>
/// <returns>The result.</returns>
public static Result<T> ToResult<T>(string error) => Result<T>.FromFailure(FromErrorMessage(error));
}
17 changes: 17 additions & 0 deletions Vonage.Common/Validation/InputValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,26 @@ public static class InputValidation
private const string CollectionCannotBeNull = "cannot be null.";
private const string GuidCannotBeNullOrWhitespace = "cannot be empty.";
private const string IntCannotBeHigherThan = "cannot be higher than {value}.";
private const string IntCannotBeLowerThan = "cannot be lower than {value}.";
private const string IntCannotBeNegative = "cannot be negative.";
private const string StringCannotBeNullOrWhitespace = "cannot be null or whitespace.";

/// <summary>
/// Verifies if higher or equal than specified threshold.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="value">The value.</param>
/// <param name="minValue">The threshold.</param>
/// <param name="name">The display name.</param>
/// <typeparam name="T">The request type.</typeparam>
/// <returns>Success or Failure.</returns>
public static Result<T> VerifyHigherOrEqualThan<T>(T request, int value, int minValue, string name) =>
value < minValue
? Result<T>.FromFailure(
ResultFailure.FromErrorMessage(
$"{name} {IntCannotBeLowerThan.Replace("{value}", minValue.ToString())}"))
: request;

/// <summary>
/// Verifies if lower or equal than specified threshold.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Vonage.Integration.Test/BaseIntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Security.Authentication;
using AutoFixture;
using Vonage.Applications;
using Vonage.Applications.Capabilities;
using Vonage.Request;
using Vonage.Server.Video;

Expand Down Expand Up @@ -32,7 +33,7 @@ private static CreateApplicationRequest BuildRequest() =>
Capabilities = new ApplicationCapabilities
{
Meetings = new Applications.Capabilities.Meetings(),
Video = new Applications.Capabilities.Video(),
Video = new Video(),
},
};

Expand Down
2 changes: 1 addition & 1 deletion Vonage.Server.Test/Serialization/JsonSerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using FluentAssertions;
using Vonage.Common;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Serialization;
using Vonage.Server.Video.Archives.Common;
using Xunit;

namespace Vonage.Server.Test.Serialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
using FluentAssertions;
using Vonage.Common.Failures;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Video.Archives.ChangeLayout;
using Vonage.Server.Video.Archives.Common;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.ChangeLayout
{
public class ChangeLayoutRequestTest
{
private readonly ArchiveLayout layout;
private readonly Fixture fixture;
private readonly Guid applicationId;
private readonly Guid archiveId;
private readonly Layout layout;

public ChangeLayoutRequestTest()
{
this.fixture = new Fixture();
this.fixture.Customize(new SupportMutableValueTypesCustomization());
this.applicationId = this.fixture.Create<Guid>();
this.archiveId = this.fixture.Create<Guid>();
this.layout = this.fixture.Create<ArchiveLayout>();
this.layout = this.fixture.Create<Layout>();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Serialization;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.ChangeLayout;
using Vonage.Server.Video.Archives.Common;
using WireMock.RequestBuilders;
using Xunit;

Expand Down Expand Up @@ -51,7 +51,7 @@ public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() =>

private static Result<ChangeLayoutRequest> BuildRequest(ISpecimenBuilder fixture) =>
ChangeLayoutRequest.Parse(fixture.Create<Guid>(), fixture.Create<Guid>(),
fixture.Create<ArchiveLayout>());
fixture.Create<Layout>());

private IRequestBuilder CreateRequest() =>
WireMockExtensions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FluentAssertions;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Serialization;
using Vonage.Server.Video.Archives.Common;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
using FluentAssertions;
using Vonage.Common.Failures;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Video.Archives.Common;
using Vonage.Server.Common;
using Vonage.Server.Video.Archives.CreateArchive;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.CreateArchive
{
public class CreateArchiveRequestBuilderTest
{
private readonly ArchiveLayout layout;
private readonly Guid applicationId;
private readonly Layout layout;
private readonly OutputMode outputMode;
private readonly RenderResolution resolution;
private readonly StreamMode streamMode;
Expand All @@ -22,13 +22,14 @@ public class CreateArchiveRequestBuilderTest
public CreateArchiveRequestBuilderTest()
{
var fixture = new Fixture();
fixture.Customize(new SupportMutableValueTypesCustomization());
this.applicationId = fixture.Create<Guid>();
this.sessionId = fixture.Create<string>();
this.name = fixture.Create<string>();
this.streamMode = fixture.Create<StreamMode>();
this.resolution = fixture.Create<RenderResolution>();
this.outputMode = fixture.Create<OutputMode>();
this.layout = fixture.Create<ArchiveLayout>();
this.layout = fixture.Create<Layout>();
}

[Fact]
Expand Down Expand Up @@ -86,7 +87,7 @@ public void Build_ShouldReturnSuccess_WithDefaultValues() =>
request.OutputMode.Should().Be(OutputMode.Composed);
request.Resolution.Should().Be(RenderResolution.StandardDefinitionLandscape);
request.StreamMode.Should().Be(StreamMode.Auto);
request.Layout.Should().Be(default(ArchiveLayout));
request.Layout.Should().Be(default(Layout));
});

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FluentAssertions;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Serialization;
using Vonage.Server.Video.Archives.Common;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using FluentAssertions;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Serialization;
using Vonage.Server.Video.Archives.Common;
using Vonage.Server.Video.Archives.GetArchives;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FluentAssertions;
using Vonage.Common.Test;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Serialization;
using Vonage.Server.Video.Archives.Common;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using AutoFixture;
using FluentAssertions;
using Vonage.Common.Failures;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Video.Broadcast.AddStreamToBroadcast;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.AddStreamToBroadcast
{
public class AddStreamToBroadcastRequestBuilderTest
{
private readonly Guid applicationId;
private readonly Guid streamId;
private readonly Guid broadcastId;

public AddStreamToBroadcastRequestBuilderTest()
{
var fixture = new Fixture();
this.applicationId = fixture.Create<Guid>();
this.broadcastId = fixture.Create<Guid>();
this.streamId = fixture.Create<Guid>();
}

[Fact]
public void Build_ShouldDisableAudio_GivenWithDisabledAudioIsUsed() =>
AddStreamToBroadcastRequestBuilder.Build()
.WithApplicationId(this.applicationId)
.WithBroadcastId(this.broadcastId)
.WithStreamId(this.streamId)
.WithDisabledAudio()
.Create()
.Map(request => request.HasAudio)
.Should()
.BeSuccess(false);

[Fact]
public void Build_ShouldDisableVideo_GivenWithDisabledVideoIsUsed() =>
AddStreamToBroadcastRequestBuilder.Build()
.WithApplicationId(this.applicationId)
.WithBroadcastId(this.broadcastId)
.WithStreamId(this.streamId)
.WithDisabledVideo()
.Create()
.Map(request => request.HasVideo)
.Should()
.BeSuccess(false);

[Fact]
public void Build_ShouldReturnFailure_GivenApplicationIdIsEmpty() =>
AddStreamToBroadcastRequestBuilder.Build()
.WithApplicationId(Guid.Empty)
.WithBroadcastId(this.broadcastId)
.WithStreamId(this.streamId)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("ApplicationId cannot be empty."));

[Fact]
public void Build_ShouldReturnFailure_GivenBroadcastIdIsEmpty() =>
AddStreamToBroadcastRequestBuilder.Build()
.WithApplicationId(this.applicationId)
.WithBroadcastId(Guid.Empty)
.WithStreamId(this.streamId)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("BroadcastId cannot be empty."));

[Fact]
public void Build_ShouldReturnFailure_GivenStreamIdIsEmpty() =>
AddStreamToBroadcastRequestBuilder.Build()
.WithApplicationId(this.applicationId)
.WithBroadcastId(this.broadcastId)
.WithStreamId(Guid.Empty)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("StreamId cannot be empty."));

[Fact]
public void Build_ShouldReturnSuccess_WithMandatoryValues() =>
AddStreamToBroadcastRequestBuilder.Build()
.WithApplicationId(this.applicationId)
.WithBroadcastId(this.broadcastId)
.WithStreamId(this.streamId)
.Create()
.Should()
.BeSuccess(success =>
{
success.ApplicationId.Should().Be(this.applicationId);
success.BroadcastId.Should().Be(this.broadcastId);
success.StreamId.Should().Be(this.streamId);
success.HasAudio.Should().BeTrue();
success.HasVideo.Should().BeTrue();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using AutoFixture;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Video.Broadcast.AddStreamToBroadcast;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.AddStreamToBroadcast
{
public class AddStreamToBroadcastRequestTest
{
private readonly Guid applicationId;
private readonly Guid streamId;
private readonly Guid broadcastId;

public AddStreamToBroadcastRequestTest()
{
var fixture = new Fixture();
this.applicationId = fixture.Create<Guid>();
this.broadcastId = fixture.Create<Guid>();
this.streamId = fixture.Create<Guid>();
}

[Fact]
public void GetEndpointPath_ShouldReturnApiEndpoint_WithDefaultOffsetAndCount() =>
AddStreamToBroadcastRequestBuilder.Build()
.WithApplicationId(this.applicationId)
.WithBroadcastId(this.broadcastId)
.WithStreamId(this.streamId)
.Create()
.Map(request => request.GetEndpointPath())
.Should()
.BeSuccess($"/v2/project/{this.applicationId}/broadcast/{this.broadcastId}/streams");
}
}
Loading

0 comments on commit e203bfc

Please sign in to comment.