feat(medios,secciones): application layer + handlers TDD — ADM-001 B3+B4

- IMedioRepository, ISeccionRepository interfaces
- MediosQuery, SeccionesQuery common records
- TipoSeccion static AllowedTipos helper
- Medios: 6 use cases (Create/Update/Deactivate/Reactivate/List/GetById) with validators, handlers and DTOs
- Secciones: 6 use cases mirroring Medios; Create validates MedioId active via IMedioRepository
- 52 unit tests (xUnit + NSubstitute) all green; audit LogAsync asserted per mutating handler
- DI registrations for all 12 handlers and validators auto-scanned via AddValidatorsFromAssemblyContaining
This commit is contained in:
2026-04-16 18:53:57 -03:00
parent bb98dbf217
commit f672de78ce
56 changed files with 1844 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
using NSubstitute;
using SIGCM2.Application.Abstractions.Persistence;
using SIGCM2.Application.Secciones.GetById;
using SIGCM2.Domain.Entities;
using SIGCM2.Domain.Exceptions;
namespace SIGCM2.Application.Tests.Secciones.GetById;
public class GetSeccionByIdQueryHandlerTests
{
private readonly ISeccionRepository _repo = Substitute.For<ISeccionRepository>();
private readonly GetSeccionByIdQueryHandler _handler;
public GetSeccionByIdQueryHandlerTests()
{
_handler = new GetSeccionByIdQueryHandler(_repo);
}
private static Seccion MakeSeccion(int id) =>
new(id, 2, "COD" + id, "Nombre " + id, "suplementos", true, DateTime.UtcNow, null);
[Fact]
public async Task Handle_NotFound_ThrowsSeccionNotFoundException()
{
_repo.GetByIdAsync(999, Arg.Any<CancellationToken>()).Returns((Seccion?)null);
await Assert.ThrowsAsync<SeccionNotFoundException>(
() => _handler.Handle(new GetSeccionByIdQuery(999)));
}
[Fact]
public async Task Handle_HappyPath_ReturnsDtoWithCorrectFields()
{
var seccion = MakeSeccion(5);
_repo.GetByIdAsync(5, Arg.Any<CancellationToken>()).Returns(seccion);
var result = await _handler.Handle(new GetSeccionByIdQuery(5));
Assert.Equal(5, result.Id);
Assert.Equal(2, result.MedioId);
Assert.Equal("COD5", result.Codigo);
Assert.Equal("Nombre 5", result.Nombre);
Assert.Equal("suplementos", result.Tipo);
Assert.True(result.Activo);
}
}