Exemplo n.º 1
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();
        }