public void CreateAccountTest()
        {
            string ssn = "123456453";

            // adds to external repository
            AddUser("john", ssn);

            IBankAccountService service = GetBankAccountService();

            IUser accountOwner = service.FindUser(ssn);

            // initially user should have no accounts
            Assert.IsTrue(service.GetAccounts(accountOwner).Count() == 0);

            Money initialDeposit = new Money(150, new Currency("United States dollar", "USD"));

            Account actual, other;

            actual = service.CreateAccount(accountOwner, initialDeposit);
            Assert.IsTrue(service.GetAccounts(accountOwner).Count() == 1);

            other = (Account)service.GetAccount(actual.AccountNo);

            Assert.AreEqual<AccountNo>(actual.AccountNo, other.AccountNo);
            Assert.AreEqual<string>(actual.AccountOwner.SSN, other.AccountOwner.SSN);

            Assert.AreEqual<Money>(initialDeposit, actual.Balance);
            Assert.AreEqual<Money>(initialDeposit, other.Balance);

            // add 5 more
            Account[] accounts = new Account[5];
            for (int i = 0; i < 5; i++)
            {
                accounts[i] = service.CreateAccount(accountOwner, initialDeposit);
            }

            Assert.AreEqual<int>(6, service.GetAccounts(accountOwner).Count());
        }
 public void Update(Account account)
 {
     _repository.Update(account);
 }
        public void DeleteAccountTest()
        {
            string ssn = "123456453";

            // adds to external repository
            AddUser("john", ssn);

            IBankAccountService service = GetBankAccountService();

            IUser accountOwner = service.FindUser(ssn);

            // initially user should have no accounts
            Assert.IsTrue(service.GetAccounts(accountOwner).Count() == 0);

            Money initialDeposit = new Money(100, new Currency("United States dollar", "USD"));

            Account[] accounts = new Account[5];
            for (int i = 0; i < 5; i++)
            {
                accounts[i] = service.CreateAccount(accountOwner, initialDeposit);
            }

            for (int i = 0; i < 5; i++)
            {
                // account must have exactly the minimum balance of $100 before it can be closed
                service.DeleteAccount(accounts[i].AccountNo);
                Assert.IsTrue(service.GetAccount(accounts[i].AccountNo) == null);
            }

            try
            {
                // this account should no longer exist
                // also tests for deleting non-existing account
                service.DeleteAccount(accounts[2].AccountNo);
                Assert.Fail("Expected InvalidOperationException");
            }
            catch (InvalidOperationException) { }

            try
            {
                // can only close an account if Balance = minimum balance ($100 in this case)
                Account acct = service.CreateAccount(accountOwner, new Money(101, new Currency("United States dollar", "USD")));
                service.DeleteAccount(acct.AccountNo);
                Assert.Fail("Expected InvalidOperationException");
            }
            catch (InvalidOperationException) { }
        }
 public void InsertAccount(Account account)
 {
     _repository.Insert(account);
 }