Esempio n. 1
0
        public async Task Returns_422_status_code_when_authorise_failed()
        {
            var authoriseResponse = _fixture
                                    .Build <AuthoriseResponse>()
                                    .With(x => x.Status, PaymentStatus.Failed)
                                    .Create();

            _mapperMock.Setup(x => x.Map <ProcessorResponse, AuthoriseResponse>(It.IsAny <ProcessorResponse>()))
            .Returns(authoriseResponse);

            var response = (UnprocessableEntityObjectResult)await _paymentController.Authorise(new AuthoriseRequest());

            Assert.That(response.StatusCode, Is.EqualTo((int)HttpStatusCode.UnprocessableEntity));
            Assert.That(response.Value, Is.EqualTo(authoriseResponse));
            _paymentProcessorMock.VerifyAll();
            _mapperMock.VerifyAll();
        }
Esempio n. 2
0
        public async Task When_authorise_payment_called_with_valid_request_then_authorisation_is_requested_with_same_payment_details()
        {
            var stubPaymentAuthoriser = new RecordingPaymentAuthoriserStub();
            var sut            = new PaymentController(new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance), stubPaymentAuthoriser, SystemClock.Instance, NullLogger <PaymentController> .Instance);
            var paymentRequest = _generatePaymentRequest();

            _ = await sut.Authorise(paymentRequest);

            Assert.Equal(paymentRequest.Amount, stubPaymentAuthoriser.LastRequest.Amount);
        }
Esempio n. 3
0
        public async Task Given_authorise_payment_called_with_valid_request_when_authorisation_fails_then_returns_denied_payment()
        {
            var sut            = new PaymentController(new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance), new AlwaysThrowsPaymentAuthoriser(), SystemClock.Instance, NullLogger <PaymentController> .Instance);
            var paymentRequest = _generatePaymentRequest();

            var result = await sut.Authorise(paymentRequest);

            var createdPayment = ExpectSuccessResponseWithCreatedPayment(result);

            Assert.Equal(PaymentResult.Failed, createdPayment.Result);
        }
Esempio n. 4
0
        public async Task When_authorise_payment_called_with_valid_request_then_request_succeeds_and_returns_created_payment_with_masked_card_details()
        {
            var sut            = new PaymentController(new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance), new AlwaysApprovesPaymentAuthoriser(), SystemClock.Instance, NullLogger <PaymentController> .Instance);
            var paymentRequest = _generatePaymentRequest();

            var result = await sut.Authorise(paymentRequest);

            var createdPayment = ExpectSuccessResponseWithCreatedPayment(result);

            Assert.Equal(paymentRequest.Card.Pan.MaskedValue, createdPayment.Card.MaskedPan);
            Assert.Equal(paymentRequest.Card.ExpiryMonth, createdPayment.Card.ExpiryMonth);
        }
Esempio n. 5
0
        public async Task When_authorise_payment_called_with_invalid_request_then_request_fails_with_bad_request()
        {
            var sut            = new PaymentController(new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance), new AlwaysApprovesPaymentAuthoriser(), SystemClock.Instance, NullLogger <PaymentController> .Instance);
            var paymentRequest = _generatePaymentRequest();

            sut.ModelState.AddModelError("Amount", "Required");

            var result = await sut.Authorise(paymentRequest);

            var actionResult = Assert.IsType <ActionResult <PaymentResponse> >(result);

            _ = Assert.IsType <BadRequestObjectResult>(actionResult.Result);
        }
Esempio n. 6
0
        public async Task When_authorise_payment_called_with_valid_request_then_payment_is_stored_with_creation_time()
        {
            var paymentsRepo          = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);
            var expectedCreatedAtTime = SystemClock.Instance.GetCurrentInstant().Minus(Duration.FromDays(5));
            var clockStub             = new ConstantTimeClockStub(expectedCreatedAtTime);
            var sut            = new PaymentController(paymentsRepo, new AlwaysApprovesPaymentAuthoriser(), clockStub, NullLogger <PaymentController> .Instance);
            var paymentRequest = _generatePaymentRequest();

            var result = await sut.Authorise(paymentRequest);

            var createdPayment = ExpectSuccessResponseWithCreatedPayment(result);
            var storedPayment  = await paymentsRepo.Get(createdPayment.Id, PaymentController.DefaultMerchant.Id);

            Assert.Equal(expectedCreatedAtTime, storedPayment.CreatedAt);
        }