test(secciones): cobertura cascada de inactividad — issue #16
This commit is contained in:
@@ -10,12 +10,16 @@ namespace SIGCM2.Application.Tests.Secciones.Update;
|
||||
public class UpdateSeccionCommandHandlerTests
|
||||
{
|
||||
private readonly ISeccionRepository _repo = Substitute.For<ISeccionRepository>();
|
||||
private readonly IMedioRepository _medioRepo = Substitute.For<IMedioRepository>();
|
||||
private readonly IAuditLogger _audit = Substitute.For<IAuditLogger>();
|
||||
private readonly UpdateSeccionCommandHandler _handler;
|
||||
|
||||
private static Seccion MakeSeccion(int id = 1, string nombre = "Original", string tipo = "clasificados")
|
||||
=> new(id, 1, "COD" + id, nombre, tipo, true, 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);
|
||||
|
||||
private static UpdateSeccionCommand ValidCommand(int id = 1) => new(
|
||||
Id: id,
|
||||
Nombre: "Nuevo Nombre",
|
||||
@@ -23,7 +27,9 @@ public class UpdateSeccionCommandHandlerTests
|
||||
|
||||
public UpdateSeccionCommandHandlerTests()
|
||||
{
|
||||
_handler = new UpdateSeccionCommandHandler(_repo, _audit);
|
||||
_handler = new UpdateSeccionCommandHandler(_repo, _medioRepo, _audit);
|
||||
// Default: medio is active
|
||||
_medioRepo.GetByIdAsync(Arg.Any<int>(), Arg.Any<CancellationToken>()).Returns(MakeMedio(1, true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -71,4 +77,18 @@ public class UpdateSeccionCommandHandlerTests
|
||||
metadata: Arg.Any<object?>(),
|
||||
ct: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_MedioInactivo_ThrowsMedioInactivoExceptionAndNoAuditLogged()
|
||||
{
|
||||
_repo.GetByIdAsync(1, Arg.Any<CancellationToken>()).Returns(MakeSeccion(1));
|
||||
_medioRepo.GetByIdAsync(1, Arg.Any<CancellationToken>()).Returns(MakeMedio(1, activo: false));
|
||||
|
||||
await Assert.ThrowsAsync<MedioInactivoException>(
|
||||
() => _handler.Handle(ValidCommand(1)));
|
||||
|
||||
await _audit.DidNotReceive().LogAsync(
|
||||
Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(),
|
||||
Arg.Any<object?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user