public void ProcessPayments_Validator_Valid(decimal amount, string cardHolder, string creditCard, DateTime exp, string sec) { // Arrange PaymentProcessModel model = new PaymentProcessModel() { Amount = amount, CardHolder = cardHolder, CreditCardNumber = creditCard, ExpirationDate = exp, SecurityCode = sec }; // Act PaymentProcessValidator _validator = new PaymentProcessValidator(); ValidationResult result = _validator.Validate(model); // Assert result.IsValid.Should().BeFalse(); }
public async Task <ActionResult <PaymentProcessExtModel> > PostPaymentProcess(PaymentProcessModel paymentProcess) { try { // Request validation PaymentProcessValidator _validator = new PaymentProcessValidator(); ValidationResult result = _validator.Validate(paymentProcess); if (!result.IsValid) { return(BadRequest(result.Errors)); } PaymentProcess _paymentProcess = _mapper.Map <PaymentProcess>(paymentProcess); _paymentProcess.Id = Guid.NewGuid().ToString(); _paymentProcess.Status = PaymentStatus.PENDING; _paymentProcess.Tries = 0; _ = _unitOfWork.PaymentProcesses.InsertAsync(_paymentProcess); await _unitOfWork.CompleteAsync(); return(Ok(_paymentProcess)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }