52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using System.Threading.Channels;
|
|
using ErsatzTV.Application;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Search;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
|
|
namespace ErsatzTV.Tests.Support;
|
|
|
|
public abstract class MediaCollectionHandlerTestBase
|
|
{
|
|
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 SeedCollection(int id, string name = "Collection")
|
|
{
|
|
await using TvContext context = Db.CreateContext();
|
|
context.Collections.Add(new Collection
|
|
{
|
|
Id = id,
|
|
Name = name,
|
|
MediaItems = []
|
|
});
|
|
await context.SaveChangesAsync();
|
|
}
|
|
|
|
protected async Task SeedSmartCollection(int id, string name = "Smart", string query = "tag:family")
|
|
{
|
|
await using TvContext context = Db.CreateContext();
|
|
context.SmartCollections.Add(new SmartCollection
|
|
{
|
|
Id = id,
|
|
Name = name,
|
|
Query = query
|
|
});
|
|
await context.SaveChangesAsync();
|
|
}
|
|
}
|