using ErsatzTV.Core.Domain; using ErsatzTV.Infrastructure.Data; using ErsatzTV.Tests.Support; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using Shouldly; namespace ErsatzTV.Tests.Infrastructure; [TestFixture] public class ChannelGraphicsElementPersistenceTests { 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 Channel_Can_Attach_And_Read_Back_A_Graphics_Element() { int channelId; int elementId; await using (TvContext context = _db.CreateContext()) { var profile = new FFmpegProfile { Name = "p" }; await context.FFmpegProfiles.AddAsync(profile); var element = new GraphicsElement { Path = "/x/on-now-next.yml", Name = "On Now / Next", Kind = GraphicsElementKind.Text }; await context.GraphicsElements.AddAsync(element); await context.SaveChangesAsync(); var channel = new Channel(Guid.NewGuid()) { Number = "1", Name = "c", Group = "g", FFmpegProfileId = profile.Id, ChannelGraphicsElements = [new ChannelGraphicsElement { GraphicsElementId = element.Id }] }; await context.Channels.AddAsync(channel); await context.SaveChangesAsync(); channelId = channel.Id; elementId = element.Id; } await using (TvContext context = _db.CreateContext()) { Channel loaded = await context.Channels .Include(c => c.ChannelGraphicsElements) .ThenInclude(x => x.GraphicsElement) .SingleAsync(c => c.Id == channelId); loaded.ChannelGraphicsElements.Count.ShouldBe(1); loaded.ChannelGraphicsElements[0].GraphicsElementId.ShouldBe(elementId); loaded.ChannelGraphicsElements[0].GraphicsElement.Name.ShouldBe("On Now / Next"); } } }