Esempio n. 1
0
        public void PostShouldValidateParametersAndThrowException(decimal amount, long cardNumber, int ccv, int merchantId)
        {
            var paymentRequest = new MerchantPaymentDetailsRequest()
            {
                MerchantId = merchantId,
                Payment    = new PaymentDetails()
                {
                    Amount     = amount,
                    CardNumber = cardNumber,
                    CCV        = ccv,
                    Timestamp  = DateTime.MaxValue
                }
            };

            var payment = new MerchantPaymentDetails(paymentRequest);

            var paymentService = new Mock <IPaymentService>();

            paymentService.Setup(ps => ps.ProcessPayment(It.IsAny <MerchantPaymentDetails>()))
            .Returns(Task.FromResult <MerchantTransactionPayment>(null));

            var sut = new Controllers.PaymentController(paymentService.Object);

            Assert.Throws <AggregateException>(() =>
            {
                var result = sut.Post(paymentRequest).Result;
            });

            paymentService.Verify(ps => ps.ProcessPayment(
                                      It.IsAny <MerchantPaymentDetails>()), Times.Never);
        }
Esempio n. 2
0
        public async Task <MerchantTransactionPayment> Post(MerchantPaymentDetailsRequest payment)
        {
            if (payment == null || payment.MerchantId == 0 || ValidatePaymentDetails(payment.Payment))
            {
                throw new ArgumentException("Invalid data.");
            }

            var data = new MerchantPaymentDetails(payment);

            var processedPayment = await paymentService.ProcessPayment(data);

            return(processedPayment);
        }
Esempio n. 3
0
        public void PostShouldCallPaymentServiceProcessPayment()
        {
            var paymentRequest = new MerchantPaymentDetailsRequest()
            {
                MerchantId = 123456,
                Payment    = new PaymentDetails()
                {
                    Amount     = 1,
                    CardNumber = 1234123412341234,
                    CCV        = 123,
                    Timestamp  = DateTime.MaxValue
                }
            };

            var payment = new MerchantPaymentDetails(paymentRequest);

            var transaction = new MerchantTransactionPayment()
            {
                Payment       = payment,
                Status        = PaymentStatus.Success,
                TransactionId = 1
            };

            var paymentService = new Mock <IPaymentService>();

            paymentService.Setup(ps => ps.ProcessPayment(It.IsAny <MerchantPaymentDetails>()))
            .Returns(Task.FromResult(transaction));

            var sut = new Controllers.PaymentController(paymentService.Object);

            var result = sut.Post(paymentRequest).Result;

            Assert.NotNull(result);
            paymentService.Verify(ps => ps.ProcessPayment(
                                      It.Is <MerchantPaymentDetails>(pd =>
                                                                     payment.CardNumber == pd.CardNumber &&
                                                                     payment.CCV == pd.CCV &&
                                                                     payment.Amount == pd.Amount &&
                                                                     payment.MerchantId == pd.MerchantId &&
                                                                     payment.Timestamp == pd.Timestamp
                                                                     )), Times.Once);
        }