public HoldInvoiceUseCaseTests() { _dbManager = new Mock <IDatabaseManager>(); _heldInvoiceGateway = new Mock <IHeldInvoiceGateway>(); _payRunInvoiceGateway = new Mock <IPayRunInvoiceGateway>(); _payRunGateway = new Mock <IPayRunGateway>(); _payrun = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, status: PayrunStatus.WaitingForApproval); var fixture = new Fixture(); _payrunInvoice = fixture.Build <PayrunInvoice>() .OmitAutoProperties() .With(pi => pi.PayrunId, _payrun.Id) .With(pi => pi.InvoiceStatus, InvoiceStatus.Draft) .Create(); _payrun.PayrunInvoices.Add(_payrunInvoice); _payRunGateway.Setup(g => g.GetPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayRunFields>(), It.IsAny <bool>())) .ReturnsAsync(_payrun); _payRunInvoiceGateway.Setup(g => g.GetPayRunInvoiceAsync(It.IsAny <Guid>(), It.IsAny <PayRunInvoiceFields>(), It.IsAny <bool>())) .ReturnsAsync(_payrunInvoice); _useCase = new HoldInvoiceUseCase(_dbManager.Object, _heldInvoiceGateway.Object, _payRunInvoiceGateway.Object, _payRunGateway.Object); _heldInvoiceCreationDomain = new HeldInvoiceCreationDomain { PayRunInvoiceId = _payrunInvoice.Id, ActionRequiredFromId = 1, ReasonForHolding = "Incorrect values" }; }
public static HeldInvoiceCreationRequest ToRequest(this HeldInvoiceCreationDomain input) { return(_mapper.Map <HeldInvoiceCreationRequest>(input)); }
public static HeldInvoice ToEntity(this HeldInvoiceCreationDomain input) { return(_mapper.Map <HeldInvoice>(input)); }
public async Task <HeldInvoiceFlatResponse> ExecuteAsync(Guid payRunId, Guid invoiceId, HeldInvoiceCreationDomain heldInvoiceCreationDomain) { heldInvoiceCreationDomain.PayRunInvoiceId = invoiceId; var payRun = await _payRunGateway.GetPayRunAsync(payRunId) .EnsureExistsAsync($"Pay run with id {payRunId} not found"); var validPayRunStatuses = new[] { PayrunStatus.WaitingForReview, PayrunStatus.WaitingForApproval }; if (!validPayRunStatuses.Contains(payRun.Status)) { throw new ApiException($"Pay run must be in review or waiting for approval to allow status change", HttpStatusCode.BadRequest); } var payRunInvoice = await _payRunInvoiceGateway.GetPayRunInvoiceAsync(heldInvoiceCreationDomain.PayRunInvoiceId, PayRunInvoiceFields.None, true).EnsureExistsAsync($"Pay run invoice with id {heldInvoiceCreationDomain.PayRunInvoiceId} not found"); // Update pay run invoice status payRunInvoice.InvoiceStatus = InvoiceStatus.Held; // Create held invoice record var heldInvoice = heldInvoiceCreationDomain.ToEntity(); _heldInvoiceGateway.AddHeldInvoice(heldInvoice); await _dbManager.SaveAsync(); return(heldInvoice.ToFlatDomain().ToResponse()); }