using ErsatzTV.Application.Channels; using ErsatzTV.Core; using LanguageExt; using ErsatzTV.Infrastructure.Data.Repositories; using ErsatzTV.Tests.Support; using NUnit.Framework; using Shouldly; using Testably.Abstractions.Testing; namespace ErsatzTV.Tests.Integration; /// /// End-to-end create -> read (get-by-id) -> delete against the in-memory SQLite harness, /// exercising the real EF Core handlers and repository. /// [TestFixture] public class ChannelLifecycleIntegrationTests : ChannelHandlerTestBase { [Test] public async Task Create_Then_Read_Then_Delete() { await SeedFFmpegProfile(); var createHandler = new CreateChannelHandler(Worker, Db.Factory, SearchTargets, RemoteLogoCacher); Either created = await createHandler.Handle(MakeCreate(number: "42", name: "Integration"), CancellationToken.None); int channelId = created.Match(Left: _ => throw new AssertionException("create failed"), Right: r => r.ChannelId); channelId.ShouldBeGreaterThan(0); var getHandler = new GetChannelByIdHandler(new ChannelRepository(Db.Factory)); Option afterCreate = await getHandler.Handle(new GetChannelById(channelId), CancellationToken.None); afterCreate.IsSome.ShouldBeTrue(); afterCreate.Match( Some: vm => { vm.Number.ShouldBe("42"); vm.Name.ShouldBe("Integration"); }, None: () => throw new AssertionException("expected channel to exist")); var deleteHandler = new DeleteChannelHandler(Worker, Db.Factory, new MockFileSystem(), SearchTargets); Either deleted = await deleteHandler.Handle(new DeleteChannel(channelId), CancellationToken.None); deleted.IsRight.ShouldBeTrue(); Option afterDelete = await getHandler.Handle(new GetChannelById(channelId), CancellationToken.None); afterDelete.IsNone.ShouldBeTrue(); } }