public async Task Handle_CorrectId_MerchantIdMismatch_Returns404()
        {
            //arrange
            var errorResponse = ApiResponse <GetPaymentByIdResponse> .Fail(StatusCodes.Status404NotFound,
                                                                           "NOT_FOUND",
                                                                           "Payment record not found");

            var paymentRecord = _fixture.Create <PaymentRecord>();

            var paymentRecords = new List <PaymentRecord>
            {
                paymentRecord
            };

            _paymentRecordReader
            .Setup(x => x.PaymentRecords)
            .Returns(paymentRecords.AsQueryable);

            var request = new GetPaymentByIdRequest
            {
                Id = paymentRecord.Id
            };

            //act
            var res = await _getPaymentByIdHandler.Handle(request);

            //assert
            res.Should().BeEquivalentTo(errorResponse);
        }
示例#2
0
        public async Task <IActionResult> GetPayment([FromQuery] GetPaymentByIdRequest request)
        {
            var query = _mapper.Map <GetPaymentByIdQuery>(request);

            Result <Payment> payment = await _mediator.Send(query);

            if (!payment.IsSuccess)
            {
                return(NotFound());
            }

            var result = _mapper.Map <GetPaymentByIdResponse>(payment.Value);

            return(Ok(result));
        }
        public async Task Handle_CorrectId_CorrectId_ReturnsSuccessfulResult()
        {
            //arrange
            var paymentRecord = _fixture.Create <PaymentRecord>();

            var paymentRecords = new List <PaymentRecord>
            {
                paymentRecord
            };

            _paymentRecordReader
            .Setup(x => x.PaymentRecords)
            .Returns(paymentRecords.AsQueryable);

            _merchantContext
            .Setup(x => x.GetMerchantId())
            .Returns(paymentRecord.MerchantId);

            var request = new GetPaymentByIdRequest
            {
                Id = paymentRecord.Id
            };

            var decryptedCvv        = _fixture.Create <string>();
            var decryptedCardNumber = _fixture.Create <string>();
            var decryptedCardExpiry = _fixture.Create <string>();

            var decryptedSortCode      = _fixture.Create <string>();
            var decryptedAccountNumber = _fixture.Create <string>();

            _decrypter
            .Setup(x => x.DecryptUtf8(paymentRecord.Source.CvvEncrypted, It.IsAny <byte[]>()))
            .Returns(decryptedCvv);

            _decrypter
            .Setup(x => x.DecryptUtf8(paymentRecord.Source.CardNumberEncrypted, It.IsAny <byte[]>()))
            .Returns(decryptedCardNumber);

            _decrypter
            .Setup(x => x.DecryptUtf8(paymentRecord.Source.CardExpiryEncrypted, It.IsAny <byte[]>()))
            .Returns(decryptedCardExpiry);

            _decrypter
            .Setup(x => x.DecryptUtf8(paymentRecord.Recipient.AccountNumberEncrypted, It.IsAny <byte[]>()))
            .Returns(decryptedAccountNumber);

            _decrypter
            .Setup(x => x.DecryptUtf8(paymentRecord.Recipient.SortCodeEncrypted, It.IsAny <byte[]>()))
            .Returns(decryptedSortCode);

            var expected = new GetPaymentByIdResponse
            {
                Id     = paymentRecord.Id,
                Source = new GetPaymentByIdResponse.PaymentSource
                {
                    Cvv        = decryptedCvv.Mask(3),
                    CardExpiry = decryptedCardExpiry,
                    CardNumber = decryptedCardNumber.Mask(12),
                },
                Recipient = new GetPaymentByIdResponse.PaymentRecipient
                {
                    SortCode      = decryptedSortCode.Mask(4),
                    AccountNumber = decryptedAccountNumber.Mask(6, 0)
                },
                Details = string.IsNullOrEmpty(paymentRecord.FailureReason)
                    ? null
                    : new GetPaymentByIdResponse.BankResponse
                {
                    FailureReason = paymentRecord.FailureReason
                },
                Amount    = paymentRecord.Amount,
                Status    = paymentRecord.Status,
                CreatedAt = paymentRecord.CreatedAt,
                Currency  = paymentRecord.Currency,
            };

            //act
            var res = await _getPaymentByIdHandler.Handle(request);

            //assert
            res.SuccessResponse.Should().BeEquivalentTo(expected);
            res.StatusCode.Should().Be(StatusCodes.Status200OK);
        }