Skip to content

Commit

Permalink
refactor: make builders internal (#388)
Browse files Browse the repository at this point in the history
* Make request builders internal

* Make builder for DeleteThemeRequest

* Make GetRoomsByThemeRequestBuilder internal

* Make UpdateRoomRequestBuilder internal

* Make UpdateThemeRequestBuilder internal

* Extract parameter from Build for UpdateThemeRequest

* Remove Common folders

* Remove Common folders

* Make AddStreamRequestBuilder internal

* Add internal ChangeLayoutRequestBuilder

* Make CreateArchiveRequestBuilder internal

* Make builder available from Request
  • Loading branch information
Tr00d authored Apr 17, 2023
1 parent 0d6e98a commit a3784a8
Show file tree
Hide file tree
Showing 97 changed files with 1,064 additions and 517 deletions.
1 change: 0 additions & 1 deletion Vonage.Server.Test/Serialization/JsonSerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using FluentAssertions;
using Vonage.Common;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Serialization;
using Xunit;

Expand Down
30 changes: 24 additions & 6 deletions Vonage.Server.Test/Video/Archives/AddStream/RequestBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,40 @@ public RequestBuilderTest()

[Fact]
public void Build_ShouldReturnFailure_GivenApplicationIdIsEmpty() =>
AddStreamRequestBuilder.Build(Guid.Empty, this.archiveId, this.streamId)
AddStreamRequest.Build()
.WithApplicationId(Guid.Empty)
.WithArchiveId(this.archiveId)
.WithStreamId(this.streamId)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("ApplicationId cannot be empty."));

[Fact]
public void Build_ShouldReturnFailure_GivenArchiveIdIsEmpty() =>
AddStreamRequestBuilder.Build(this.applicationId, Guid.Empty, this.streamId)
AddStreamRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(Guid.Empty)
.WithStreamId(this.streamId)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("ArchiveId cannot be empty."));

[Fact]
public void Build_ShouldReturnFailure_GivenStreamIdIsEmpty() =>
AddStreamRequestBuilder.Build(this.applicationId, this.archiveId, Guid.Empty)
AddStreamRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(this.archiveId)
.WithStreamId(Guid.Empty)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("StreamId cannot be empty."));

[Fact]
public void Build_ShouldReturnSuccess_WithDefaultValues() =>
AddStreamRequestBuilder.Build(this.applicationId, this.archiveId, this.streamId)
AddStreamRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(this.archiveId)
.WithStreamId(this.streamId)
.Create()
.Should()
.BeSuccess(request =>
Expand All @@ -59,15 +71,21 @@ public void Build_ShouldReturnSuccess_WithDefaultValues() =>

[Fact]
public void Parse_ShouldReturnDisabledAudio_WhenUsingDisableAudio() =>
AddStreamRequestBuilder.Build(this.applicationId, this.archiveId, this.streamId)
AddStreamRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(this.archiveId)
.WithStreamId(this.streamId)
.DisableAudio()
.Create()
.Should()
.BeSuccess(request => request.HasAudio.Should().Be(false));

[Fact]
public void Parse_ShouldReturnDisabledVideo_WhenUsingDisableVideo() =>
AddStreamRequestBuilder.Build(this.applicationId, this.archiveId, this.streamId)
AddStreamRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(this.archiveId)
.WithStreamId(this.streamId)
.DisableVideo()
.Create()
.Should()
Expand Down
5 changes: 4 additions & 1 deletion Vonage.Server.Test/Video/Archives/AddStream/RequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public RequestTest()

[Fact]
public void GetEndpointPath_ShouldReturnApiEndpoint() =>
AddStreamRequestBuilder.Build(this.applicationId, this.archiveId, this.streamId)
AddStreamRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(this.archiveId)
.WithStreamId(this.streamId)
.Create()
.Map(request => request.GetEndpointPath())
.Should()
Expand Down
8 changes: 4 additions & 4 deletions Vonage.Server.Test/Video/Archives/AddStream/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ private ExpectedRequest BuildExpectedRequest() =>
};

