示例#1
0
        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();
        }
示例#3
0
        public override void Run(bool clearScreen = true)
        {
            if (User == null || !AuthService.IsAuthenticated(AuthKey))
            {
                Console.WriteLine("Could not validate user.");
                return;
            }

            Console.Clear();
            Console.WriteLine($"Welcome {User.Username}!\n");
            Console.WriteLine("1. Check Balance");
            Console.WriteLine("2. Deposit");
            Console.WriteLine("3. Withdrawl");
            Console.WriteLine("4. Transaction History");
            Console.WriteLine("5. Logout");

            Console.Write("\nPlease enter your choice: ");
            if (Int32.TryParse(Console.ReadLine(), out int input))
            {
                switch (input)
                {
                case 1:
                {
                    var currBal = UserTransactionService.GetCurrentBalanceForUser(User.Id);
                    Console.WriteLine($"Your Current Balance is {currBal:C}");
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadLine();
                    Run();
                    break;
                }

                case 2:
                {
                    new DepositScreen(User.Id, AuthKey).Run();
                    break;
                }

                case 3:
                {
                    new WithdrawalScreen(User.Id, AuthKey).Run();
                    break;
                }

                case 4:
                {
                    new TransactionHistoryScreen(User.Id, AuthKey).Run();
                    break;
                }

                case 5:
                {
                    AuthService.Logout(User.Id);
                    new HomeScreen().Run();
                    break;
                }

                default:
                {
                    ShowInvalidOptionError();
                    break;
                }
                }
            }
            else
            {
                ShowInvalidOptionError();
            }
        }