Exemplo n.º 1
0
        public void Consider_as_valid_paymentRequest()
        {
            var card              = new Infrastructure.Card("4564 4589 1052 4568", "05/22", "123");
            var paymentRequest    = new PaymentGateway.Infrastructure.PaymentRequest(Guid.NewGuid(), Guid.NewGuid(), amount: new Money("EUR", 42), card: card);
            var validationResults = paymentRequest.Validate(null);

            Check.That(validationResults).IsEmpty();
        }
Exemplo n.º 2
0
        public void Detect_malformatted_PaymentRequest(
            [Values("456A 4589 1052 4568", "4560 ???9 1052 4568", "45601199 1052 4568", "45601199 1052 4568 ")] string cardNumber,
            [Values("05/19", "13/12", "112", "aaa", "aa/ba")] string expiry,
            [Values("a45", "789456123")] string cvv,
            [Values("EU", "USDUSD")] string currency,
            [Values(-42, 0)] double value)
        {
            var card              = new Infrastructure.Card(cardNumber, expiry, cvv);
            var paymentRequest    = new PaymentGateway.Infrastructure.PaymentRequest(Guid.Empty, Guid.Empty, amount: new Money(currency, value), card: card);
            var validationResults = paymentRequest.Validate(null);

            Check.That(validationResults.Select(x => x.ErrorMessage))
            .IsOnlyMadeOf("Request id missing",
                          "Merchant id missing",
                          "Invalid card number",
                          "Invalid card CVV",
                          "Invalid card expiry",
                          "Amount should be greater than 0",
                          "Currency is absent or not correctly formatted");
        }
        public async Task Return_BadRequest_When_PaymenRequest_Contains_a_merchant_not_onboarded_yet()
        {
            var validCard = new Infrastructure.Card("1234 5623 5489 1004", "05/19", "123");
            var systemNotAwareOfThisMerchant = Guid.NewGuid();

            var invalidRequest = new PaymentRequest(Guid.NewGuid(), merchantId: systemNotAwareOfThisMerchant,
                                                    amount: new Money("USD", 42), card: validCard);

            var           gatewayPaymentId = Guid.NewGuid();
            IGenerateGuid guidGenerator    = new GuidGeneratorForTesting(gatewayPaymentId);

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

            var actionResult = await cqrs.RequestsController.ProceedPaymentRequest(invalidRequest, guidGenerator, cqrs.PaymentRequestsMemory, cqrs.PaymentProcessor);

            Check.That(actionResult).IsInstanceOf <BadRequestObjectResult>();
            var badRequest = (BadRequestObjectResult)actionResult;
            var failDetail = (ProblemDetails)badRequest.Value;

            Check.That(failDetail.Detail).IsEqualTo($"Merchant {systemNotAwareOfThisMerchant} has not been onboarded");

            Check.That(await cqrs.PaymentRequestsMemory.AlreadyHandled(new PaymentRequestId(invalidRequest.RequestId)))
            .IsFalse();
        }