public IActionResult MakeCardPayment([FromBody] CardPaymentCommand command) { var result = _paymentService.MakePayment(command); if (result != PaymentResult.Success) { return(BadRequest(result.GetStringValue())); } return(Ok(result.GetStringValue())); }
public void MakePayment_CardNotFound() { var command = new CardPaymentCommand { CardId = card1.Id, Amount = 10 }; var result = _paymentService.MakePayment(command); Assert.AreEqual(result, PaymentResult.CardNotFound); }
public void MakePayment_NotEnoughMoney() { var command = new CardPaymentCommand { CardId = card1.Id, Amount = 10 + bankAccount1.Money }; mockBankCardRepository.SetupSequence(m => m.Find(It.IsAny <Guid>())) .Returns(card1); mockBankAccountRepository.SetupSequence(m => m.Find(It.IsAny <Guid>())) .Returns(bankAccount1); var result = _paymentService.MakePayment(command); Assert.AreEqual(result, PaymentResult.NotEnoughMoney); }
public void MakePayment_Success() { var command = new CardPaymentCommand { CardId = card1.Id, Amount = 10 }; var bankAccount1Money = bankAccount1.Money; mockBankCardRepository.SetupSequence(m => m.Find(It.IsAny <Guid>())) .Returns(card1); mockBankAccountRepository.SetupSequence(m => m.Find(It.IsAny <Guid>())) .Returns(bankAccount1); var result = _paymentService.MakePayment(command); Assert.AreEqual(result, PaymentResult.Success); Assert.AreEqual(bankAccount1.Money, bankAccount1Money - command.Amount); }
public PaymentResult MakePayment(CardPaymentCommand command) { EnsureIsValid(command); var card = UnitOfWork.BankCardRepository.Find(command.CardId); if (card == null) { return(PaymentResult.CardNotFound); } var bankAccount = UnitOfWork.BankAccountRepository.Find(card.BankAccountId); if (bankAccount.Money - command.Amount < 0) { return(PaymentResult.NotEnoughMoney); } bankAccount.Money -= command.Amount; return(PaymentResult.Success); }