52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using ErsatzTV.Tests.Support;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Infrastructure;
|
|
|
|
[TestFixture]
|
|
public class DbInitializerChannelTemplateTests
|
|
{
|
|
private InMemoryTvContext _db = null!;
|
|
|
|
[SetUp]
|
|
public async Task SetUp() => _db = await InMemoryTvContext.CreateAsync();
|
|
|
|
[TearDown]
|
|
public async Task TearDown() => await _db.DisposeAsync();
|
|
|
|
[Test]
|
|
public async Task Initialize_Should_Seed_System_Channel_Templates_And_Default_Config()
|
|
{
|
|
await using TvContext context = _db.CreateContext();
|
|
|
|
await DbInitializer.Initialize(context, CancellationToken.None);
|
|
|
|
List<ChannelTemplate> templates = context.ChannelTemplates.OrderBy(t => t.Name).ToList();
|
|
templates.Count.ShouldBe(2);
|
|
templates.ShouldContain(t => t.Name == "Music videos" && t.IsSystem);
|
|
ChannelTemplate standard = templates.Single(t => t.Name == "Standard");
|
|
standard.IsSystem.ShouldBeTrue();
|
|
|
|
ConfigElement config = context.ConfigElements.Single(
|
|
c => c.Key == ConfigElementKey.ChannelTemplatesDefaultTemplateId.Key);
|
|
config.Value.ShouldBe(standard.Id.ToString());
|
|
}
|
|
|
|
[Test]
|
|
public async Task Initialize_Should_Not_Clobber_Existing_System_Template()
|
|
{
|
|
await using TvContext context = _db.CreateContext();
|
|
await DbInitializer.Initialize(context, CancellationToken.None);
|
|
ChannelTemplate standard = context.ChannelTemplates.Single(t => t.Name == "Standard");
|
|
standard.Description = "User adjusted description";
|
|
await context.SaveChangesAsync();
|
|
|
|
await DbInitializer.Initialize(context, CancellationToken.None);
|
|
|
|
context.ChannelTemplates.Single(t => t.Name == "Standard").Description.ShouldBe("User adjusted description");
|
|
}
|
|
}
|