public void CreateOperation_Amount_IsNegative() { Account account = new Account(); OperationServices operationServices = new OperationServices(_repository, _accountRepository); operationServices.CreateOperations(account, OperationType.Deposit, -10000); }
public void CreateOperation_DefaultCase() { Expect.Call(_accountRepository.GetBalance(3)).Return(15000); _mocks.ReplayAll(); Account account = new Account { Id = 3 }; OperationServices operationServices = new OperationServices(_repository, _accountRepository); operationServices.CreateOperations(account, OperationType.Withdraw, 10000); _mocks.VerifyAll(); }
public void DisplayBalance_AccountIsNotNull_DefaultCulture() { IRepository repository = _mocks.Stub<IRepository>(); IAccountRepository accountRepository = _mocks.Stub<IAccountRepository>(); Account account = new Account { Id = 2 }; Expect.Call(accountRepository.GetBalance(2)).Return(1000000); _mocks.ReplayAll(); AccountServices services = new AccountServices(repository, accountRepository); string balance = services.DisplayBalance(account, null); Assert.AreEqual("$1,000,000.00", balance); _mocks.VerifyAll(); }
public void DisplayBalance_AccountIsNotNull_FrenchCulture() { IRepository repository = _mocks.Stub<IRepository>(); IAccountRepository accountRepository = _mocks.Stub<IAccountRepository>(); Account account = new Account { Id = 2 }; CultureInfo cultureInfo = new CultureInfo("fr-FR"); Expect.Call(accountRepository.GetBalance(2)).Return(1000000); _mocks.ReplayAll(); AccountServices services = new AccountServices(repository, accountRepository); string balance = services.DisplayBalance(account, cultureInfo); Assert.AreEqual("1 000 000,00 €", balance); _mocks.VerifyAll(); }
public void GetAccountsByClient_NoAccountFound() { IOperationRepository operationRepository = new OperationRepository(NHibernateHelper.SessionFactory); IAccountRepository accountRepository = new AccountRepository(NHibernateHelper.SessionFactory, operationRepository); Repository repository = new Repository(NHibernateHelper.SessionFactory); Client client1 = new Client { LastName = "Aaa", FirstName = "Bbb", StartDate = DateTime.Now }; Client client2 = new Client { LastName = "Ccc", FirstName = "Ddd", StartDate = DateTime.Now }; Account account1 = new Account { AccountHolder = client1, OpeningDate = DateTime.Now }; Account account2 = new Account { AccountHolder = client1, OpeningDate = DateTime.Now }; using (ITransaction transaction = NHibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction()) { repository.Save(client1); repository.Save(client2); repository.Save(account1); repository.Flush(); IList<Account> accounts = accountRepository.GetAccountsByClient(client2.Id); Assert.AreEqual(0, accounts.Count); } }
public void GetBalance_WithNoOperations() { IOperationRepository operationRepository = _mocks.Stub<IOperationRepository>(); IAccountRepository accountRepository = new AccountRepository(NHibernateHelper.SessionFactory, operationRepository); Client client1 = new Client { LastName = "Aaa", FirstName = "Bbb", StartDate = DateTime.Now }; Client client2 = new Client { LastName = "Ccc", FirstName = "Ddd", StartDate = DateTime.Now }; Account account1 = new Account { AccountHolder = client1, OpeningDate = DateTime.Now }; Account account2 = new Account { AccountHolder = client1, OpeningDate = DateTime.Now }; Expect.Call(operationRepository.GetOperationsByAccount(account1.Id)) .Return(new List<Operation>()); _mocks.ReplayAll(); Assert.AreEqual(0, accountRepository.GetBalance(account1.Id)); _mocks.VerifyAll(); }
public void GetBalance_WithSomeOperations() { IOperationRepository operationRepository = _mocks.Stub<IOperationRepository>(); IAccountRepository accountRepository = new AccountRepository(NHibernateHelper.SessionFactory, operationRepository); Client client1 = new Client { LastName = "Aaa", FirstName = "Bbb", StartDate = DateTime.Now }; Client client2 = new Client { LastName = "Ccc", FirstName = "Ddd", StartDate = DateTime.Now }; Account account1 = new Account { AccountHolder = client1, OpeningDate = DateTime.Now }; Account account2 = new Account { AccountHolder = client1, OpeningDate = DateTime.Now }; Operation operation1 = new Operation { Account = account1, OperationType = OperationType.Deposit, Amount = 10000, Date = DateTime.Now }; Operation operation2 = new Operation { Account = account1, OperationType = OperationType.Withdraw, Amount = 1000, Date = DateTime.Now }; Operation operation3 = new Operation { Account = account1, OperationType = OperationType.Withdraw, Amount = 5000, Date = DateTime.Now }; Operation operation4 = new Operation { Account = account1, OperationType = OperationType.Deposit, Amount = 30000, Date = DateTime.Now }; Expect.Call(operationRepository.GetOperationsByAccount(account1.Id)) .Return(new List<Operation> { operation1, operation2, operation3, operation4 }); _mocks.ReplayAll(); Assert.AreEqual(34000, accountRepository.GetBalance(account1.Id)); _mocks.VerifyAll(); }
/// <summary> /// Create an operation, withdraw is allowed only if there is enough money on the bank account /// </summary> /// <param name="account"></param> /// <param name="operationType"></param> /// <param name="amount"></param> public void CreateOperations(Account account, OperationType operationType, decimal amount) { throw new NotImplementedException(); }
private IList<Account> CreateData() { Client Client1 = new Client { Id = 1 }; Client Client2 = new Client { Id = 2 }; Client Client3 = new Client { Id = 3 }; Account account11 = new Account {Id=11, AccountHolder = Client1 }; Account account12 = new Account { Id = 12, AccountHolder = Client1 }; Account account2 = new Account { Id = 2, AccountHolder = Client2 }; Account account3 = new Account { Id = 3, AccountHolder = Client3 }; Client1.Accounts= new List<Account> {account11, account12 }; Client2.Accounts = new List<Account>{account2}; Client3.Accounts = new List<Account>{account3}; return new List<Account> { account11, account12, account2, account3 }; }
public void DisplayGlobalBalance_ClientHasAccounts_DefaultCulture() { IRepository repository = _mocks.Stub<IRepository>(); IAccountRepository accountRepository = _mocks.Stub<IAccountRepository>(); AccountServices services = new AccountServices(repository, accountRepository); Account account1 = new Account{Id = 4}; Account account2 = new Account{Id = 5}; Client client = new Client { Id = 2 , Accounts = new List<Account> { account1, account2 } }; Expect.Call(accountRepository.GetAccountsByClient(2)).Return(client.Accounts); Expect.Call(accountRepository.GetBalance(4)).Return(50000); Expect.Call(accountRepository.GetBalance(5)).Return(30000); _mocks.ReplayAll(); string globalBalance = services.DisplayGlobalBalance(client, null); Assert.AreEqual("$80,000.00", globalBalance); _mocks.VerifyAll(); }
public void DisplayGlobalBalance_ClientHasNoAccount() { IRepository repository = _mocks.Stub<IRepository>(); IAccountRepository accountRepository = _mocks.Stub<IAccountRepository>(); AccountServices services = new AccountServices(repository, accountRepository); Account account1 = new Account(); Account account2 = new Account(); Client client = new Client { Accounts = new List<Account> { account1, account2 } }; services.DisplayBalance(null, null); }
/// <summary> /// Returns the balance of the considered account /// If culture is not specified, use the default culture (en-US) /// </summary> /// <param name="account"></param> /// <param name="cultureInfo"></param> /// <returns></returns> public string DisplayBalance(Account account, CultureInfo cultureInfo) { decimal balance = _accountRepository.GetBalance(account.Id); return balance.ToString(); }