feat(application): repository abstraction + DTOs + validators + handlers CRUD PuntosDeVenta con auditoría + retry deadlock

This commit is contained in:
2026-04-17 12:28:11 -03:00
parent 43877bd4a1
commit 50f6f2b67a
36 changed files with 1296 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
using NSubstitute;
using SIGCM2.Application.Abstractions.Persistence;
using SIGCM2.Application.PuntosDeVenta.GetById;
using SIGCM2.Domain.Entities;
using SIGCM2.Domain.Exceptions;
namespace SIGCM2.Application.Tests.PuntosDeVenta.GetById;
public class GetPuntoDeVentaByIdQueryHandlerTests
{
private readonly IPuntoDeVentaRepository _repo = Substitute.For<IPuntoDeVentaRepository>();
private readonly GetPuntoDeVentaByIdQueryHandler _handler;
public GetPuntoDeVentaByIdQueryHandlerTests()
{
_handler = new GetPuntoDeVentaByIdQueryHandler(_repo);
}
private static PuntoDeVenta MakePdv(int id = 5) =>
new(id, 2, 3, "PdV " + id, "Desc", true, DateTime.UtcNow, null);
[Fact]
public async Task Handle_NotFound_ThrowsPuntoDeVentaNotFoundException()
{
_repo.GetByIdAsync(999, Arg.Any<CancellationToken>()).Returns((PuntoDeVenta?)null);
await Assert.ThrowsAsync<PuntoDeVentaNotFoundException>(
() => _handler.Handle(new GetPuntoDeVentaByIdQuery(999)));
}
[Fact]
public async Task Handle_HappyPath_ReturnsDtoWithCorrectFields()
{
var pdv = MakePdv(5);
_repo.GetByIdAsync(5, Arg.Any<CancellationToken>()).Returns(pdv);
var result = await _handler.Handle(new GetPuntoDeVentaByIdQuery(5));
Assert.Equal(5, result.Id);
Assert.Equal(2, result.MedioId);
Assert.Equal(3, result.NumeroAFIP);
Assert.Equal("PdV 5", result.Nombre);
Assert.Equal("Desc", result.Descripcion);
Assert.True(result.Activo);
}
}