public async Task Unit_CreateNewPayment_ExpectPaymentInResult() { Account newAccount = new Account { Name = "Test Account" }; _context.Accounts.Add(newAccount); _context.SaveChanges(); Transaction deposit = new Transaction { AccountId = newAccount.Id, Amount = 1000000, Date = new DateTime(2020, 1, 1), TransactionStatus = TransactionStatusEnum.Processed, TransactionType = TransactionTypeEnum.Deposit, CreationDate = new DateTime(2020, 1, 1), LastUpdateDate = new DateTime(2020, 1, 1) }; _context.Transactions.Add(deposit); _context.SaveChanges(); TransactionCreatorService creator = new TransactionCreatorService(_mockPaymentLogger.Object, _mapper, newAccount.Id, 10000, new DateTime(2020, 1, 1), _accountRepo, _transRepo, TransactionStatusEnum.Pending, TransactionTypeEnum.Withdrawal, Messages.Payment_FailedToCreate); ServiceResult result = await creator.CreateTransaction(); result.Should().NotBeNull(); result.StatusCode.Should().Be(StatusCodes.Status201Created); TransactionResultDto transaction = JsonConvert.DeserializeObject <TransactionResultDto>(result.ContentResult); transaction.Should().NotBeNull(); transaction.AccountId.Should().Be(newAccount.Id); transaction.Amount.Should().Be(10000); transaction.Date.Should().Be(new DateTime(2020, 1, 1)); transaction.TransactionStatus.Should().Be(TransactionStatusEnum.Pending.ToString()); }
public async Task Integration_CreateNewPayment_ExpectPaymentInResultAndRepository() { Account newAccount = new Account { Name = "Test Account" }; _context.Accounts.Add(newAccount); _context.SaveChanges(); // 10 Deposits of 1000 for (int i = 0; i < 10; i++) { _context.Transactions.Add(new Transaction { AccountId = newAccount.Id, Amount = 1000, TransactionStatus = TransactionStatusEnum.Processed, TransactionType = TransactionTypeEnum.Deposit, Date = new DateTime(2020, 1, 1), CreationDate = new DateTime(2020, 1, 1), LastUpdateDate = new DateTime(2020, 1, 1) }); } _context.SaveChanges(); TransactionInsertDto payment = new TransactionInsertDto { AccountId = newAccount.Id, Amount = 1000, Date = new DateTime(2020, 1, 1) }; var content = JsonConvert.SerializeObject(payment); var stringContent = new StringContent(content, Encoding.UTF8, "application/json"); var response = await _client.PostAsync("/api/payment/create", stringContent); response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created); var responseString = await response.Content.ReadAsStringAsync(); TransactionResultDto PaymentResult = JsonConvert.DeserializeObject <TransactionResultDto>(responseString); PaymentResult.Should().NotBeNull(); PaymentResult.AccountId.Should().Be(newAccount.Id); PaymentResult.Amount.Should().Be(payment.Amount); PaymentResult.Date.Should().Be((DateTime)payment.Date); PaymentResult.ClosedReason.Should().BeNull(); PaymentResult.TransactionStatus.Should().Be(TransactionStatusEnum.Pending.ToString()); Transaction PaymentFromDb = _context.Transactions.Find(PaymentResult.Id); PaymentFromDb.Should().NotBeNull(); PaymentFromDb.Amount.Should().Be(payment.Amount); PaymentFromDb.Date.Should().Be((DateTime)payment.Date); PaymentFromDb.Id.Should().Be(PaymentResult.Id); PaymentFromDb.TransactionStatus.Should().Be(TransactionStatusEnum.Pending); PaymentFromDb.TransactionType.Should().Be(TransactionTypeEnum.Withdrawal); }
public async Task Integration_CreateNewPayment_NoBalance_ExpectCreated_ButTransactionCreatedAndClosed() { Account newAccount = new Account { Name = "Test Account" }; _context.Accounts.Add(newAccount); _context.SaveChanges(); TransactionInsertDto payment = new TransactionInsertDto { AccountId = newAccount.Id, Date = new DateTime(2020, 1, 1), Amount = 1000 }; var content = JsonConvert.SerializeObject(payment); var stringContent = new StringContent(content, Encoding.UTF8, "application/json"); var response = await _client.PostAsync("/api/payment/create", stringContent); response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created); var responseString = await response.Content.ReadAsStringAsync(); TransactionResultDto PaymentResult = JsonConvert.DeserializeObject <TransactionResultDto>(responseString); PaymentResult.Should().NotBeNull(); PaymentResult.AccountId.Should().Be(newAccount.Id); PaymentResult.Amount.Should().Be(payment.Amount); PaymentResult.Date.Should().Be((DateTime)payment.Date); PaymentResult.ClosedReason.Should().Be(Messages.Payment_NotEnoughFundsReason); PaymentResult.TransactionStatus.Should().Be(TransactionStatusEnum.Closed.ToString()); Transaction PaymentFromDb = _context.Transactions.Find(PaymentResult.Id); PaymentFromDb.Should().NotBeNull(); PaymentFromDb.Amount.Should().Be(payment.Amount); PaymentFromDb.Date.Should().Be((DateTime)payment.Date); PaymentFromDb.Id.Should().Be(PaymentResult.Id); PaymentFromDb.TransactionStatus.Should().Be(TransactionStatusEnum.Closed); PaymentFromDb.TransactionType.Should().Be(TransactionTypeEnum.Withdrawal); PaymentFromDb.ClosedReason.Should().Be(Messages.Payment_NotEnoughFundsReason); }
public async Task Integration_CreateNewDeposit_ExpectAccountInResultAndRepository() { Account newAccount = new Account { Name = "Test Account" }; _context.Accounts.Add(newAccount); _context.SaveChanges(); TransactionInsertDto deposit = new TransactionInsertDto { AccountId = newAccount.Id, Amount = 1000, Date = new DateTime(2020, 1, 1) }; var content = JsonConvert.SerializeObject(deposit); var stringContent = new StringContent(content, Encoding.UTF8, "application/json"); var response = await _client.PostAsync("/api/deposit/create", stringContent); response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created); var responseString = await response.Content.ReadAsStringAsync(); TransactionResultDto depositResult = JsonConvert.DeserializeObject <TransactionResultDto>(responseString); depositResult.Should().NotBeNull(); depositResult.AccountId.Should().Be(newAccount.Id); Transaction depositFromDb = _context.Transactions.Find(depositResult.Id); depositFromDb.Should().NotBeNull(); depositFromDb.Amount.Should().Be(deposit.Amount); depositFromDb.Date.Should().Be((DateTime)deposit.Date); depositFromDb.Id.Should().Be(depositResult.Id); depositFromDb.TransactionStatus.Should().Be(TransactionStatusEnum.Processed); depositFromDb.TransactionType.Should().Be(TransactionTypeEnum.Deposit); }
public async Task <IActionResult> Transaction([FromBody] CreditTransactionDto creditTransactionDto) { Maybe <Player> playerFromRepository = _playerRepository.GetByIdentifier(creditTransactionDto.PlayerIdentifier); if (playerFromRepository.HasNoValue) { return(BadRequest("Player does not exists")); } Result <Money> money = Money.Create(creditTransactionDto.Amount); if (money.IsFailure) { return(BadRequest(money.Error)); } Result <TransactionAttempt> transaction = await _transactionExecutor.ExecuteTransaction(creditTransactionDto.TransactionIdentifier, playerFromRepository.Value, money.Value, _transactionTypeConverter.Convert(creditTransactionDto.Type)); if (transaction.IsFailure) { return(BadRequest(transaction.Error)); } CreditTransactionResult transactionResult = _transactionTypeConverter.Convert(transaction.Value.TransactionState); TransactionResultDto result = new TransactionResultDto { Identifier = transaction.Value.Identifier, Result = transactionResult }; return(Ok(result)); }