示例#1
0
        public void InsertOperationsBulkData(string data, String accountNumber)
        {
            var account = _repository.Find <Account>(x => x.Number == accountNumber).FirstOrDefault();

            if (account == null)
            {
                throw new Exception("Could not find specified account using the account number");
            }

            using (var reader = new StringReader(data))
            {
                var operations = CSVProcessing.GetTransactionsFromCSV(reader);


                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (var operation in operations)
                    {
                        operation.Account = account;
                        _repository.Save <Operation>(operation);
                    }
                    scope.Complete();
                }
            }
        }
 public void GetTransactionsFromCSVTestCSV()
 {
     using (TextReader reader = new StreamReader(@"transactions.csv"))
     {
         IEnumerable <Operation> actual;
         actual = CSVProcessing.GetTransactionsFromCSV(reader);
         Assert.IsTrue(actual.Count() > 0);
     }
 }
 public void GetCategorizedTransactionsCreateAndStoreTagsTestCSV()
 {
     using (TextReader reader = new StreamReader(@"transactions.csv"))
     {
         IRepository repository = MockRepository.GenerateMock <IRepository>();
         Dictionary <string, StandardTag> tagList = new Dictionary <string, StandardTag>();
         IList <Operation> actual;
         actual = CSVProcessing.GetCategorizedTransactionsCreateAndStoreTags(reader, repository, tagList);
         Assert.IsTrue(actual.Count > 0);
     }
 }
        public void ComposeOperationTest()
        {
            string timeString  = "10/11/2011";
            string amount      = "-3.456,35";
            string description = "SOME DESCRIPTION - OK";


            var actual = CSVProcessing.ComposeOperation(timeString, ref amount, description);

            Assert.IsTrue(actual.Amount == 3456.35m);
            Assert.IsTrue(actual.Direction == Direction.Debit);
        }
        public void GetTransactionsFromCSVTest()
        {
            var text = "date,description,amount\n" +
                       "25/11/2011,RETRAIT DAB 24/11/11 19H35 169770 BNP PARIBAS PARIS ,\"-60,00\"\n" +
                       "25/11/2011,VIREMENT RECU TIERS OCTO TECHNOLOGY VIREMENT SALAIRES NOVEMB ,\"2.023,96\"";

            using (TextReader reader = new StringReader(text)){
                var actual = CSVProcessing.GetTransactionsFromCSV(reader).ToList();

                Assert.IsTrue(actual.Count() == 2);
                Assert.AreEqual(actual.First().Amount, 60);
            }
        }
        public void GetCategorizedTransactionsCreateAndStoreTagsTest()
        {
            var text = "date,description,amount,category\n" +
                       "25/11/2011,RETRAIT DAB 24/11/11 19H35 169770 BNP PARIBAS PARIS ,\"-60,00\",withdrawal\n" +
                       "25/11/2011,VIREMENT RECU TIERS OCTO TECHNOLOGY VIREMENT SALAIRES NOVEMB ,\"2.023,96\",received payment";

            var         tagsBag    = new Dictionary <String, StandardTag>();
            IRepository repository = MockRepository.GenerateStub <IRepository>();

            using (TextReader reader = new StringReader(text))
            {
                var actual = CSVProcessing.GetCategorizedTransactionsCreateAndStoreTags(reader, repository, tagsBag).ToList();

                Assert.IsTrue(actual.Count() == 2);
                Assert.AreEqual(actual.First().Amount, 60);
                Assert.AreEqual(tagsBag.Count, 2);
            }
        }
示例#7
0
        public bool ProcessPayments()
        {
            var filePath = "/Data/CBSinput.txt";
            List <Operation> operations = new List <Operation>();

            using (var reader = new StreamReader(filePath))
            {
                var transactions = CSVProcessing.GetTransactionsFromCSV(reader);

                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (var transaction in transactions)
                    {
                        _repository.Save(transaction);
                    }
                    scope.Complete();
                }
            }

            return(true);
        }
示例#8
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();
        }