143 lines
4.5 KiB
C#
143 lines
4.5 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.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!;
|
|
|
|
[SetUp]
|
|
public async Task BaseSetUp()
|
|
{
|
|
Db = await InMemoryTvContext.CreateAsync();
|
|
Worker = System.Threading.Channels.Channel.CreateUnbounded<IBackgroundServiceRequest>().Writer;
|
|
SearchTargets = Substitute.For<ISearchTargets>();
|
|
}
|
|
|
|
[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 SeedChannel(
|
|
int id,
|
|
string number,
|
|
string name = "Test",
|
|
int ffmpegProfileId = 1,
|
|
string group = "ErsatzTV")
|
|
{
|
|
await using TvContext context = Db.CreateContext();
|
|
context.Channels.Add(
|
|
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
|
|
});
|
|
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") =>
|
|
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.TransportStreamHybrid,
|
|
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") =>
|
|
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);
|
|
}
|