Example #1
0
        public void TransactionIsCreated_WhenUserWithdraws()
        {
            int     allTransactionsBefore = context.Transactions.CountAsync().Result;
            int     accountId             = 20;
            decimal withdrawalAmount      = 100;

            accountCommandHandler.Withdraw(accountId, withdrawalAmount);

            int allTransactionsAfter = context.Transactions.CountAsync().Result;

            Assert.AreEqual(allTransactionsAfter, allTransactionsBefore + 1);
        }
Example #2
0
        public void AccountBalanceDecreased_WhenUserWithdraws()
        {
            int accountId = 30;

            options = new DbContextOptionsBuilder <BankAppDataContext>()
                      .UseInMemoryDatabase(databaseName: "TestingDb")
                      .Options;
            using (var context = new BankAppDataContext(options))
            {
                accountQueriesHandler = new AccountQueriesHandler(context);
                accountCommandHandler = new AccountCommandHandler(context);

                context.Accounts.Add(new Account {
                    AccountId = accountId, Balance = 2000
                });
                context.SaveChanges();
            }

            using (var context = new BankAppDataContext(options))
            {
                accountQueriesHandler = new AccountQueriesHandler(context);
                accountCommandHandler = new AccountCommandHandler(context);

                decimal balanceBefore    = accountQueriesHandler.GetAccount(accountId).Balance;
                decimal withdrawalAmount = 1000;

                accountCommandHandler.Withdraw(accountId, withdrawalAmount);

                decimal balanceAfter = accountQueriesHandler.GetAccount(accountId).Balance;

                Assert.Less(balanceAfter, balanceBefore);
            }
        }
Example #3
0
        public IActionResult Withdraw(int accountId, decimal amount)
        {
            if (ModelState.IsValid)
            {
                int result = accountHandler.Withdraw(accountId, amount);

                if (result == 1)
                {
                    TempData["success"] = "Withdrawal executed successfully.";

                    return(View());
                }
            }

            TempData["error"] = "Withdrawal was unsuccessful. Please check that amount and account Id are correct.";

            return(View());
        }