public void GetAccountsByCustomerSomeAccountsFound() { IAccountRepository accountRepository = new AccountRepository(NhibernateHelper.SessionFactory); Repository repository = new Repository(NhibernateHelper.SessionFactory); Customer thirdParty1 = new Customer { Code = "tjdsklfs", Email = "*****@*****.**", LastName = "roux", FirstName = "Olivier", Password = "******", PasswordSalt = "sss" }; Customer thirdParty2 = new Customer { Code = "topsecret", Email = "*****@*****.**", LastName = "roux2", FirstName = "Olivier", Password = "******", PasswordSalt = "sss" }; Account account1 = new Account { Balance = 201, BalanceDate = DateTime.Now, Number = "dsf1", Iban="12354"}; Account account2 = new Account { Balance = 202, BalanceDate = DateTime.Now, Number = "dsf2", Iban="12435"}; Role role = new Role{Id=1}; thirdParty1.RelatedAccounts.Add(account1, role); thirdParty1.RelatedAccounts.Add(account2, role); using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction()) { repository.Save(thirdParty1); repository.Save(thirdParty2); repository.Save(account1); repository.Save(account2); repository.Flush(); IList<Account> accounts = accountRepository.GetAccountsByCustomer(thirdParty1.Id); Assert.AreEqual(2, accounts.Count); } }
private static void CreateCustomersWithAccounts(IGenerationSession session,IRepository repository, Role[] roles) { var customers = session. List<Customer>(CUSTOMERS_COUNT).Get(); for (int i = 0; i < customers.Count; i++) { customers[i].Identification = "00000000" + i; customers[i].PasswordSalt = GenerationUtils.RandomString(5); customers[i].Password = SHA256HashProvider.Instance.Hash("Test" + customers[i].PasswordSalt); repository.Save(customers[i]); AddAccountsAndOperations(customers[i], roles, repository, session); //create some bussiness partners for each customer session.List<BusinessPartner>(5) .Impose(x => x.Customer, customers[i]) .Get().ForEach(x => repository.Save(x)); } repository.Flush(); }
private static Role[] CreateAndSaveRoles(IRepository repository) { Role[] roles = new Role[4]; roles[0] = new Role { Name = "Owner", Permission = Permission.Modify | Permission.Read | Permission.Write | Permission.Transfer }; roles[1] = new Role { Name = "Advisor", Permission = Permission.Modify | Permission.Read | Permission.Write | Permission.Transfer }; roles[2] = new Role { Name = "OperationTagger", Permission = Permission.Read | Permission.TagOperations }; roles[3] = new Role { Name = "Minor", Permission = Permission.Read }; roles.ForEach(x => Repository.Save(x)); repository.Flush(); repository.Clear(); return roles; }
private static void AddAccountsAndOperations(Customer customer, Role[] roles, IRepository repository, IGenerationSession session) { //get the transaction data from csv file using (var reader = new StreamReader(@"Data\transactions.csv")) { _categorizedTransactions = CSVProcessing.GetCategorizedTransactionsCreateAndStoreTags(reader, repository, _tagsBag); } Account account = session.Single<Account>().Get(); account.Name = "Savings account"; account.RelatedCustomers.Add(customer, roles[0]); account.Iban = GenerationUtils.GenerateIban(account.Number, "12345", "12345", "FR"); account.Currency = "EUR"; Account account2 = session.Single<Account>().Get(); account2.Name = "Checking account"; account2.RelatedCustomers.Add(customer, roles[1]); account2.Currency = "EUR"; customer.RelatedAccounts.Add(account, roles[0]); customer.RelatedAccounts.Add(account2, roles[1]); repository.Save(account); repository.Save(account2); repository.Save(customer); repository.Flush(); //Get random transactions from the list Random rnd = new Random(); var randomTransactions = _categorizedTransactions.Where(x => x.Tag.Name != "Not set").OrderBy(x => rnd.Next()); //add the first half to the first account SelectForAccount(repository, account, rnd, randomTransactions); SelectForAccount(repository, account2, rnd, randomTransactions); //IList<Operation> operations = session.List<Operation>(20) // .Impose(x => x.TransactionCode, Guid.NewGuid().ToString()) // .Impose(x => x.Currency, "EUR") // .Impose(x=>x.Tag,EmptyTag) // .First(10) // .Impose(x => x.Account, account) // .Next(10) // .Impose(x => x.Account, account2) // .All() // .Get(); //operations.ForEach(x => repository.Save(x)); repository.Flush(); var paymentEvents = session.List<PaymentEvent>(20) .First(10) .Impose(x => x.Account, account) .Impose(x=>x.Customer,customer) .Next(10) .Impose(x => x.Account, account2) .Impose(x=>x.Customer, customer) .All() .Get(); paymentEvents.ForEach(x => repository.Save(x)); repository.Flush(); }
public void CreateAccount_ok() { //arrange IRepository repository = MockRepository.GenerateStub<IRepository>(); IAccountRepository accountRepository = MockRepository.GenerateStub<IAccountRepository>(); ICustomerRepository thirdPartyRepository = MockRepository.GenerateStub<ICustomerRepository>(); IDtoCreator<Account, AccountDto> accountCreator = new AccountDtoCreator(); string accountName = "name"; Customer customer = new Customer() { Id = 1 }; Role role = new Role { Id = 1 }; repository.Expect(x => x.Get<Customer>(customer.Id)).Return(customer); repository.Expect(x => x.Get<Role>(role.Id)).Return(role); //act IAccountServices services = new AccountServices(repository, accountRepository, thirdPartyRepository, accountCreator); services.CreateAccount(accountName, customer.Id,role.Id); //assert repository.VerifyAllExpectations(); repository.AssertWasCalled(x => x.SaveOrUpdate<Customer>(customer)); repository.AssertWasCalled(x => x.Save<Account>(Arg<Account>.Is.NotNull)); }