test(secciones): cobertura cascada de inactividad — issue #16

This commit is contained in:
2026-04-17 11:46:14 -03:00
parent 4fb25356a3
commit 3829c93af6
5 changed files with 274 additions and 3 deletions

View File

@@ -11,15 +11,21 @@ namespace SIGCM2.Application.Tests.Secciones.Reactivate;
public class ReactivateSeccionCommandHandlerTests
{
private readonly ISeccionRepository _repo = Substitute.For<ISeccionRepository>();
private readonly IMedioRepository _medioRepo = Substitute.For<IMedioRepository>();
private readonly IAuditLogger _audit = Substitute.For<IAuditLogger>();
private readonly ReactivateSeccionCommandHandler _handler;
private static Seccion MakeSeccion(int id = 1, bool activo = false)
=> new(id, 1, "COD" + id, "Nombre", "clasificados", activo, DateTime.UtcNow, null);
private static Medio MakeMedio(int id = 1, bool activo = true)
=> new(id, "COD" + id, "Medio " + id, TipoMedio.Diario, null, activo, DateTime.UtcNow, null);
public ReactivateSeccionCommandHandlerTests()
{
_handler = new ReactivateSeccionCommandHandler(_repo, _audit);
_handler = new ReactivateSeccionCommandHandler(_repo, _medioRepo, _audit);
// Default: medio is active
_medioRepo.GetByIdAsync(Arg.Any<int>(), Arg.Any<CancellationToken>()).Returns(MakeMedio(1, true));
}
[Fact]
@@ -79,4 +85,18 @@ public class ReactivateSeccionCommandHandlerTests
metadata: Arg.Any<object?>(),
ct: Arg.Any<CancellationToken>());
}
[Fact]
public async Task Handle_MedioInactivo_ThrowsMedioInactivoExceptionAndNoAuditLogged()
{
_repo.GetByIdAsync(1, Arg.Any<CancellationToken>()).Returns(MakeSeccion(1, false));
_medioRepo.GetByIdAsync(1, Arg.Any<CancellationToken>()).Returns(MakeMedio(1, activo: false));
await Assert.ThrowsAsync<MedioInactivoException>(
() => _handler.Handle(new ReactivateSeccionCommand(1)));
await _audit.DidNotReceive().LogAsync(
Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(),
Arg.Any<object?>(), Arg.Any<CancellationToken>());
}
}