Exemplo n.º 1
0
        public async Task Handle_BankResponseSuccessful_SendsProcessSuccessfulPaymentRequest()
        {
            //arrange
            var merchantId = _fixture.Create <string>();

            _merchantContext.Setup(x => x.GetMerchantId()).Returns(merchantId);

            var successfulTransferResponse = _fixture.Create <TransferFundsSuccessfulResponse>();

            _mockBankApiClient
            .Setup(x => x.TransferFunds(It.IsAny <TransferFundsRequest>()))
            .ReturnsAsync(TransferFundsResponse.Successful(successfulTransferResponse));

            var request = _fixture.Create <CreatePaymentRequest>();

            var expected = new ProcessSuccessfulPaymentRequest
            {
                Source = new ProcessSuccessfulPaymentRequest.PaymentSource
                {
                    Cvv        = request.Source.Cvv,
                    CardExpiry = request.Source.CardExpiry,
                    CardNumber = request.Source.CardNumber,
                },
                Recipient = new ProcessSuccessfulPaymentRequest.PaymentRecipient
                {
                    SortCode      = request.Recipient.SortCode,
                    AccountNumber = request.Recipient.AccountNumber
                },
                Currency = request.Currency,
                Amount   = request.Amount,
                Merchant = new ProcessSuccessfulPaymentRequest.MerchantDetails
                {
                    Id = merchantId,
                },
                BankResponse = new ProcessSuccessfulPaymentRequest.BankPaymentResponse
                {
                    TransactionId = successfulTransferResponse.Id.ToString()
                }
            };

            //act
            await _createPaymentHandler.Handle(request);

            //assert
            _mediator.Verify(x => x.Send(It.Is <ProcessSuccessfulPaymentRequest>(req => req.Should().BeEquivalentToBool(expected)), It.IsAny <CancellationToken>()), Times.Once);
        }
Exemplo n.º 2
0
        private void SetupMockDefaults()
        {
            _mediator
            .Setup(x => x.Send(It.IsAny <ProcessSuccessfulPaymentRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_fixture.Create <ProcessSuccessfulPaymentResponse>());

            _mediator
            .Setup(x => x.Send(It.IsAny <ProcessRejectedPaymentRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(_fixture.Create <ProcessRejectedPaymentResponse>());

            _merchantContext
            .Setup(x => x.GetMerchantId())
            .Returns(_fixture.Create <string>());

            _mockBankApiClient
            .Setup(x => x.TransferFunds(It.IsAny <TransferFundsRequest>()))
            .ReturnsAsync(TransferFundsResponse.Successful(_fixture.Create <TransferFundsSuccessfulResponse>()));
        }
Exemplo n.º 3
0
        public async Task Handle_BankResponseSuccessful_ReturnsExpectedSuccessResponse()
        {
            //arrange
            var processSuccessfulPaymentResponse = _fixture.Create <ProcessSuccessfulPaymentResponse>();

            _mediator
            .Setup(x => x.Send(It.IsAny <ProcessSuccessfulPaymentRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(processSuccessfulPaymentResponse);

            _mockBankApiClient
            .Setup(x => x.TransferFunds(It.IsAny <TransferFundsRequest>()))
            .ReturnsAsync(TransferFundsResponse.Successful(_fixture.Create <TransferFundsSuccessfulResponse>()));

            //act
            var res = await _createPaymentHandler.Handle(_fixture.Create <CreatePaymentRequest>());

            //assert
            res.StatusCode.Should().Be(StatusCodes.Status201Created);
            res.SuccessResponse.Status.Should().Be(PaymentStatus.Succeeded);
            res.SuccessResponse.PaymentId.Should().Be(processSuccessfulPaymentResponse.Id);
        }
        private async Task <TransferFundsResponse> TransferFundsResponseInternal(TransferFundsRequest request)
        {
            var response = await _httpClient.PostAsync(
                "api/payment",
                new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"));

            var responseBody = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                if (response.StatusCode == (HttpStatusCode)HttpStatusCodeUnprocessableEntity)
                {
                    return(TransferFundsResponse.Error((int)response.StatusCode, JsonConvert.DeserializeObject <TransferFundsErrorResponse>(responseBody)));
                }
                else
                {
                    return(TransferFundsResponse.UnknownError((int)response.StatusCode));
                }
            }

            var deserialized = JsonConvert.DeserializeObject <TransferFundsSuccessfulResponse>(responseBody);

            return(TransferFundsResponse.Successful(deserialized));
        }