Ejemplo n.º 1
0
        public void CloseAccount_CorrectValuesPassed_ClosesCorrectly()
        {
            var repositoryMock            = new Mock <IAccountRepository>();
            var unitOfWorkMock            = Mock.Of <IUnitOfWork>();
            var accountIdGeneratorMock    = Mock.Of <IAccountIdGeneratorService>();
            var bonusPointsCalculatorMock = Mock.Of <IBonusPointsCalculatorService>();

            repositoryMock.Setup(repository => repository.Update(It.Is <BankAccountDto>(dto => dto.IsClosed)));
            repositoryMock.Setup(repository => repository.GetAccountById(It.IsAny <string>()))
            .Returns(new BankAccountDto
            {
                FirstName   = string.Empty,
                LastName    = string.Empty,
                Id          = string.Empty,
                AccountType = "PlatinumAccount"
            });

            var service = new BankAccountService(
                repositoryMock.Object,
                unitOfWorkMock,
                accountIdGeneratorMock,
                bonusPointsCalculatorMock);

            service.CloseAccount(string.Empty);

            repositoryMock.Verify();
        }
Ejemplo n.º 2
0
        public void BankAccountRepository_RemoveAccountTest(string firstName, string lastName, string email, string expectedAccountNumber)
        {
            var repositoryMock = new Mock <IBankAccountRepository>();

            repositoryMock.Setup(repository => repository.GetAccount(It.IsAny <string>())).Returns(
                new DtoAccount
            {
                AccountNumber  = expectedAccountNumber,
                AccountType    = "BaseBankAccount",
                Balance        = 0,
                Bonus          = 0,
                OwnerFirstName = firstName,
                OwnerLastName  = lastName
            });
            var accountNumberGeneratorMock = new Mock <IAccountNumberGenerator>(MockBehavior.Strict);

            accountNumberGeneratorMock.Setup(service => service.CreateNumber(new List <BankAccount>())).Returns(expectedAccountNumber);
            var bankAccountService = new BankAccountService(repositoryMock.Object);

            bankAccountService.CreateAccount(
                AccountType.Base,
                accountNumberGeneratorMock.Object,
                firstName,
                lastName,
                email);

            bankAccountService.CloseAccount(expectedAccountNumber);

            repositoryMock.Verify(
                repository => repository.RemoveAccount(It.Is <DtoAccount>(account => account.AccountNumber == expectedAccountNumber)),
                Times.Once);
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            BankAccount accountJohn  = new BankAccount(1, "John", "Doe", 100.0m, 0, new BaseAccountType(), new DefaultBonusPointsCalculator());
            BankAccount accountJimmy = new BankAccount(2, "Jimmy", "McNulty", 0.0m, 10, new GoldAccountType(), new DefaultBonusPointsCalculator());
            BankAccount accountJane  = new BankAccount(3, "Jane", "Doe", 200.0m, 15, new BaseAccountType(), new DefaultBonusPointsCalculator());
            BankAccount accountKima  = new BankAccount(4, "Kima", "Greggs", 10.0m, 15, new PlatinumAccountType(), new DefaultBonusPointsCalculator());
            BankAccount accountOmar  = new BankAccount(5, "Omar", "Little", 1000.0m, 20, new PlatinumAccountType(), new DefaultBonusPointsCalculator());

            Console.WriteLine("Create new bank account service\n");
            BankAccountService bankAccountService = new BankAccountService(new BinaryFileStorage("accounts.dat"));

            Console.WriteLine("Open \"Jimmy McNulty\" account\n");
            bankAccountService.OpenAccount(accountJimmy);
            Console.WriteLine("List of accounts:\n");
            bankAccountService.ShowAccounts();

            Console.WriteLine("Open \"Jane Doe\" account\n");
            bankAccountService.OpenAccount(accountJane);
            Console.WriteLine("List of accounts:\n");
            bankAccountService.ShowAccounts();

            Console.WriteLine("Deposit 500$ into \"Jimmy McNulty\" account:\n");
            bankAccountService.Deposit(accountJimmy, 500.0m);
            Console.WriteLine("List of accounts:\n");
            bankAccountService.ShowAccounts();

            Console.WriteLine("Withdraw 18$ from \"Jane Doe\" account:\n");
            bankAccountService.Withdraw(accountJane, 18.0m);
            Console.WriteLine("List of accounts:\n");
            bankAccountService.ShowAccounts();


            Console.WriteLine("Close \"Jimmy McNulty\" account:\n");
            bankAccountService.CloseAccount(accountJimmy);
            Console.WriteLine("List of accounts:\n");
            bankAccountService.ShowAccounts();

            Console.WriteLine("Close \"Jane Doe\" account:\n");
            bankAccountService.CloseAccount(accountJane);
            Console.WriteLine("List of accounts:\n");
            bankAccountService.ShowAccounts();

            Console.ReadLine();
        }
