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);
            }
        }
        public void Balance_CustomerOK()
        {
            //arrange
            Account account = new Account();
            Account account2 = new Account();
            Customer customer = new Customer();

            customer.RelatedAccounts.Add(account, new Role());
            customer.RelatedAccounts.Add(account2, new Role());

            IRepository repository = MockRepository.GenerateMock<IRepository>();
            ICustomerRepository customerRepository = MockRepository.GenerateMock<ICustomerRepository>();
            IAccountRepository accountRepository = MockRepository.GenerateMock<IAccountRepository>();
            IDtoCreator<Customer, CustomerDto> custCreator = new CustomerDtoCreator();

            IAccountServices accountServices = MockRepository.GenerateMock<IAccountServices>(); //(repository, accountRepository,customerRepository);
            accountServices.Expect(x => x.Balance(account2)).Return(-10);
            accountServices.Expect(x => x.Balance(account)).Return(-20);

            //act
            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices, custCreator);
            decimal balance = services.CustomerBalance(customer);

            //assert
            Assert.AreEqual(balance, -30);
            accountServices.VerifyAllExpectations();
        }
        public void FindIndividualCustomersByName()
        {
            ICustomerRepository customerRepository = new CustomerRepository(NhibernateHelper.SessionFactory);
            Repository repository = new Repository(NhibernateHelper.SessionFactory);

            Customer customer = new Customer { Code = "tjdsklfs", Email = "*****@*****.**", FirstName = "Sim", LastName = "Lehericey", Password = "******", PasswordSalt = "sss" };

            IList<Customer> customers1;
            IList<Customer> customers2;
            IList<Customer> customers3;

            using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
            {
                repository.Save(customer);
                //repository.Save(account1);
                repository.Flush();

                String[] names1 = { customer.FirstName };
                String[] names2 = { customer.LastName };
                String[] names3 = { customer.FirstName, customer.LastName };

                customers1 = customerRepository.FindCustomersByName(names1);
                customers2 = customerRepository.FindCustomersByName(names2);
                customers3 = customerRepository.FindCustomersByName(names3);

                Assert.IsNotNull(customers1);
                Assert.IsNotNull(customers2);
                Assert.IsNotNull(customers3);

            }
            Assert.AreEqual("*****@*****.**", customers1[0].Email);
            Assert.AreEqual("*****@*****.**", customers2[0].Email);
            Assert.AreEqual("*****@*****.**", customers3[0].Email);
        }
Example #4
0
        public Decimal CustomerBalance(Customer customer)
        {
            if (customer.RelatedAccounts == null)
            {
                return 0;
            }

            return customer.RelatedAccounts.Sum(x =>_accountServices.Balance(x.Key));
        }
Example #5
0
 public Permission GetCustomerRights(Account account, Customer customer)
 {
     if (customer.RelatedAccounts.ContainsKey(account))
     {
         Role role = customer.RelatedAccounts[account];
         return role.Permission;
     }
     return 0;
 }
        public List<TagDepenses> AggregateCustomerFromDB(Customer customer)
        {
            Dictionary<Tag, TagDepenses> depenses = new Dictionary<Tag, TagDepenses>();

            foreach (Account account in customer.RelatedAccounts.Keys)
            {
                MapTagDepenses(depenses, account.TagDepenses);
            }
            return depenses.Select(x => x.Value).ToList();
        }
        public List<TagDepenses> AggregateCustomer(Customer customer)
        {
            Dictionary<Tag, TagDepenses> depenses = new Dictionary<Tag, TagDepenses>();

            foreach (Account account in customer.RelatedAccounts.Keys)
            {
                var tagDepenses = AggregateAccountTags(account);
                MapTagDepenses(depenses, tagDepenses);
                _repository.Update<Account>(account);
            }
            return depenses.Select(x => x.Value).ToList();
        }
Example #8
0
 public static Customer Create(
     string value_s,
     string value_s1,
     Advisor value_advisor,
     CustomerProfile value_customerProfile,
     string value_s2,
     string value_s3,
     DateTime value_dt,
     FamilySituation value_i,
     string value_s4,
     string value_s5,
     IList<UserTag> value_iList,
     IList<PaymentEvent> value_iList1_,
     IList<BusinessPartner> value_iList2_,
     IList<TagDepenses> value_iList3_,
     IList<CustomerImage> value_iList4_,
     IList<AuthToken> value_iList5_,
     int value_i1_,
     string value_s6,
     string value_s7,
     DateTime value_dt1,
     DateTime value_dt2,
     string value_s8,
     UserType value_i2_
 )
 {
     Customer customer = new Customer();
     customer.Code = value_s;
     customer.PhoneNumber = value_s1;
     customer.Advisor = value_advisor;
     customer.CustomerProfile = value_customerProfile;
     customer.FirstName = value_s2;
     customer.LastName = value_s3;
     customer.BirthDate = value_dt;
     customer.Situation = value_i;
     customer.Password = value_s4;
     customer.PasswordSalt = value_s5;
     customer.Tags = value_iList;
     customer.PaymentEvents = value_iList1_;
     customer.Partners = value_iList2_;
     customer.TagDepenses = value_iList3_;
     customer.Images = value_iList4_;
     customer.Tokens = value_iList5_;
     ((UserIdentity)customer).Id = value_i1_;
     ((UserIdentity)customer).Identification = value_s6;
     ((UserIdentity)customer).Type = value_s7;
     ((UserIdentity)customer).ValidityEndDate = value_dt1;
     ((UserIdentity)customer).ValidityStartDate = value_dt2;
     ((UserIdentity)customer).Email = value_s8;
     ((UserIdentity)customer).UserType = value_i2_;
     return customer;
 }
Example #9
0
        public void GetUserByIdentity_Found_NotFound()
        {
            IUserRepository userRepository = new UserRepository(NhibernateHelper.SessionFactory);
            Repository repository = new Repository(NhibernateHelper.SessionFactory);

            Customer customer = new Customer { Id = 1, Identification = "Ident", Email = "Test", Password = "******", FirstName = "Name", LastName = "Last", Code = "Code", PasswordSalt = "sss" };

            using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
            {
                repository.Save(customer);
                repository.Flush();
                UserIdentity user = userRepository.GetUserByIdentity(customer.Identification);
                UserIdentity user2 = userRepository.GetUserByIdentity("test");
                Assert.AreEqual(user.Email, customer.Email);
                Assert.AreEqual(user2, null);
            }
        }
Example #10
0
        public void CreateCustomer(string firstName, string lastName, string email, string phoneNumber, string code)
        {
            Customer customer = new Customer();
            customer.Code = code;
            customer.Email = email;
            customer.FirstName = firstName;
            customer.LastName = lastName;
            customer.PhoneNumber = phoneNumber;
            customer.Password = GenerationUtils.RandomString(8);
            customer.PasswordSalt = GenerationUtils.RandomString(5);

            using (TransactionScope scope = new TransactionScope())
            {
                _repository.Save<Customer>(customer);
                _repository.Flush();
                scope.Complete();
            }
        }
        public void GetAccountByCustomerNoAccountFound()
        {
            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="12349340943"};

            using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
            {
                repository.Save(thirdParty1);
                repository.Save(thirdParty2);
                repository.Save(account1);

                repository.Flush();

                IList<Account> accounts = accountRepository.GetAccountsByCustomer(thirdParty2.Id);
                Assert.AreEqual(0, accounts.Count);
            }
        }
        public decimal CustomerBalance(Customer customer)
        {
            //assume
            Dictionary<Account, Role> accounts = new Dictionary<Account, Role>();
            accounts.Add(new Account { Id = 1, Balance = 100 }, new Role());
            accounts.Add(new Account { Id = 2, Balance = -200 }, new Role());

            PexAssume.Implies(customer != null, () => customer.RelatedAccounts = accounts);

            //arrange
            SIRepository repository = new SIRepository();
            SICustomerRepository customerRepository = new SICustomerRepository();
            SIAccountServices accountServices = new SIAccountServices();
            IDtoCreator<Customer,CustomerDto> custCreator = new CustomerDtoCreator();

            accountServices.BalanceAccount = (x) => x.Balance;

            CustomerServices services = new CustomerServices(customerRepository, repository, accountServices,custCreator);
            var result = services.CustomerBalance(customer);
            PexAssert.Case(customer.RelatedAccounts == accounts).Implies(() => result == -100);
            return result;
        }
        public void GetCustomerByIdentity_Found_NotFound()
        {
            ICustomerRepository customerRepository = new CustomerRepository(NhibernateHelper.SessionFactory);
            Repository repository = new Repository(NhibernateHelper.SessionFactory);

            Customer customer = new Customer { Code = "tjdsklfs", Email = "*****@*****.**", FirstName = "Sim", LastName = "Lehericey", Password = "******", Identification = "Ident", PasswordSalt = "sss" };

            Customer foundCustomer;
            Customer notFoundCustomer;

            using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
            {
                repository.Save(customer);
                repository.Flush();

                foundCustomer = customerRepository.GetCustomerByIdentity(customer.Identification);
                notFoundCustomer = customerRepository.GetCustomerByIdentity("a");
            }
            Assert.IsNull(notFoundCustomer);
            Assert.IsNotNull(foundCustomer);
            Assert.AreEqual("*****@*****.**", foundCustomer.Email);
        }
Example #14
0
 public string GetName(Customer customer)
 {
     return String.Format("{0} {1}", customer.FirstName, customer.LastName);
 }
