public async Task GivenPaymentFail_WhenProcessPaymentIsCalled_ThenBadRequestIsReturnedWithError() { var request = new ProcessPaymentRequest(); var requestPaymentCommand = new RequestPaymentCommand(); var requestPaymentCommandResult = new Result(); var resultCode = "Error"; var resultDescription = "Error desciription"; var transactionId = Guid.NewGuid(); var getPaymentByMerchantTransactionIdQueryResponse = new GetPaymentByMerchantTransactionIdQueryResponse() { IsSuccessfull = false, ResultCode = resultCode, ResultDescription = resultDescription, TransactionId = transactionId }; _mapper.Map <RequestPaymentCommand>(request).Returns(requestPaymentCommand); _mediator.Send(requestPaymentCommand).Returns(requestPaymentCommandResult); _mediator.Send(Arg.Any <GetPaymentByMerchantTransactionIdQuery>()) .Returns(new Result <GetPaymentByMerchantTransactionIdQueryResponse>() { Value = getPaymentByMerchantTransactionIdQueryResponse }); var response = await _controller.ProcessPayment(request); var ProcessPaymentResponse = ((BadRequestObjectResult)response).Value as ProcessPaymentResponse; ProcessPaymentResponse.Should().BeEquivalentTo(new ProcessPaymentResponse { ResultCode = resultCode, ResultDescription = resultDescription, TransactionId = transactionId }); }
public async Task <PerformMoneyTransferResponseDto> PerformPayment(PerformPaymentRequestDto dto) { try { var paymentId = Guid.NewGuid().ToString(); var command = new RequestPaymentCommand( paymentId, dto.creditCardId, dto.orderId, dto.Amount ); await _messageSession.Send(command).ConfigureAwait(false); return(new PerformMoneyTransferResponseDto { Response = "OK" }); } catch (Exception ex) { return(new PerformMoneyTransferResponseDto { Response = "ERROR: " + ex.Message + " -- " + ex.StackTrace }); } }
public async Task GivenValidationErrorsInPayment_WhenProcessPaymentIsCalled_BadRequestIsReturnedWithVAlidationErrors() { var request = new ProcessPaymentRequest(); var requestPaymentCommand = new RequestPaymentCommand(); var requestPaymentCommandResult = new Result { Errors = new List <string> { "Error1" } }; var getPaymentByMerchantTransactionIdQueryResponse = new GetPaymentByMerchantTransactionIdQueryResponse() { IsSuccessfull = true }; _mapper.Map <RequestPaymentCommand>(request).Returns(requestPaymentCommand); _mediator.Send(requestPaymentCommand).Returns(requestPaymentCommandResult); _mediator.Send(Arg.Any <GetPaymentByMerchantTransactionIdQuery>()) .Returns(new Result <GetPaymentByMerchantTransactionIdQueryResponse>() { Value = getPaymentByMerchantTransactionIdQueryResponse }); var response = await _controller.ProcessPayment(request); var ProcessPaymentResponse = ((BadRequestObjectResult)response).Value as ProcessPaymentResponse; ProcessPaymentResponse.Should().BeEquivalentTo(new ProcessPaymentResponse { ResultCode = "ValidationError", ResultDescription = "Error1", }); }
public async Task Apikey_is_populated_in_command() { var request = new ProcessPaymentRequest(); var requestPaymentCommand = new RequestPaymentCommand(); _mapper.Map <RequestPaymentCommand>(request).Returns(requestPaymentCommand); await _controller.ProcessPayment(request); requestPaymentCommand.ApiKey.Should().Be(_apiKey); }
public async Task GivenConcurrencyException_WhenExecuteIsCalled_ThenPaymentIsNotUpdated() { var apiKey = "new api key"; var merchantId = Guid.NewGuid(); var merchant = new Merchant { Id = merchantId }; var merchantTransactionId = "tranid"; var amount = 15.4m; var currency = "EUR"; var cardNumber = "1234"; var expiryMonth = 12; var expityYear = 2020; var cvv = "123"; var acquirerResultCode = "ok"; var acquirerResultDescription = "Result descroption"; var acquirerTransactionId = "transciontionId"; var requestPaymentCommand = new RequestPaymentCommand { MerchantTransactionId = merchantTransactionId, ApiKey = apiKey, Amount = amount, Currency = currency, CardNumber = cardNumber, ExpiryMonth = expiryMonth, ExpiryYear = expityYear, Cvv = cvv }; var acquirerSuccessResponse = new ProcessPaymentResponse { IsSuccess = true, ResultCode = acquirerResultCode, ResultDescription = acquirerResultDescription, TransactionId = acquirerTransactionId }; _merchantRepository.GetByApiKey(apiKey).Returns(merchant); _paymentrepository.AddPayment(Arg.Is <Payment>( p => p.MerchantId.Equals(merchantId) && p.Amount == amount && p.Currency == currency && p.CardDetails.CardNumber == cardNumber && p.CardDetails.ExpiryMonth == expiryMonth && p.CardDetails.ExpiryYear == expityYear && p.CardDetails.Cvv == cvv)) .Throws(new ArgumentException()); await _handler.Handle(requestPaymentCommand, new System.Threading.CancellationToken()); await _paymentrepository.Received(0).UpdatePayment(Arg.Any <Payment>()); await _acquiringBank.Received(0).ProcessPayment(Arg.Any <ProcessPaymentRequest>()); }
public async Task GivenInternalServerError_WhenProcessPaymentIsCalled_InternalServerErrorIsReturned() { var request = new ProcessPaymentRequest(); var requestPaymentCommand = new RequestPaymentCommand(); _mapper.Map <RequestPaymentCommand>(request).Returns(requestPaymentCommand); _mediator.Send(requestPaymentCommand).Throws(new Exception("any exception")); var response = await _controller.ProcessPayment(request); ((StatusCodeResult)response).StatusCode.Should().Be((int)HttpStatusCode.InternalServerError); }
public async Task <IActionResult> RequestPayment([FromBody] ODataActionParameters value) { if (!ModelState.IsValid || value == null) { return(new BadRequestObjectResult(ModelState)); } string orderId = value["orderId"].ToString(); RequestPaymentCommand command = Command <RequestPaymentCommand>(); bool result = await command.Process(CurrentContext, orderId); return(new ObjectResult(command)); }
public async Task GetPaymentDbReturnsAPaymentWithStatusPending() { //Arange var requestPayment = this.FakeValidRequestPayment(); var requestPaymentCode = Guid.NewGuid(); var bankResponse = this.FakeBankResponsePayment(requestPaymentCode, PaymentStatusTypes.Pending); // Act var command = new RequestPaymentCommand(requestPayment); this.paymentGatewayRepostiory.Setup(x => x.AddPaymentAsync(command.RequestPayment)).Returns(Task.FromResult(Guid.NewGuid())); this.paymentBankRepostiory.Setup(x => x.RequestPaymentAsync(command.RequestPayment)).Returns(Task.FromResult(bankResponse)); var handler = new RequestPaymentCommandHandler(this.paymentBankRepostiory.Object, this.paymentGatewayRepostiory.Object); var result = await handler.Handle(command, CancellationToken.None); // Assert Assert.Equal(PaymentStatusTypes.Pending, result.PaymentStatus); Assert.NotNull(result); }
public async Task GivenValidPayment_WhenProcessPaymentIsCalled_ThenSuccessResponseIsReturned() { var merchantTransactionId = "merchant trans"; var request = new ProcessPaymentRequest { MerchantTransactionId = merchantTransactionId }; var requestPaymentCommand = new RequestPaymentCommand(); var requestPaymentCommandResult = new Result(); var resultCode = "OK"; var resultDescription = "desciription"; var transactionId = Guid.NewGuid(); var getPaymentByMerchantTransactionIdQueryResponse = new GetPaymentByMerchantTransactionIdQueryResponse() { IsSuccessfull = true, ResultCode = resultCode, ResultDescription = resultDescription, TransactionId = transactionId }; _mapper.Map <RequestPaymentCommand>(request).Returns(requestPaymentCommand); _mediator.Send(requestPaymentCommand).Returns(requestPaymentCommandResult); _mediator.Send(Arg.Is <GetPaymentByMerchantTransactionIdQuery>(t => t.MerchantTransactionId.Equals(merchantTransactionId) && t.ApiKey.Equals(_apiKey))) .Returns(new Result <GetPaymentByMerchantTransactionIdQueryResponse>() { Value = getPaymentByMerchantTransactionIdQueryResponse }); var response = await _controller.ProcessPayment(request); var ProcessPaymentResponse = ((CreatedResult)response).Value as ProcessPaymentResponse; ProcessPaymentResponse.Should().BeEquivalentTo(new ProcessPaymentResponse { ResultCode = resultCode, ResultDescription = resultDescription, TransactionId = transactionId }); }