コード例 #1
0
        public void Execute()
        {
            AccountManager accountManager = AccountManagerFactory.Create();

            Console.Clear();
            Console.WriteLine("Withdraw from Account");
            Console.WriteLine("----------------------------------");

            Console.Write("Enter an account number: ");
            string accountNumber = Console.ReadLine();

            Console.Write("Enter a negative withdrawl amount: ");

            decimal.TryParse(Console.ReadLine(), out decimal amount);

            AccountWithdrawlResponse response = accountManager.Withdrawl(accountNumber, amount);

            if (response.Success)
            {
                Console.WriteLine("Withdrawl completed");
                Console.WriteLine($"Account number: {response.Account.AccountNumber}");
                Console.WriteLine($"Old balance: {response.OldBalance:c}");
                Console.WriteLine($"Amount Withdrawn: {response.Amount:c}");
                Console.WriteLine($"New balance: {response.Account.Balance:C}");
            }
            else
            {
                Console.WriteLine("An error occured");
                Console.WriteLine(response.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
コード例 #2
0
        public AccountWithdrawlResponse Withdrawl(Account account, decimal amount)
        {
            AccountWithdrawlResponse response = new AccountWithdrawlResponse();

            if (account.Type != AccountType.Premium)
            {
                response.Success = false;
                response.Message = "Error: non-Premium account hit a Premium Account Rule. Contact IT";
                return(response);
            }

            if (amount >= 0)
            {
                response.Success = false;
                response.Message = "Entry must be a negative number";
                return(response);
            }

            if (amount + account.Balance < -500)
            {
                response.Success = false;
                response.Message = "This is more than $500 overdraft limit.";
                return(response);
            }

            response.Success    = true;
            response.OldBalance = account.Balance;
            response.Account    = account;
            response.Amount     = amount;
            account.Balance    += amount;

            return(response);
        }
コード例 #3
0
ファイル: AccountManager.cs プロジェクト: juxith/SGBank
        public AccountWithdrawlResponse Withdrawl(string accountNumber, decimal amount)
        {
            AccountWithdrawlResponse response = new AccountWithdrawlResponse();

            response.Account = _accountRepository.LoadAccount(accountNumber);

            if (response.Account == null)
            {
                response.Success = false;
                response.Message = $"{accountNumber} is not a valid account.";
                return(response);
            }
            else
            {
                response.Success = true;
            }

            IWithdrawl withdrawlRule = WithdrawlRulesFactory.Create(response.Account.Type);

            response = withdrawlRule.Withdrawl(response.Account, amount);

            if (response.Success)
            {
                _accountRepository.SaveAccount(response.Account);
            }
            return(response);
        }
コード例 #4
0
ファイル: FreeAccountTest.cs プロジェクト: juxith/SGBank
        public void FreeAccountWithdrawlRuleTest(string accountNumber, string name, decimal balance,
                                                 AccountType accountType, decimal amount, decimal newBalance, bool expectedResult)
        {
            IWithdrawl test = new FreeAccountWithdrawlRules();

            Account newAcct = new Account();

            newAcct.AccountNumber = accountNumber;
            newAcct.Name          = name;
            newAcct.Balance       = balance;
            newAcct.Type          = accountType;

            AccountWithdrawlResponse response = test.Withdrawl(newAcct, amount);

            Assert.AreEqual(response.Success, expectedResult);
            Assert.AreEqual(newAcct.Balance, newBalance);
        }
コード例 #5
0
ファイル: PremiumAccountTest.cs プロジェクト: juxith/SGBank
        [TestCase("33333", "Premium Account", 1000, AccountType.Premium, -100, 900, true)] //Success
        public void PremiumAccountWithdrawRulesTest(string accountNumber, string name, decimal balance,
                                                    AccountType type, decimal amount, decimal newBalance, bool expectedResult)
        {
            IWithdrawl withdraw = new PremiumAccountWithdrawRules();

            Account account = new Account();

            account.AccountNumber = accountNumber;
            account.Name          = name;
            account.Balance       = balance;
            account.Type          = type;

            AccountWithdrawlResponse response = withdraw.Withdrawl(account, amount);

            Assert.AreEqual(response.Success, expectedResult);
            Assert.AreEqual(account.Balance, newBalance);
        }
コード例 #6
0
        public AccountWithdrawlResponse Withdrawl(Account account, decimal amount)
        {
            AccountWithdrawlResponse response = new AccountWithdrawlResponse();

            if (account.Type != AccountType.Basic)
            {
                response.Success = false;
                response.Message = "Error: a non-basic account hit the Basic WithDraw Rule. Contact IT";
                return(response);
            }

            if (amount >= 0)
            {
                response.Success = false;
                response.Message = "Entry must be a negative number";
                return(response);
            }

            if (amount < -500)
            {
                response.Success = false;
                response.Message = "Basic accounts cannot withdraw more than $500.";
                return(response);
            }

            if (account.Balance + amount < -100)
            {
                response.Success = false;
                response.Message = "This amount will overdraft more than your $100 limit.";
                return(response);
            }

            response.Success    = true;
            response.Account    = account;
            response.Amount     = amount;
            response.OldBalance = account.Balance;
            account.Balance    += amount;

            if (account.Balance < 0)
            {
                account.Balance -= 10;
            }

            return(response);
        }
コード例 #7
0
        public AccountWithdrawlResponse Withdrawl(Account account, decimal amount)
        {
            AccountWithdrawlResponse response = new AccountWithdrawlResponse();

            if (account.Type != AccountType.Free)
            {
                response.Success = false;
                response.Message = "Error: a non free account hit the Free Withdrawl Rule. Contact IT";
                return(response);
            }

            if (amount >= 0)
            {
                response.Success = false;
                response.Message = "Entry must be a negative number";
                return(response);
            }

            if (amount + account.Balance < 0)
            {
                response.Success = false;
                response.Message = $"Insufficient funds for withdrawl. Balance is {account.Balance}";
                return(response);
            }

            if (amount < -100)
            {
                response.Success = false;
                response.Message = "Free accounts cannot withdrawl more than $100 at a time.";
                return(response);
            }

            response.OldBalance = account.Balance;
            account.Balance    += amount;
            response.Account    = account;
            response.Amount     = amount;
            response.Success    = true;

            return(response);
        }