public void TestNhibernateConfigurationWithUser() { var client = new Client { FirstName = "AAAAAA", LastName = "BBBBBBB", StartDate = DateTime.Now }; using (var scope = new TransactionScope()) { _repo.Save(client); scope.Complete(); } int clientId = client.Id; _repo.Clear(); var clientRetrieved = _repo.Get<Client>(clientId); Assert.AreEqual(clientId, clientRetrieved.Id); using (var scope = new TransactionScope()) { _repo.Delete(clientRetrieved); scope.Complete(); } _repo.Clear(); Assert.IsNull(_repo.Get<Client>(clientId)); }
/// <summary> /// Returns all the accounts of the considered client /// </summary> /// <param name="client"></param> /// <returns></returns> public IList<Account> GetClientAccounts(Client client) { if (client == null) throw new AccountServicesException(); return _accountRepository.GetAccountsByClient(client.Id); }
/// <summary> /// Returns the cumulated balance of the considered client /// </summary> /// <param name="client"></param> /// <param name="cultureInfo"></param> /// <returns></returns> public string DisplayGlobalBalance(Client client, CultureInfo cultureInfo) { decimal globalBalance = GetClientAccounts(client) .Sum(clientAccount => _accountRepository.GetBalance(clientAccount.Id)); return globalBalance.ToString(); }
public void Find_NoExpression() { IClientRepository clientRepository = new ClientRepository(NHibernateHelper.SessionFactory, _accountRepository); Repository repository = new Repository(NHibernateHelper.SessionFactory); Client client = new Client { LastName = "Aaa", FirstName = "Bbb", StartDate = DateTime.Now }; using (ITransaction transaction = NHibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction()) { repository.Save(client); repository.Flush(); IList<Client> result = clientRepository.Find(null); Assert.AreEqual(1, result.Count); } }
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(); }
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 GetClientAccounts_ClientNotNull() { IRepository repository = _mocks.Stub<IRepository>(); IAccountRepository accountRepository = _mocks.Stub<IAccountRepository>(); Client client = new Client { Id = 3 }; IList<Account> accounts = new List<Account>(); Expect.Call(accountRepository.GetAccountsByClient(3)).Return(accounts); _mocks.ReplayAll(); AccountServices services = new AccountServices(repository, accountRepository); services.GetClientAccounts(client); _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); }