Ejemplo n.º 5
0
        public void BLL_CloseNotExistedAccount_Test(string lastName, string firstName, string accountID,
                                                    decimal invoiceAmount, double bonusScores, decimal withdrawAmount)
        {
            var mock = new Mock <IRepository>();

            mock.Setup(a => a.CloseAccount(accountID)).Throws(new Exception());
            IAccountService service = new BankAccountService(mock.Object);


            Assert.Throws <Exception>(() => service.CloseAccount(accountID));
        }
        private static void Main(string[] args)
        {
            IAccountService accountService = new BankAccountService();

            accountService.OpenAccount(new User("123", "123"), AccountType.Platinum, out string id);
            Console.WriteLine(accountService.Info(id));
            accountService.Deposite(id, 1000);
            accountService.Withdraw(id, 10);
            Console.WriteLine(accountService.Info(id));
            accountService.CloseAccount(id);
            Console.WriteLine(accountService.Info(id));
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            BankAccountService service = new BankAccountService()
            {
                ClientsList = new List <Client>()
                {
                    new Client
                    {
                        FirstName      = "Ivanov",
                        LastName       = "Ivan",
                        Email          = "*****@*****.**",
                        PhoneNumber    = "+37529115-35-35",
                        PassportNumber = "MP222222",
                        Accounts       = new List <Account>()
                        {
                            new Account {
                                AccountValue = 100, AccountBehaviour = new Base()
                            },
                            new Account {
                                AccountValue = 200, AccountBehaviour = new Silver()
                            },
                            new Account {
                                AccountValue = 300, AccountBehaviour = new Gold()
                            }
                        }
                    }
                }
            };

            service.ClientsList[0].Accounts[0].Withdraw(100);
            service.ClientsList[0].Accounts[1].Withdraw(200);
            service.ClientsList[0].Accounts[2].Withdraw(300);

            Console.WriteLine($"All account must have 0 value");
            Console.WriteLine($"The first account: {service.ClientsList[0].Accounts[0].ToString()}, " +
                              $"\nthe second: {service.ClientsList[0].Accounts[1].ToString()}, " +
                              $"\nthe third account: {service.ClientsList[0].Accounts[2].ToString()}");

            Console.WriteLine("\nPut on accounts 200, 300, 400");
            service.ClientsList[0].Accounts[0].Put(200);
            service.ClientsList[0].Accounts[1].Put(300);
            service.ClientsList[0].Accounts[2].Put(400);
            service.CloseAccount(null, service.ClientsList[0].Accounts[2].IdNumber);
            Console.WriteLine($"The first account: {service.ClientsList[0].Accounts[0].ToString()} " +
                              $"\nthe second: {service.ClientsList[0].Accounts[1].ToString()}, " +
                              $"\nthe third account: {service.ClientsList[0].Accounts[2].ToString()}");

            Console.WriteLine($"Add new account");
            Console.WriteLine("\nClient info: \n{0}", service.ClientsList[0].ToString());
            Console.ReadLine();
        }
Ejemplo n.º 8
0
        public void BLL_CloseAccountExecute_Test(string lastName, string firstName, string accountID,
                                                 decimal invoiceAmount, double bonusScores)
        {
            BankAccount account = new BaseAccount(new AccountOwner(firstName, lastName), accountID, invoiceAmount, bonusScores);

            account.IsClosed = true;
            var mock = new Mock <IRepository>();

            mock.Setup(a => a.FindAccountByID(accountID)).Returns(account);
            IAccountService service = new BankAccountService(mock.Object);

            service.CloseAccount(accountID);

            Assert.AreEqual(true, account.IsClosed);
        }
Ejemplo n.º 9
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();
        }