Exemplo n.º 1
0
        public async Task <ActionResult <CreatePaymentResponseV1> > CreatePayment([FromBody] CreatePaymentRequestV1 newPaymentRequestBodyV1, CancellationToken cancellationToken)
        {
            var newPaymentDto = _mapper.Map <CompletedPaymentDto>(newPaymentRequestBodyV1);
            var paymentResult = await _paymentService.ProcessPaymentAsync(newPaymentDto, cancellationToken);

            var paymentResultResponse = _mapper.Map <CreatePaymentResponseV1>(paymentResult);

            return(CreatedAtRoute(nameof(GetPayment), new { paymentId = paymentResultResponse.PaymentId }, paymentResultResponse));
        }
        public async Task CallPaymentServiceWithNewPayment_GivenValidPaymentRequest_WhenCallingCreatePayment()
        {
            // Arrange
            var createPaymentRequest = new CreatePaymentRequestV1()
            {
                CardNumber   = "4658582263620043",
                ExpiryDate   = "0824",
                Amount       = 10m,
                CurrencyCode = "GBP",
                Ccv          = "001"
            };
            var expectedPaymentResponse = new CreatePaymentResponseV1()
            {
                PaymentId    = "AAAAAAAABBBBCCCCDDDDEEEEEEEEEEEE",
                IsSuccessful = true
            };

            // Act
            var actualResponse = await _sut.CreatePayment(createPaymentRequest, CancellationToken.None);

            // Assert
            actualResponse.Result.Should().BeOfType <CreatedAtRouteResult>();
            ((ObjectResult)actualResponse.Result).Value.Should().BeEquivalentTo(expectedPaymentResponse);
        }