Exemplo n.º 1
0
        static void Main(string[] args)
        {
            BankAccountStorage storage = new BankAccountStorage("BankAccountStorage.bin");

            BankAccountService service = new BankAccountService();

            BankAccount account1 = new BankAccount("454545nn45", "Ivan", "Petrov", 596.30m, 0.15, BancAccountType.Gold);
            BankAccount account2 = new BankAccount("56dj8533d2", "Sergei", "Sidorov", 0m, 0, BancAccountType.Base);
            BankAccount account3 = new BankAccount("45jnd45snn", "Elena", "Ivanova", 100m, 1, BancAccountType.Platinum);

            List <BankAccount> bankAccounts = new List <BankAccount>()
            {
                account1, account2, account3
            };

            ListInput(bankAccounts);

            service.WriteAccounts(storage, bankAccounts);

            service.WithdrawMoney(100m, bankAccounts[0]);
            service.DepositMoney(10m, bankAccounts[1]);
            service.CloseAccount(bankAccounts[2]);
            ListInput(bankAccounts);

            bankAccounts = service.ReadAccounts(storage);
            ListInput(bankAccounts);

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("To String tests");
            BankAccount bankAccount1 = new BankAccount("BY20OLMP31350000001000000933", "Ivanov Ivan", 100M, 0.8f, TypeBankAccount.Base);
            BankAccount bankAccount2 = new BankAccount("BY20OLMP31350000001011110933", "Petrov Petr", 800M, 10f, TypeBankAccount.Gold);

            Console.WriteLine(bankAccount1);
            Console.WriteLine();
            Console.WriteLine(bankAccount2);
            Console.WriteLine();

            Console.WriteLine("Add new Bank Account");
            BankAccount bankAccount3 = new BankAccount("BY20OLMP31350000001000111933", "Sidorov Ivan", 50.145M, 13.8f, TypeBankAccount.Platinum);

            Console.WriteLine("Get all Accounts from storage");
            BankAccountStorage storage = new BankAccountStorage("file.bin");
            BankAccountService service = new BankAccountService(storage);

            try
            {
                service.AddNewAccount(bankAccount1);
                service.AddNewAccount(bankAccount2);
                service.AddNewAccount(bankAccount3);
            }
            catch (BankAccountExistsException exception)
            {
                Console.WriteLine();
                Console.WriteLine($"Error: {exception.Message}");
            }
            List <BankAccount> accounts = service.GetAllAccounts();

            foreach (var account in accounts)
            {
                Console.WriteLine(account);
            }
            Console.WriteLine();
            Console.WriteLine("Try add account with same IBAN");
            BankAccount bankAccountWrong = new BankAccount("BY20OLMP31350000001000111933", "Kotin Ann", 200M, 0f, TypeBankAccount.Base);

            try
            {
                service.AddNewAccount(bankAccountWrong);
            }
            catch (BankAccountExistsException exception)
            {
                Console.WriteLine();
                Console.WriteLine($"Error: {exception.Message}");
            }

            Console.WriteLine();
            Console.WriteLine("Change Balance and try withdraw a large amount");
            try
            {
                service.IncreaseBalance(bankAccount1, 200M);
                service.WithdrawBalance(bankAccount2, 10M);
                service.WithdrawBalance(bankAccount3, 100000M);
            }
            catch (WrongAmountException exception)
            {
                Console.WriteLine();
                Console.WriteLine($"Error: {exception.Message}");
            }
            Console.WriteLine();
            Console.WriteLine("Get change list Bank Account");
            accounts = service.GetAllAccounts();
            foreach (var account in accounts)
            {
                Console.WriteLine(account);
            }

            Console.WriteLine();
            Console.WriteLine("Try change balance of a non-existent account:");
            BankAccount bankAccountWrong2 = new BankAccount("BY20OLMP31350000001000111930", "Kotin Ann", 200M, 0f, TypeBankAccount.Base);

            try
            {
                service.WithdrawBalance(bankAccountWrong2, 100M);
            }
            catch (BankAccountDoesNotExistException exception)
            {
                Console.WriteLine();
                Console.WriteLine($"Error: {exception.Message}");
            }

            Console.WriteLine("Try to close account which does not exist");
            BankAccount bankAccountWrong3 = new BankAccount("BY20OLMP31350000001000111930", "lp", 1000M, 0f, TypeBankAccount.Base);

            try
            {
                service.CloseAccount(bankAccountWrong3);
            }
            catch (BankAccountDoesNotExistException exception)
            {
                Console.WriteLine();
                Console.WriteLine($"Error: {exception.Message}");
            }

            Console.WriteLine();
            Console.WriteLine("Close two Bank accounts and show list accounts");
            service.CloseAccount(bankAccount1);
            service.CloseAccount(bankAccount2);
            accounts = service.GetAllAccounts();
            foreach (var account in accounts)
            {
                Console.WriteLine(account);
            }

            Console.ReadLine();
        }