Files
SIG-CM2.0/tests/SIGCM2.Application.Tests/PuntosDeVenta/ProximoNumero/GetProximoNumeroQueryHandlerTests.cs

53 lines
1.7 KiB
C#
Raw Normal View History

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>());
}
}