Example #15
0
 /// <summary>
 /// Find a profile for a customer, based on the customers age and family situation
 /// </summary>
 /// <param name="customer"></param>
 /// <param name="profiles"></param>
 /// <returns></returns>
 public CustomerProfile FindProfile(Customer customer, IList<CustomerProfile> profiles)
 {
     var selectedProfile = (from profile in profiles
                            where customer.GetAge() >= profile.LowAge && customer.GetAge() <= profile.HighAge && customer.Situation == profile.Situation
                            select profile).FirstOrDefault();
     return selectedProfile;
 }
        public void GetIndividualCustomerByCode_Found()
        {
            ICustomerRepository customerRepository = new CustomerRepository(NhibernateHelper.SessionFactory);
            Repository repository = new Repository(NhibernateHelper.SessionFactory);

            Customer customer = new Customer { Code = "tjdsklfs", Email = "*****@*****.**", FirstName = "Sim", LastName = "Lehericey", Password = "******", PasswordSalt = "sss" };
            Account account1 = new Account { Balance = 201, BalanceDate = DateTime.Now, Number = "dsf1", Iban="1234"};

            Customer retrievedCustomer;

            using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
            {
                repository.Save(customer);
                repository.Save(account1);
                repository.Flush();

                retrievedCustomer = customerRepository.GetCustomerByCode(customer.Code);
                Assert.IsNotNull(retrievedCustomer);
            }
        }
        public void GetIndividualCustomerByCode_NotFound()
        {
            ICustomerRepository thirdPartyRepository = new CustomerRepository(NhibernateHelper.SessionFactory);
            Repository repository = new Repository(NhibernateHelper.SessionFactory);

            Customer individualThirdParty1 = new Customer { Code = "tjdsklfs", Email = "*****@*****.**", FirstName = "Sim", LastName = "Lehericey", Password = "******", PasswordSalt = "sss" };

            using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
            {
                repository.Save(individualThirdParty1);
                repository.Flush();

                Customer individualThirdPartyRetrieved = thirdPartyRepository.GetCustomerByCode("a");
                Assert.IsNull(individualThirdPartyRetrieved);
            }
        }
Example #18
0
        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));
        }
Example #19
0
        public void GetClientAccounts_ClientNotNull()
        {
            //arange
            IRepository repository = MockRepository.GenerateStub<IRepository>();
            IAccountRepository accountRepository = MockRepository.GenerateMock<IAccountRepository>();
            ICustomerRepository thirdPartyRepository = MockRepository.GenerateStub<ICustomerRepository>();
            IDtoCreator<Account, AccountDto> accountCreator = new AccountDtoCreator();

            Customer customer = new Customer { Id = 3 };
            IList<Account> accounts = new List<Account>();
            Account account = new Account() { Id = 1 };
            accounts.Add(account);

            accountRepository.Expect(x => x.GetAccountsByCustomer(customer.Id)).Return(accounts);

            //act
            AccountServices services = new AccountServices(repository, accountRepository, thirdPartyRepository,accountCreator);
            IList<AccountDto> retrievedAccounts = services.GetCustomerAccounts(customer.Id);

            //assert
            Assert.AreEqual(1, retrievedAccounts.Count);
            Assert.AreEqual(account.Id, retrievedAccounts[0].Id);
            accountRepository.VerifyAllExpectations();
        }
Example #20
0
 public void CreateNewCustomer(String password, String userName,  String email)
 {
     String salt = _hashProvider.CreateSalt(8);
     Customer customer = new Customer { Password = password, PasswordSalt = salt, Identification = userName, Email = email };
 }
Example #21
0
 public decimal CustomerBalance(Customer customer)
 {
     Contract.Requires<CustomerServicesException>(customer != null);
     return default(decimal);
 }
Example #22
0
        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();
        }
Example #23
0
        private List<TagDepenses> AggregateCustomerTagDepenses(Customer customer)
        {
            Dictionary<Tag, TagDepenses> depenses = new Dictionary<Tag, TagDepenses>();

            foreach (Account account in customer.RelatedAccounts.Keys)
            {
                foreach (TagDepenses tagDepense in account.TagDepenses)
                {

                    if (depenses.ContainsKey(tagDepense.Tag))
                    {
                        depenses[tagDepense.Tag].Depenses += tagDepense.Depenses;
                    }
                    else
                    {
                        depenses.Add(tagDepense.Tag, tagDepense);
                    }
                }
            }
            return depenses.Select(x => x.Value).ToList();
        }
Example #24
0
 public void Update(ref Customer customer, CustomerDto customerDto)
 {
     customer.Email = customerDto.Email;
     customer.FirstName = customerDto.FirstName;
     customer.LastName = customerDto.LastName;
     customer.PhoneNumber = customerDto.PhoneNumber;
     customer.Situation = customerDto.Situation;
 }