コード例 #1
0
        public void CreatePaymentTest_Validate_Approve_Status_Balance_Check()
        {
            decimal initialBalance       = InMemoryData.CurrentBalance;
            CreatePaymentRequest request = new CreatePaymentRequest {
                Amount = 10, PaymentDate = DateTime.Now
            };
            PaymentValidatorService validatorService = new PaymentValidatorService();
            PaymentService          paymentService   = new PaymentService(validatorService);
            CreatePaymentResponse   response         = paymentService.CreatePayment(request);

            if (response.IsValid && response.Payment != null &&
                response.Payment.RunningBalance == initialBalance &&
                response.ErrorMessages.Count == 0 &&
                response.Payment.Status == "Pending")
            {
                ApprovePaymentRequest approvePaymentRequest = new ApprovePaymentRequest();
                approvePaymentRequest.PaymentId = response.Payment.PaymentId;
                ApprovePaymentResponse approvePaymentResponse = paymentService.ApprovePayment(approvePaymentRequest);
                if (approvePaymentResponse.IsValid)
                {
                    Assert.IsTrue(approvePaymentResponse.Payment.Status == "Processed");
                    Assert.IsTrue(approvePaymentResponse.Payment.RunningBalance == (initialBalance - request.Amount));
                    Assert.IsTrue(approvePaymentResponse.Payment.Amount == request.Amount);
                }
            }
            else
            {
                string msg       = string.Empty;
                string delimiter = Environment.NewLine;
                response.ErrorMessages.ForEach(x => msg += x + delimiter);
                Assert.Fail(msg);
            }
        }
コード例 #2
0
        private CreatePaymentResponse CreatePaymentResponse(decimal amount, DateTime paymentDate)
        {
            CreatePaymentRequest request = new CreatePaymentRequest {
                Amount = amount, PaymentDate = paymentDate
            };
            PaymentValidatorService validatorService = new PaymentValidatorService();
            PaymentService          paymentService   = new PaymentService(validatorService);
            CreatePaymentResponse   response         = paymentService.CreatePayment(request);

            return(response);
        }
コード例 #3
0
        public void CreatePaymentTest_Disallow_Cancel_On_Closed_Payments()
        {
            decimal initialBalance       = InMemoryData.CurrentBalance;
            CreatePaymentRequest request = new CreatePaymentRequest {
                Amount = 10, PaymentDate = DateTime.Now
            };
            PaymentValidatorService validatorService = new PaymentValidatorService();
            PaymentService          paymentService   = new PaymentService(validatorService);
            CreatePaymentResponse   response         = paymentService.CreatePayment(request);

            if (response.IsValid && response.Payment != null &&
                response.Payment.RunningBalance == initialBalance &&
                response.ErrorMessages.Count == 0 &&
                response.Payment.Status == "Pending")
            {
                CancelPaymentRequest cancelPaymentRequest = new CancelPaymentRequest
                {
                    PaymentId = response.Payment.PaymentId
                };
                CancelPaymentResponse cancelPaymentResponse = paymentService.CancelPayment(cancelPaymentRequest);
                if (cancelPaymentResponse.IsValid)
                {
                    CancelPaymentRequest tryCancelClosedPayment = new CancelPaymentRequest();
                    tryCancelClosedPayment.PaymentId = cancelPaymentResponse.Payment.PaymentId;
                    CancelPaymentResponse disAllowedAction = paymentService.CancelPayment(tryCancelClosedPayment);
                    Assert.IsFalse(disAllowedAction.IsValid);
                    Assert.IsTrue(disAllowedAction.ErrorMessages.Count == 1);
                    Assert.IsTrue(disAllowedAction.ErrorMessages[0] == "Only pending payment can be cancelled");
                }
            }
            else
            {
                string msg       = string.Empty;
                string delimiter = Environment.NewLine;
                response.ErrorMessages.ForEach(x => msg += x + delimiter);
                Assert.Fail(msg);
            }
        }
コード例 #4
0
        public void CreatePaymentTest_Validate_Cancel_Status_Balance_And_Cancel_Reason_Check()
        {
            decimal initialBalance       = InMemoryData.CurrentBalance;
            CreatePaymentRequest request = new CreatePaymentRequest {
                Amount = 10, PaymentDate = DateTime.Now
            };
            PaymentValidatorService validatorService = new PaymentValidatorService();
            PaymentService          paymentService   = new PaymentService(validatorService);
            CreatePaymentResponse   response         = paymentService.CreatePayment(request);

            if (response.IsValid && response.Payment != null &&
                response.Payment.RunningBalance == initialBalance &&
                response.ErrorMessages.Count == 0 &&
                response.Payment.Status == "Pending")
            {
                CancelPaymentRequest cancelPaymentRequest = new CancelPaymentRequest
                {
                    PaymentId    = response.Payment.PaymentId,
                    CancelReason = "I am testing if can cancel works or not"
                };
                CancelPaymentResponse cancelPaymentResponse = paymentService.CancelPayment(cancelPaymentRequest);
                if (cancelPaymentResponse.IsValid)
                {
                    Assert.IsTrue(cancelPaymentResponse.Payment.Status == "Closed");
                    Assert.IsTrue(cancelPaymentResponse.Payment.CancellationMessage == cancelPaymentRequest.CancelReason);

                    Assert.IsTrue(cancelPaymentResponse.Payment.RunningBalance == initialBalance);
                    Assert.IsTrue(cancelPaymentResponse.Payment.Amount == request.Amount);
                }
            }
            else
            {
                string msg       = string.Empty;
                string delimiter = Environment.NewLine;
                response.ErrorMessages.ForEach(x => msg += x + delimiter);
                Assert.Fail(msg);
            }
        }