Files
ersatztv/ErsatzTV.Tests/Integration/ChannelLifecycleIntegrationTests.cs
T
2026-07-21 13:13:21 +02:00

53 lines
2.0 KiB
C#

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;
/// <summary>
/// End-to-end create -> read (get-by-id) -> delete against the in-memory SQLite harness,
/// exercising the real EF Core handlers and repository.
/// </summary>
[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<BaseError, CreateChannelResult> 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<ChannelViewModel> 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<BaseError, Unit> deleted =
await deleteHandler.Handle(new DeleteChannel(channelId), CancellationToken.None);
deleted.IsRight.ShouldBeTrue();
Option<ChannelViewModel> afterDelete =
await getHandler.Handle(new GetChannelById(channelId), CancellationToken.None);
afterDelete.IsNone.ShouldBeTrue();
}
}