public void Withdraw_WithValidAmount_AfterDeposit_UpdatesLastTransactionBalance() { //Arrange var user = new User { Username = "******", FirstName = "Demo", LastName = "User", Password = "******" }; new AuthService().Register(user); decimal depositAmount = 500; decimal withdrawAmount = 150; decimal expected = depositAmount - withdrawAmount; UserTransactionService transactionService = new UserTransactionService(); //act transactionService.Deposit(user.Id, depositAmount); transactionService.Withdraw(user.Id, withdrawAmount); //Assert var balance = transactionService.GetCurrentBalanceForUser(user.Id); Assert.AreEqual(expected, balance, "Wrong balance value"); }
public override void Run(bool clearScreen = true) { if (clearScreen) { Console.Clear(); } Console.WriteLine($"Withdrawal for {User.Username}"); Console.WriteLine($"Availabe for withdrawal: {UserTransactionService.GetCurrentBalanceForUser(User.Id):C}\n"); Console.Write("Enter amount to withdraw: "); var amount = UserInputHelper.GetDecimal(); Console.Write($"Withdraw {amount:C}. Are you sure? (y/n) : "); var confirm = Console.ReadLine(); if (confirm == "y" || confirm == "Y") { var res = UserTransactionService.Withdraw(User.Id, amount); if (res.Success) { Console.WriteLine("Withdrawal Success!"); } else { Console.WriteLine($"Withdrawal Failed. {res.Errors}"); } } else { Console.WriteLine("Withdrawal Cancelled!"); } ShowDoneOptions(); }