test(secciones): cobertura cascada de inactividad — issue #16
This commit is contained in:
@@ -10,15 +10,21 @@ namespace SIGCM2.Application.Tests.Secciones.Deactivate;
|
||||
public class DeactivateSeccionCommandHandlerTests
|
||||
{
|
||||
private readonly ISeccionRepository _repo = Substitute.For<ISeccionRepository>();
|
||||
private readonly IMedioRepository _medioRepo = Substitute.For<IMedioRepository>();
|
||||
private readonly IAuditLogger _audit = Substitute.For<IAuditLogger>();
|
||||
private readonly DeactivateSeccionCommandHandler _handler;
|
||||
|
||||
private static Seccion MakeSeccion(int id = 1, bool activo = true)
|
||||
=> 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 DeactivateSeccionCommandHandlerTests()
|
||||
{
|
||||
_handler = new DeactivateSeccionCommandHandler(_repo, _audit);
|
||||
_handler = new DeactivateSeccionCommandHandler(_repo, _medioRepo, _audit);
|
||||
// Default: medio is active
|
||||
_medioRepo.GetByIdAsync(Arg.Any<int>(), Arg.Any<CancellationToken>()).Returns(MakeMedio(1, true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -78,4 +84,18 @@ public class DeactivateSeccionCommandHandlerTests
|
||||
metadata: Arg.Any<object?>(),
|
||||
ct: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_MedioInactivo_ThrowsMedioInactivoExceptionAndNoAuditLogged()
|
||||
{
|
||||
_repo.GetByIdAsync(1, Arg.Any<CancellationToken>()).Returns(MakeSeccion(1, true));
|
||||
_medioRepo.GetByIdAsync(1, Arg.Any<CancellationToken>()).Returns(MakeMedio(1, activo: false));
|
||||
|
||||
await Assert.ThrowsAsync<MedioInactivoException>(
|
||||
() => _handler.Handle(new DeactivateSeccionCommand(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