private static void Main(string[] args)
        {
            BankAccountService bankAccountService = new BankAccountService();

            bankAccountService.OpenAccount(new User("asfasf", "safasf"), AccountType.Platinum);

            foreach (BankAccount bankAccount in bankAccountService.GetAllAccounts())
            {
                Console.WriteLine(bankAccount.ToString());
            }
        }
        public void GetAllAccounts_GetAllBankAccountsTests()
        {
            Mock <IAccountStorage> mockStorage   = new Mock <IAccountStorage>();
            Mock <IBonusCounter>   mockCounter   = new Mock <IBonusCounter>();
            Mock <IIDGenerator>    mockGenerator = new Mock <IIDGenerator>();

            BankAccountService service = new BankAccountService(mockStorage.Object, mockCounter.Object);

            service.GetAllAccounts();

            mockStorage.Verify(storage => storage.GetAllAccounts(), Times.Exactly(2));
        }
Пример #3
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();
        }