private static Result<AddStreamRequest> BuildRequest(ISpecimenBuilder fixture) =>
AddStreamRequestBuilder.Build(
fixture.Create<Guid>(),
fixture.Create<Guid>(),
fixture.Create<Guid>())
AddStreamRequest.Build()
.WithApplicationId(fixture.Create<Guid>())
.WithArchiveId(fixture.Create<Guid>())
.WithStreamId(fixture.Create<Guid>())
.Create();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using AutoFixture;
using FluentAssertions;
using Vonage.Common.Failures;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Video.Archives.ChangeLayout;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.ChangeLayout
{
public class RequestBuilderTest
{
private readonly Guid applicationId;
private readonly Guid archiveId;
private readonly Layout layout;

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

[Fact]
public void Parse_ShouldReturnFailure_GivenApplicationIdIsEmpty() =>
ChangeLayoutRequest.Build()
.WithApplicationId(Guid.Empty)
.WithArchiveId(this.archiveId)
.WithLayout(this.layout)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("ApplicationId cannot be empty."));

[Fact]
public void Parse_ShouldReturnFailure_GivenArchiveIdIsEmpty() =>
ChangeLayoutRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(Guid.Empty)
.WithLayout(this.layout)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("ArchiveId cannot be empty."));

[Fact]
public void Parse_ShouldReturnSuccess_GivenAllValuesAreProvided() =>
ChangeLayoutRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(this.archiveId)
.WithLayout(this.layout)
.Create()
.Should()
.BeSuccess(request =>
{
request.ApplicationId.Should().Be(this.applicationId);
request.ArchiveId.Should().Be(this.archiveId);
request.Layout.Should().Be(this.layout);
});
}
}
42 changes: 10 additions & 32 deletions Vonage.Server.Test/Video/Archives/ChangeLayout/RequestTest.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,35 @@
using System;
using AutoFixture;
using FluentAssertions;
using Vonage.Common.Failures;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Video.Archives.ChangeLayout;
using Xunit;

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

public RequestTest()
{
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<Layout>();
var fixture = new Fixture();
fixture.Customize(new SupportMutableValueTypesCustomization());
this.applicationId = fixture.Create<Guid>();
this.archiveId = fixture.Create<Guid>();
this.layout = fixture.Create<Layout>();
}

[Fact]
public void GetEndpointPath_ShouldReturnApiEndpoint() =>
ChangeLayoutRequest.Parse(this.applicationId, this.archiveId, this.layout)
ChangeLayoutRequest.Build()
.WithApplicationId(this.applicationId)
.WithArchiveId(this.archiveId)
.WithLayout(this.layout)
.Create()
.Map(request => request.GetEndpointPath())
.Should()
.BeSuccess($"/v2/project/{this.applicationId}/archive/{this.archiveId}/layout");

[Fact]
public void Parse_ShouldReturnFailure_GivenApplicationIdIsEmpty() =>
ChangeLayoutRequest.Parse(Guid.Empty, this.archiveId, this.layout)
.Should()
.BeFailure(ResultFailure.FromErrorMessage("ApplicationId cannot be empty."));

[Fact]
public void Parse_ShouldReturnFailure_GivenArchiveIdIsEmpty() =>
ChangeLayoutRequest.Parse(this.applicationId, Guid.Empty, this.layout)
.Should()
.BeFailure(ResultFailure.FromErrorMessage("ArchiveId cannot be empty."));

[Fact]
public void Parse_ShouldReturnSuccess_GivenAllValuesAreProvided() =>
ChangeLayoutRequest.Parse(this.applicationId, this.archiveId, this.layout)
.Should()
.BeSuccess(request =>
{
request.ApplicationId.Should().Be(this.applicationId);
request.ArchiveId.Should().Be(this.archiveId);
});
}
}
8 changes: 5 additions & 3 deletions Vonage.Server.Test/Video/Archives/ChangeLayout/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Server.Common;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.ChangeLayout;
using Xunit;
Expand Down Expand Up @@ -57,7 +56,10 @@ private ExpectedRequest BuildExpectedRequest() =>
};

