コード例 #1
0
        public async Task Return_InternalServerEror_When_AcquiringBank_sent_duplicated_PaymentId(BankPaymentStatus bankPaymentStatus, PaymentStatus expectedPaymentStatusReturnedByGateway)
        {
            var requestId            = Guid.Parse("9cb25b95-45ba-4100-a180-deb13259d0e1");
            var paymentRequest       = TestsUtils.BuildPaymentRequest(requestId, MerchantsRepository.Amazon);
            var secondRequestId      = Guid.Parse("9c940897-b1c4-4598-96a7-82502ca51845");
            var secondPaymentRequest = TestsUtils.BuildPaymentRequest(secondRequestId, MerchantsRepository.Apple);

            var           gatewayPaymentId          = Guid.Parse("002ee45f-fdfb-4666-b504-70aa26ecf646");
            var           secondGatewayPaymentId    = Guid.Parse("4cc3dd04-b3d8-4be4-8c68-e744c387fb6c");
            IGenerateGuid gatewayPaymentIdGenerator = Substitute.For <IGenerateGuid>();

            gatewayPaymentIdGenerator.Generate().Returns(gatewayPaymentId, secondGatewayPaymentId);

            var bankPaymentId = Guid.Parse("3ec8c76c-7dc2-4769-96f8-7e0649ecdfc0");
            var cqrs          = await PaymentCQRS.Build(bankPaymentStatus, new BankPaymentIdGeneratorForTests(bankPaymentId), new AlwaysSuccessBankConnectionBehavior(), new DelayProviderForTesting(TimeSpan.FromMilliseconds(1)), PaymentCQRS.TimeoutProviderForBankResponseWaiting(TimeSpan.FromMilliseconds(200)), Substitute.For <IKnowBufferAndReprocessPaymentRequest>(), Substitute.For <IAmCircuitBreakers>());

            await cqrs.RequestsController.ProceedPaymentRequest(paymentRequest, gatewayPaymentIdGenerator, cqrs.PaymentRequestsMemory, cqrs.PaymentProcessor);

            await cqrs.RequestsController.ProceedPaymentRequest(secondPaymentRequest, gatewayPaymentIdGenerator, cqrs.PaymentRequestsMemory, cqrs.PaymentProcessor);

            var secondFailedPayment = (await cqrs.PaymentReadController.GetPaymentInfo(secondGatewayPaymentId)).Value;

            Check.That(secondFailedPayment.RequestId).IsEqualTo(secondRequestId);
            Check.That(secondFailedPayment.GatewayPaymentId).IsEqualTo(secondGatewayPaymentId);

            Check.That(secondFailedPayment.Status).IsEqualTo(expectedPaymentStatusReturnedByGateway);
            Check.That(secondFailedPayment.Approved).IsEqualTo(secondFailedPayment.Status == PaymentGateway.Domain.PaymentStatus.Success);
            Check.That(secondFailedPayment.AcquiringBankPaymentId).IsNull();
        }
コード例 #2
0
        public async Task Return_proper_payment_status_When_Connect_to_bank_fails_twice_then_connected_AND_AcquiringBank_accepts_or_reject_payment(BankPaymentStatus bankPaymentStatus, PaymentStatus expectedPaymentStatusReturnedByGateway)
        {
            var           requestId        = Guid.NewGuid();
            var           paymentRequest   = TestsUtils.BuildPaymentRequest(requestId, MerchantsRepository.Amazon);
            var           gatewayPaymentId = Guid.NewGuid();
            IGenerateGuid guidGenerator    = new GuidGeneratorForTesting(gatewayPaymentId);

            var bankPaymentId = Guid.Parse("3ec8c76c-7dc2-4769-96f8-7e0649ecdfc0");
            var cqrs          = await PaymentCQRS.Build(bankPaymentStatus, new BankPaymentIdGeneratorForTests(bankPaymentId), new FailTwiceBankThenSuccessConnectionBehavior(), new DelayProviderForTesting(TimeSpan.FromMilliseconds(1)), PaymentCQRS.TimeoutProviderForBankResponseWaiting(TimeSpan.FromMilliseconds(200)), Substitute.For <IKnowBufferAndReprocessPaymentRequest>(), Substitute.For <IAmCircuitBreakers>());

            await cqrs.RequestsController.ProceedPaymentRequest(paymentRequest, guidGenerator, cqrs.PaymentRequestsMemory, cqrs.PaymentProcessor);


            var payment = (await cqrs.PaymentReadController.GetPaymentInfo(gatewayPaymentId)).Value;

            Check.That(payment.RequestId).IsEqualTo(requestId);
            Check.That(payment.GatewayPaymentId).IsEqualTo(gatewayPaymentId);

            Check.That(payment.Status).IsEqualTo(expectedPaymentStatusReturnedByGateway);
            Check.That(payment.Approved).IsEqualTo(payment.Status == PaymentGateway.Domain.PaymentStatus.Success);
            Check.That(payment.AcquiringBankPaymentId).IsEqualTo(bankPaymentId);
        }