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,52 @@
using NSubstitute;
using SIGCM2.Application.Abstractions.Persistence;
using SIGCM2.Application.PuntosDeVenta.ProximoNumero;
using SIGCM2.Domain.Enums;
namespace SIGCM2.Application.Tests.PuntosDeVenta.ProximoNumero;
public class GetProximoNumeroQueryHandlerTests
{
private readonly IPuntoDeVentaRepository _repo = Substitute.For<IPuntoDeVentaRepository>();
private readonly GetProximoNumeroQueryHandler _handler;
public GetProximoNumeroQueryHandlerTests()
{
_handler = new GetProximoNumeroQueryHandler(_repo);
}
[Fact]
public async Task Handle_ExistingSequence_ReturnsUltimoNumeroMasUno()
{
_repo.GetUltimoNumeroAsync(10, TipoComprobante.FacturaA, Arg.Any<CancellationToken>())
.Returns(7);
var result = await _handler.Handle(new GetProximoNumeroQuery(10, TipoComprobante.FacturaA));
Assert.Equal(TipoComprobante.FacturaA, result.TipoComprobante);
Assert.Equal(8, result.ProximoNumero);
}
[Fact]
public async Task Handle_NoExistingSequence_ReturnsOne()
{
_repo.GetUltimoNumeroAsync(10, TipoComprobante.FacturaB, Arg.Any<CancellationToken>())
.Returns((int?)null);
var result = await _handler.Handle(new GetProximoNumeroQuery(10, TipoComprobante.FacturaB));
Assert.Equal(1, result.ProximoNumero);
}
[Fact]
public async Task Handle_DoesNotCallReservarNumero()
{
_repo.GetUltimoNumeroAsync(10, TipoComprobante.FacturaA, Arg.Any<CancellationToken>())
.Returns(5);
await _handler.Handle(new GetProximoNumeroQuery(10, TipoComprobante.FacturaA));
await _repo.DidNotReceive().ReservarNumeroAsync(
Arg.Any<int>(), Arg.Any<TipoComprobante>(), Arg.Any<CancellationToken>());
}
}