예제 #1
0
        public async Task <IActionResult> ProcessPaymentAsync([FromQuery] ProcessPaymentRequest processPaymentRequest)
        {
            try
            {
                var result = await _PaymentBusiness.ProcessPaymentAsync(processPaymentRequest).ConfigureAwait(false);

                return(Ok(result));
            }
            catch (InvalidOperationException ex)
            {
                _Logger.LogError(ex.Message, ex);
                return(BadRequest());
            }
            catch (Exception ex)
            {
                _Logger.LogError(ex.Message, ex);
                return(StatusCode(500, "Internal Server Error"));
            }
        }
예제 #2
0
        public void ProcessPaymentAsync_200()
        {
            var request = new ProcessPaymentRequest()
            {
                Amount = 101
            };
            var payment = new Payment()
            {
                Amount = 101, Id = 1, Status = "processed"
            };

            _PaymentBusiness.ProcessPaymentAsync(Arg.Any <ProcessPaymentRequest>()).Returns(payment);
            var actionResult = _PaymentController.ProcessPaymentAsync(request).GetAwaiter().GetResult() as OkObjectResult;

            Assert.Equals(200, actionResult.StatusCode);
            Assert.IsTrue(actionResult.Value is ProcessPaymentResponse);
            var result = actionResult.Value as ProcessPaymentResponse;

            Assert.IsTrue(result.PaymentAmount.Equals(payment.Amount.ToString()));
            Assert.IsTrue(result.PaymentRefrenceNumber.Equals(payment.Id.ToString()));
            Assert.IsTrue(result.PaymentStatus.Equals(payment.Status.ToString()));
        }