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(); private readonly GetProximoNumeroQueryHandler _handler; public GetProximoNumeroQueryHandlerTests() { _handler = new GetProximoNumeroQueryHandler(_repo); } [Fact] public async Task Handle_ExistingSequence_ReturnsUltimoNumeroMasUno() { _repo.GetUltimoNumeroAsync(10, TipoComprobante.FacturaA, Arg.Any()) .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()) .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()) .Returns(5); await _handler.Handle(new GetProximoNumeroQuery(10, TipoComprobante.FacturaA)); await _repo.DidNotReceive().ReservarNumeroAsync( Arg.Any(), Arg.Any(), Arg.Any()); } }