示例#1
0
        public async Task ItWillCaptureTransaction(bool captureSuccess)
        {
            using (AutoMock mock = AutoMock.GetLoose())
            {
                var paymentMethod      = PaymentMethod.CreditCard;
                var paymentTransaction = GetPaymentTransaction();
                var paymentProfile     = GetPaymentProfile();
                var mockExternalPaymentProcessingService = new MockExternalPaymentProcessingService
                {
                    TestCallResponseType = captureSuccess
                        ? TestCallResponseType.Succcess
                        : TestCallResponseType.Failure
                };

                mock.Mock <IExternalPaymentFactory>().Setup(x => x.GetPaymentService(It.IsAny <PaymentMethod>()))
                .Returns(mockExternalPaymentProcessingService);

                var externalPaymentService = mock.Create <ExternalPaymentService>();
                var result = await externalPaymentService.CaptureTransaction(paymentMethod, paymentTransaction, paymentProfile);

                Assert.NotNull(result);
                Assert.Equal(captureSuccess, result.IsApproved);

                mockExternalPaymentProcessingService.VerifyCaptureTransactionCalls(paymentTransaction, paymentProfile);

                mock.Mock <IExternalPaymentFactory>().Verify(x =>
                                                             x.GetPaymentService(It.Is <PaymentMethod>(p => p == paymentMethod)), Times.Once);
            }
        }
示例#2
0
        public async Task ItWillSendManualProcessingEmail()
        {
            using (AutoMock mock = AutoMock.GetLoose())
            {
                var paymentMethod      = PaymentMethod.CreditCard;
                var paymentTransaction = GetPaymentTransaction();
                var paymentProfile     = GetPaymentProfile();
                var mockExternalPaymentProcessingService = new MockExternalPaymentProcessingService();

                mock.Mock <IExternalPaymentFactory>().Setup(x => x.GetPaymentService(It.IsAny <PaymentMethod>()))
                .Returns(mockExternalPaymentProcessingService);

                var externalPaymentService = mock.Create <ExternalPaymentService>();
                await externalPaymentService.SendManualProcessingEmail(paymentMethod, paymentTransaction, paymentProfile);

                mockExternalPaymentProcessingService.VerifySendManualProcessingEmailCalls(paymentTransaction, paymentProfile);

                mock.Mock <IExternalPaymentFactory>().Verify(x =>
                                                             x.GetPaymentService(It.Is <PaymentMethod>(p => p == paymentMethod)), Times.Once);
            }
        }
示例#3
0
        public void ItWillCheckIsAutomatedProcessingEnabled()
        {
            using (AutoMock mock = AutoMock.GetLoose())
            {
                var paymentMethod = PaymentMethod.CreditCard;
                var mockExternalPaymentProcessingService = new MockExternalPaymentProcessingService();

                mock.Mock <IExternalPaymentFactory>().Setup(x => x.GetPaymentService(It.IsAny <PaymentMethod>()))
                .Returns(mockExternalPaymentProcessingService);

                var  externalPaymentService = mock.Create <ExternalPaymentService>();
                bool result = externalPaymentService.IsAutomatedProcessingEnabled(paymentMethod);

                Assert.True(result);
                mockExternalPaymentProcessingService.VerifyIsAutomatedProcessingEnabledCalled();

                mock.Mock <IExternalPaymentFactory>().Verify(x =>
                                                             x.GetPaymentService(It.Is <PaymentMethod>(p => p == paymentMethod)), Times.Once);
                //mock.Mock<IExternalPaymentFactory>().Verify(x =>
                //    x.GetPaymentService(It.IsAny<PaymentMethod>()), Times.Once);
            }
        }
示例#4
0
        public async Task ItWillRefundTransaction()
        {
            using (AutoMock mock = AutoMock.GetLoose())
            {
                var paymentMethod      = PaymentMethod.CreditCard;
                var paymentTransaction = GetPaymentTransaction();
                var paymentProfile     = GetPaymentProfile();
                var mockExternalPaymentProcessingService = new MockExternalPaymentProcessingService();

                mock.Mock <IExternalPaymentFactory>().Setup(x => x.GetPaymentService(It.IsAny <PaymentMethod>()))
                .Returns(mockExternalPaymentProcessingService);

                var externalPaymentService = mock.Create <ExternalPaymentService>();
                var result = await externalPaymentService.RefundTransaction(paymentMethod, paymentTransaction, paymentProfile);

                Assert.NotNull(result);
                Assert.True(result.IsApproved);

                mockExternalPaymentProcessingService.VerifyRefundTransactionCalls(paymentTransaction, paymentProfile);

                mock.Mock <IExternalPaymentFactory>().Verify(x =>
                                                             x.GetPaymentService(It.Is <PaymentMethod>(p => p == paymentMethod)), Times.Once);
            }
        }