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:
@@ -0,0 +1,46 @@
|
||||
using NSubstitute;
|
||||
using SIGCM2.Application.Abstractions.Persistence;
|
||||
using SIGCM2.Application.Medios.GetById;
|
||||
using SIGCM2.Domain.Entities;
|
||||
using SIGCM2.Domain.Exceptions;
|
||||
|
||||
namespace SIGCM2.Application.Tests.Medios.GetById;
|
||||
|
||||
public class GetMedioByIdQueryHandlerTests
|
||||
{
|
||||
private readonly IMedioRepository _repo = Substitute.For<IMedioRepository>();
|
||||
private readonly GetMedioByIdQueryHandler _handler;
|
||||
|
||||
public GetMedioByIdQueryHandlerTests()
|
||||
{
|
||||
_handler = new GetMedioByIdQueryHandler(_repo);
|
||||
}
|
||||
|
||||
private static Medio MakeMedio(int id) =>
|
||||
new(id, "COD" + id, "Nombre " + id, TipoMedio.Radio, 10, true, DateTime.UtcNow, null);
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_NotFound_ThrowsMedioNotFoundException()
|
||||
{
|
||||
_repo.GetByIdAsync(999, Arg.Any<CancellationToken>()).Returns((Medio?)null);
|
||||
|
||||
await Assert.ThrowsAsync<MedioNotFoundException>(
|
||||
() => _handler.Handle(new GetMedioByIdQuery(999)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_HappyPath_ReturnsDtoWithCorrectFields()
|
||||
{
|
||||
var medio = MakeMedio(3);
|
||||
_repo.GetByIdAsync(3, Arg.Any<CancellationToken>()).Returns(medio);
|
||||
|
||||
var result = await _handler.Handle(new GetMedioByIdQuery(3));
|
||||
|
||||
Assert.Equal(3, result.Id);
|
||||
Assert.Equal("COD3", result.Codigo);
|
||||
Assert.Equal("Nombre 3", result.Nombre);
|
||||
Assert.Equal(TipoMedio.Radio, result.Tipo);
|
||||
Assert.Equal(10, result.PlataformaEmpresaId);
|
||||
Assert.True(result.Activo);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user