Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (push) Skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (push) Skipped
Build ErsatzTV Image / CI toolchain image resolves (push) Successful in 9s
Build ErsatzTV Image / Delimiter ban (release path) (push) Successful in 25s
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 8m40s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 6m18s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (push) Successful in 6m12s
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 4m13s
probe742/combined-newest SECOND
Co-authored-by: Timothy <timothy@noreply.gitea.tblindustries.be>
163 lines
5.1 KiB
C#
163 lines
5.1 KiB
C#
using System.Threading.Channels;
|
|
using ErsatzTV.Application;
|
|
using ErsatzTV.Application.Artworks;
|
|
using ErsatzTV.Application.Channels;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Images;
|
|
using ErsatzTV.Core.Interfaces.Search;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using DomainChannel = ErsatzTV.Core.Domain.Channel;
|
|
|
|
namespace ErsatzTV.Tests.Support;
|
|
|
|
public abstract class ChannelHandlerTestBase
|
|
{
|
|
protected InMemoryTvContext Db = null!;
|
|
protected ChannelWriter<IBackgroundServiceRequest> Worker = null!;
|
|
protected ISearchTargets SearchTargets = null!;
|
|
protected IRemoteLogoCacher RemoteLogoCacher = null!;
|
|
|
|
[SetUp]
|
|
public async Task BaseSetUp()
|
|
{
|
|
Db = await InMemoryTvContext.CreateAsync();
|
|
Worker = System.Threading.Channels.Channel.CreateUnbounded<IBackgroundServiceRequest>().Writer;
|
|
SearchTargets = Substitute.For<ISearchTargets>();
|
|
RemoteLogoCacher = Substitute.For<IRemoteLogoCacher>();
|
|
}
|
|
|
|
[TearDown]
|
|
public async Task BaseTearDown() => await Db.DisposeAsync();
|
|
|
|
protected async Task SeedFFmpegProfile(int id = 1)
|
|
{
|
|
await using TvContext context = Db.CreateContext();
|
|
context.FFmpegProfiles.Add(new FFmpegProfile { Id = id, Name = $"profile-{id}" });
|
|
await context.SaveChangesAsync();
|
|
}
|
|
|
|
protected async Task<DomainChannel> SeedChannel(
|
|
int id,
|
|
string number,
|
|
string name = "Test",
|
|
int ffmpegProfileId = 1,
|
|
string group = "ErsatzTV")
|
|
{
|
|
await using TvContext context = Db.CreateContext();
|
|
var channel = new DomainChannel(Guid.NewGuid())
|
|
{
|
|
Id = id,
|
|
Number = number,
|
|
Name = name,
|
|
Group = group,
|
|
Categories = string.Empty,
|
|
FFmpegProfileId = ffmpegProfileId,
|
|
StreamSelector = string.Empty,
|
|
PreferredAudioLanguageCode = string.Empty,
|
|
PreferredAudioTitle = string.Empty,
|
|
PreferredSubtitleLanguageCode = string.Empty,
|
|
MusicVideoCreditsTemplate = string.Empty,
|
|
StreamingMode = StreamingMode.TransportStreamHybrid,
|
|
PlayoutSource = ChannelPlayoutSource.Generated,
|
|
PlayoutMode = ChannelPlayoutMode.Continuous
|
|
};
|
|
context.Channels.Add(channel);
|
|
await context.SaveChangesAsync();
|
|
return channel;
|
|
}
|
|
|
|
protected async Task SeedPlayout(int id, int channelId)
|
|
{
|
|
await using TvContext context = Db.CreateContext();
|
|
context.Playouts.Add(
|
|
new Playout
|
|
{
|
|
Id = id,
|
|
ChannelId = channelId,
|
|
ScheduleKind = PlayoutScheduleKind.Classic
|
|
});
|
|
await context.SaveChangesAsync();
|
|
}
|
|
|
|
protected static CreateChannel MakeCreate(
|
|
string number = "5",
|
|
int ffmpegProfileId = 1,
|
|
bool isEnabled = true,
|
|
bool showInEpg = false,
|
|
string logoPath = "",
|
|
string name = "Test",
|
|
string group = "ErsatzTV",
|
|
StreamingMode streamingMode = StreamingMode.TransportStreamHybrid) =>
|
|
new(
|
|
name,
|
|
number,
|
|
group,
|
|
string.Empty,
|
|
ffmpegProfileId,
|
|
null,
|
|
new ArtworkContentTypeModel(logoPath, string.Empty),
|
|
ChannelStreamSelectorMode.Default,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
ChannelPlayoutSource.Generated,
|
|
ChannelPlayoutMode.Continuous,
|
|
null,
|
|
null,
|
|
streamingMode,
|
|
null,
|
|
null,
|
|
string.Empty,
|
|
ChannelSubtitleMode.None,
|
|
ChannelMusicVideoCreditsMode.None,
|
|
string.Empty,
|
|
ChannelSongVideoMode.Default,
|
|
ChannelTranscodeMode.OnDemand,
|
|
ChannelIdleBehavior.StopOnDisconnect,
|
|
isEnabled,
|
|
showInEpg);
|
|
|
|
protected static UpdateChannel MakeUpdate(
|
|
int channelId,
|
|
string number = "5",
|
|
int ffmpegProfileId = 1,
|
|
bool isEnabled = true,
|
|
bool showInEpg = false,
|
|
string logoPath = "",
|
|
string name = "Test",
|
|
string group = "ErsatzTV",
|
|
List<int> graphicsElementIds = null) =>
|
|
new(
|
|
channelId,
|
|
name,
|
|
number,
|
|
group,
|
|
string.Empty,
|
|
ffmpegProfileId,
|
|
null,
|
|
new ArtworkContentTypeModel(logoPath, string.Empty),
|
|
ChannelStreamSelectorMode.Default,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
ChannelPlayoutSource.Generated,
|
|
ChannelPlayoutMode.Continuous,
|
|
null,
|
|
null,
|
|
StreamingMode.TransportStreamHybrid,
|
|
null,
|
|
null,
|
|
string.Empty,
|
|
ChannelSubtitleMode.None,
|
|
ChannelMusicVideoCreditsMode.None,
|
|
string.Empty,
|
|
ChannelSongVideoMode.Default,
|
|
ChannelTranscodeMode.OnDemand,
|
|
ChannelIdleBehavior.StopOnDisconnect,
|
|
isEnabled,
|
|
showInEpg,
|
|
graphicsElementIds ?? []);
|
|
}
|