Skip to content

Commit

Permalink
refactor: add test use case interface to facilitate new tests (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d authored May 9, 2023
1 parent 85aaa76 commit c41414d
Show file tree
Hide file tree
Showing 55 changed files with 141 additions and 53 deletions.
16 changes: 16 additions & 0 deletions Vonage.Common.Test/TestHelpers/IUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using FsCheck;

namespace Vonage.Common.Test.TestHelpers;

public interface IUseCase
{
Property ShouldReturnFailure_GivenApiErrorCannotBeParsed();

Property ShouldReturnFailure_GivenApiResponseIsError();

Task ShouldReturnFailure_GivenRequestIsFailure();

Task ShouldReturnFailure_GivenTokenGenerationFailed();

Task ShouldReturnSuccess_GivenApiResponseIsSuccess();
}
6 changes: 6 additions & 0 deletions Vonage.Common.Test/TestHelpers/IUseCaseWithResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Vonage.Common.Test.TestHelpers;

public interface IUseCaseWithResponse : IUseCase
{
Task ShouldReturnFailure_GivenApiResponseCannotBeParsed();
}
3 changes: 2 additions & 1 deletion Vonage.Server.Test/Video/Archives/AddStream/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.AddStream;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.AddStream
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new ArchiveClient(configuration).AddStreamAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.ChangeLayout;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.ChangeLayout
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new ArchiveClient(configuration).ChangeLayoutAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.CreateArchive;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.CreateArchive
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<Archive>>> Operation =>
configuration => new ArchiveClient(configuration).CreateArchiveAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.DeleteArchive;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.DeleteArchive
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new ArchiveClient(configuration).DeleteArchiveAsync(this.request);
Expand Down
3 changes: 2 additions & 1 deletion Vonage.Server.Test/Video/Archives/GetArchive/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.GetArchive;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.GetArchive
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<Archive>>> Operation =>
configuration => new ArchiveClient(configuration).GetArchiveAsync(this.request);
Expand Down
3 changes: 2 additions & 1 deletion Vonage.Server.Test/Video/Archives/GetArchives/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.GetArchives;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.GetArchives
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<GetArchivesResponse>>> Operation =>
configuration => new ArchiveClient(configuration).GetArchivesAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.RemoveStream;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.RemoveStream
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new ArchiveClient(configuration).RemoveStreamAsync(this.request);
Expand Down
3 changes: 2 additions & 1 deletion Vonage.Server.Test/Video/Archives/StopArchive/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Archives;
using Vonage.Server.Video.Archives.StopArchive;
using Xunit;

namespace Vonage.Server.Test.Video.Archives.StopArchive
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<Archive>>> Operation =>
configuration => new ArchiveClient(configuration).StopArchiveAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Broadcast;
using Vonage.Server.Video.Broadcast.AddStreamToBroadcast;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.AddStreamToBroadcast
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new BroadcastClient(configuration).AddStreamToBroadcastAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Broadcast;
using Vonage.Server.Video.Broadcast.ChangeBroadcastLayout;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.ChangeBroadcastLayout
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new BroadcastClient(configuration).ChangeBroadcastLayoutAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Broadcast;
using Vonage.Server.Video.Broadcast.GetBroadcast;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.GetBroadcast
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<Server.Video.Broadcast.Broadcast>>> Operation =>
configuration => new BroadcastClient(configuration).GetBroadcastAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Broadcast;
using Vonage.Server.Video.Broadcast.GetBroadcasts;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.GetBroadcasts
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<GetBroadcastsResponse>>> Operation =>
configuration => new BroadcastClient(configuration).GetBroadcastsAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Broadcast;
using Vonage.Server.Video.Broadcast.RemoveStreamFromBroadcast;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.RemoveStreamFromBroadcast
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new BroadcastClient(configuration).RemoveStreamFromBroadcastAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Broadcast;
using Vonage.Server.Video.Broadcast.GetBroadcasts;
using Vonage.Server.Video.Broadcast.StartBroadcast;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.StartBroadcast
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<Server.Video.Broadcast.Broadcast>>> Operation =>
configuration => new BroadcastClient(configuration).StartBroadcastsAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Test;
using Vonage.Common.Test.TestHelpers;
using Vonage.Server.Video.Broadcast;
using Vonage.Server.Video.Broadcast.StopBroadcast;
using Xunit;

namespace Vonage.Server.Test.Video.Broadcast.StopBroadcast
{
public class UseCaseTest : BaseUseCase
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<Server.Video.Broadcast.Broadcast>>> Operation =>
configuration => new BroadcastClient(configuration).StopBroadcastAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
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
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new ModerationClient(configuration).DisconnectConnectionAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
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
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<MuteStreamResponse>>> Operation =>
configuration => new ModerationClient(configuration).MuteStreamAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
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
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<MuteStreamsResponse>>> Operation =>
configuration => new ModerationClient(configuration).MuteStreamsAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
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
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new SessionClient(configuration).ChangeStreamLayoutAsync(this.request);
Expand Down
3 changes: 2 additions & 1 deletion Vonage.Server.Test/Video/Sessions/GetStream/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
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
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<GetStreamResponse>>> Operation =>
configuration => new SessionClient(configuration).GetStreamAsync(this.request);
Expand Down
3 changes: 2 additions & 1 deletion Vonage.Server.Test/Video/Sessions/GetStreams/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
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
public class UseCaseTest : BaseUseCase, IUseCaseWithResponse
{
private Func<VonageHttpClientConfiguration, Task<Result<GetStreamsResponse>>> Operation =>
configuration => new SessionClient(configuration).GetStreamsAsync(this.request);
Expand Down
3 changes: 2 additions & 1 deletion Vonage.Server.Test/Video/Signaling/SendSignal/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
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
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new SignalingClient(configuration).SendSignalAsync(this.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
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
public class UseCaseTest : BaseUseCase, IUseCase
{
private Func<VonageHttpClientConfiguration, Task<Result<Unit>>> Operation =>
configuration => new SignalingClient(configuration).SendSignalsAsync(this.request);
Expand Down
Loading

0 comments on commit c41414d

Please sign in to comment.