private static Result<ChangeLayoutRequest> BuildRequest(ISpecimenBuilder fixture) =>
ChangeLayoutRequest.Parse(fixture.Create<Guid>(), fixture.Create<Guid>(),
fixture.Create<Layout>());
ChangeLayoutRequest.Build()
.WithApplicationId(fixture.Create<Guid>())
.WithArchiveId(fixture.Create<Guid>())
.WithLayout(fixture.Create<Layout>())
.Create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using FluentAssertions;
using Vonage.Common.Failures;
using Vonage.Common.Test.Extensions;
using Vonage.Server.Common;
using Vonage.Server.Video.Archives.CreateArchive;
using Xunit;

Expand Down Expand Up @@ -34,47 +33,59 @@ public RequestBuilderTest()

[Fact]
public void Build_ShouldAssignArchiveLayout_GivenWithArchiveLayoutIsUsed() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.WithArchiveLayout(this.layout)
.Create()
.Should()
.BeSuccess(request => request.OutputMode.Should().Be(this.outputMode));

[Fact]
public void Build_ShouldAssignName_GivenWithNameIsUsed() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.WithName(this.name)
.Create()
.Should()
.BeSuccess(request => request.Name.Should().BeSome(this.name));

[Fact]
public void Build_ShouldAssignOutputMode_GivenWithOutputModeIsUsed() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.WithOutputMode(this.outputMode)
.Create()
.Should()
.BeSuccess(request => request.OutputMode.Should().Be(this.outputMode));

[Fact]
public void Build_ShouldAssignResolution_GivenWithRenderResolutionIsUsed() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.WithRenderResolution(this.resolution)
.Create()
.Should()
.BeSuccess(request => request.Resolution.Should().Be(this.resolution));

[Fact]
public void Build_ShouldAssignStreamMode_GivenWithStreamModeIsUsed() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.WithStreamMode(this.streamMode)
.Create()
.Should()
.BeSuccess(request => request.StreamMode.Should().Be(this.streamMode));

[Fact]
public void Build_ShouldReturnSuccess_WithDefaultValues() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.Create()
.Should()
.BeSuccess(request =>
Expand All @@ -92,23 +103,29 @@ public void Build_ShouldReturnSuccess_WithDefaultValues() =>

[Fact]
public void Parse_ShouldReturnDisabledAudio_WhenUsingDisableAudio() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.DisableAudio()
.Create()
.Should()
.BeSuccess(request => request.HasAudio.Should().Be(false));

[Fact]
public void Parse_ShouldReturnDisabledVideo_WhenUsingDisableVideo() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.DisableVideo()
.Create()
.Should()
.BeSuccess(request => request.HasVideo.Should().Be(false));

[Fact]
public void Parse_ShouldReturnFailure_GivenApplicationIdIsEmpty() =>
CreateArchiveRequestBuilder.Build(Guid.Empty, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(Guid.Empty)
.WithSessionId(this.sessionId)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("ApplicationId cannot be empty."));
Expand All @@ -118,7 +135,9 @@ public void Parse_ShouldReturnFailure_GivenApplicationIdIsEmpty() =>
[InlineData(" ")]
[InlineData(null)]
public void Parse_ShouldReturnFailure_GivenSessionIdIsNullOrWhitespace(string value) =>
CreateArchiveRequestBuilder.Build(this.applicationId, value)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(value)
.Create()
.Should()
.BeFailure(ResultFailure.FromErrorMessage("SessionId cannot be null or whitespace."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public RequestTest()

[Fact]
public void GetEndpointPath_ShouldReturnApiEndpoint() =>
CreateArchiveRequestBuilder.Build(this.applicationId, this.sessionId)
CreateArchiveRequest.Build()
.WithApplicationId(this.applicationId)
.WithSessionId(this.sessionId)
.Create()
.Map(request => request.GetEndpointPath())
.Should()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +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;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.CreateArchive
Expand Down
Loading

0 comments on commit a3784a8

Please sign in to comment.