Exemplo n.º 1
0
        public void ParserThrowsArgumentExceptionWhenParsingEmptyTransactions(string invalidInputTransaction)
        {
            var parser = new TransactionParser(invalidInputTransaction);

            _ = Assert.Throws <ArgumentException>(
                delegate { parser.Parse(); });
        }
Exemplo n.º 2
0
        public bool TryGetMonthReports(FileData data, out TransactionReport report)
        {
            report = null;

            try
            {
                string header = data.Lines.FirstOrDefault();
                if (header.IsNull())
                {
                    return(false);
                }

                report = new TransactionReport()
                {
                    Name = data.Name, Transactions = new List <Transaction>()
                };

                char separator           = Convert.ToChar(data.Separator);
                TransactionParser parser = new TransactionParser(header, separator);

                for (int i = 1; i < data.Lines.Count; i++)
                {
                    string      line         = data.Lines[i];
                    Transaction iTransaction = parser.ParseFromLine(line);
                    report.Transactions.Add(iTransaction);
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public void CanParseTransactionXml()
        {
            Transaction transaction = TransactionParser.Parse(_xml);

            CheckIf.EqualId("419124c2108f39c94378c488dda67348", transaction.Id, "Transaction id should be parsed");
            Assert.AreEqual("RUB", transaction.Currency, "Transaction currency should be parsed");

            Assert.AreEqual(
                new DateTimeOffset(2013, 12, 9, 23, 00, 00, new TimeSpan(3, 0, 0)),
                transaction.Posted,
                "Transaction posted date should be parsed");

            Assert.AreEqual(
                new DateTimeOffset(2014, 1, 6, 15, 30, 21, new TimeSpan(3, 0, 0)),
                transaction.Entered,
                "Transaction entered date should be parsed");

            Assert.AreEqual("Обои (отдавать маме)", transaction.Description, "Transaction description should be parsed");

            Assert.AreEqual(2, transaction.Splits.Count, "Transaction splits should be parsed");

            AssertSplitValues(
                "e739f02a5e4ced52a8974292d183727f", "b43f593c319ae9bf475ddb2af3953b38", 10000.00m, 10000.00m,
                transaction.Splits[0]);

            AssertSplitValues(
                "0db32508c93b252e0acb168787d82289", "f7e5c9bd34d8cd881f481d837d98f94d", -10000.00m, -10000.00m,
                transaction.Splits[1]);
        }
Exemplo n.º 4
0
        public void ParseData_InvalidDataTooShort_ThrowsException()
        {
            byte[] data;

            data = HelperFunctions.ConvertHex(cDATA_INVALID);
            TransactionParser.Parse(data);
        }
Exemplo n.º 5
0
        public IList <ITransaction> GetTransactionHistory(string address, int num)
        {
            IList <ITransaction> result = new List <ITransaction>();

            if (num <= 0)
            {
                return(result);
            }
            string url  = string.Format("{0}/transactions/address/{1}/limit/{2}", NodeUrl, address, num);
            string json = HttpHelper.Get(url);

            try
            {
                List <List <object> > list = JsonConvert.DeserializeObject <List <List <object> > >(json);
                if (list.Count == 0)
                {
                    return(result);
                }
                List <object> txList = list[0];
                foreach (object txObj in txList)
                {
                    string       txStr = JsonConvert.SerializeObject(txObj);
                    ITransaction tx    = TransactionParser.Parse(txStr);
                    result.Add(tx);
                }
            }
            catch (Exception)
            {
                throw ApiError.FromJson(json);
            }
            return(result);
        }
Exemplo n.º 6
0
        Transaction GetTransaction(int rowNumber)
        {
            IExcelSheet    sheet = _app.GetActiveWorkbook().GetActiveSheet();
            ExcelSheetData data  = sheet.GetSheetData(1, rowNumber);


            if (data.Rows.Count < 2)
            {
                return(null);
            }


            ExcelRowData headerRowData = data.Rows[0];

            ExcelRowData valueRowData = data.Rows[1];

            string separator = ";";
            string header    = headerRowData.GetValuesInLine(separator);
            string values    = valueRowData.GetValuesInLine(separator);

            TransactionParser parser      = new TransactionParser(header, separator.FirstOrDefault());
            Transaction       transaction = parser.ParseFromLine(values);

            return(transaction);
        }
Exemplo n.º 7
0
        public void ParserCanParseMultipleTransactions()
        {
            var parser       = new TransactionParser(TransactionTestData.TwoValidTransactions);
            var transactions = parser.Parse();

            Assert.AreEqual(2, transactions.Count);
        }
Exemplo n.º 8
0
        public void ParserParsesDebitTransaction()
        {
            var parser       = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount);
            var transactions = parser.Parse();

            Assert.AreEqual(-3.52M, transactions[0].Amount);
        }
Exemplo n.º 9
0
        public void ParseStream_EmptyData_ThrowsException()
        {
            MemoryStream stream = new MemoryStream {
                Capacity = 0
            };

            TransactionParser.Parse(stream);
        }
Exemplo n.º 10
0
        public void ParserSkipsEmptyLine()
        {
            var parser = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount + Environment.NewLine);

            var transactions = parser.Parse();

            Assert.AreEqual(1, transactions.Count);
        }
Exemplo n.º 11
0
        public void ParserParsesTransactionDate()
        {
            var parser = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount);

            var transactions = parser.Parse();

            Assert.AreEqual(new DateTime(2020, 12, 18), transactions[0].Date);
        }
Exemplo n.º 12
0
        public void ParserParsesDescription()
        {
            var parser = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount);

            var transactions = parser.Parse();

            Assert.AreEqual("ACME Company", transactions[0].Description);
        }
Exemplo n.º 13
0
        public void ParserReadsLine()
        {
            var parser = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount);

            var transactions = parser.Parse();

            Assert.AreEqual(1, transactions.Count);
        }
Exemplo n.º 14
0
        public void ParseStream_InvalidDataTooShort_ThrowsException()
        {
            byte[]       data;
            MemoryStream stream;

            data   = HelperFunctions.ConvertHex(cDATA_INVALID);
            stream = new MemoryStream(data);
            TransactionParser.Parse(stream);
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Приложение для личного финансового учета");

            Trace.Listeners.Add(new ConsoleTraceListener());

            var currencyConverter = new ExchangeRatesApiConverter(new HttpClient(), new MemoryCache(new MemoryCacheOptions()), "a5cf9da55cb835d0a633a7825b3aa8b5");

            var transactionParser = new TransactionParser();
            // var transactionRepository = new InMemoryTransactionRepository();
            var transactionRepository = new FileTransactionRepository("transactions.txt", transactionParser);

            var budgetApp = new BudjetApplication(transactionRepository, transactionParser, currencyConverter);

            //budgetApp.AddTransaction("Трата -10 EUR Продукты A-Store");
            //budgetApp.AddTransaction("Трата -100 USD Бензин RP");
            //budgetApp.AddTransaction("Трата -50 EUR Кафе Turandot");
            //budgetApp.AddTransaction("Зачисление 2000 EUR Зарплата");
            //budgetApp.AddTransaction("Перевод 50 EUR Услуги BeeLine");

            budgetApp.OutputTransactions();

            budgetApp.OutputBalanceInMainCurrencies();

            var flagContinue = true;

            while (flagContinue)
            {
                Console.WriteLine("Введите 1 - для ввода новой транзакции, 2 - вывести транзакции, 0 - Выход");
                var key = Console.ReadKey();
                Console.WriteLine();

                if (key.KeyChar == '0')
                {
                    flagContinue = false;
                }
                else if (key.KeyChar == '1')
                {
                    Console.WriteLine("Введите транзакцию: ");
                    var input = Console.ReadLine();

                    budgetApp.AddTransaction(input);
                    budgetApp.OutputBalanceInMainCurrencies();
                }
                else if (key.KeyChar == '2')
                {
                    Console.WriteLine("Список транзакций:");
                    Console.WriteLine("======================");

                    budgetApp.OutputTransactions();
                    budgetApp.OutputBalanceInMainCurrencies();
                }
            }
        }
Exemplo n.º 16
0
        public void ParseData_ValidData_IsValid()
        {
            byte[]      data;
            Transaction result;

            data   = HelperFunctions.ConvertHex(cDATA_VALID_1_1);
            result = TransactionParser.Parse(data);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Inputs.Count, 1);
            Assert.AreEqual(result.LockTime.Type, LockTimeType.NoLockTime);
            Assert.AreEqual(result.Outputs.Count, 1);
            Assert.AreEqual(result.Version, 1);
        }
Exemplo n.º 17
0
        public void ShouldProcessOfficialAbnAmroBankExportFile()
        {
            var inputFileData        = File.ReadAllText(Path.Combine(LocationOfTestFiles, "THREE_MONTH_ABN_AMRO_EXPORT_FILE.TAB"));
            var inputCategoryMapJson = File.ReadAllText(Path.Combine(LocationOfTestFiles, "TestCategories.json"));

            var parser    = new TransactionParser(inputFileData);
            var processor = new TransactionProcessor(parser, inputCategoryMapJson);
            var cr        = new CategoryReporter(processor);

            var report = cr.CreateReport();

            StringAssert.Contains("unknown: 2453.43 EUR", report);
        }
Exemplo n.º 18
0
        public void TransactionParser_ShouldParseTransaction_WhenCorrectDataProvided()
        {
            // Arrange
            var parser = new TransactionParser();

            // Act
            var transaction = parser.ParseTransactionEntry("2018-09-01 7-ELEVEN 100");

            // Assert
            Assert.Equal("7-ELEVEN", transaction.Owner.Name);
            Assert.Equal(new DateTime(2018, 9, 1), transaction.DoneOn);
            Assert.Equal(100M, transaction.Amount);
        }
Exemplo n.º 19
0
        public ITransaction GetUnconfirmedTransactionById(string txId)
        {
            string url  = string.Format("{0}/transactions/unconfirmed/info/{1}", NodeUrl, txId);
            string json = HttpHelper.Get(url);

            try
            {
                return(TransactionParser.Parse(json));
            }
            catch (Exception)
            {
                throw TransactionError.FromJson(json);
            }
        }
Exemplo n.º 20
0
        private static void Main()
        {
            var transactionParser = new TransactionParser();
            var transactionReader = new TransactionReader(transactionParser);

            var transactions = transactionReader.ReadTransactions();

            var discountCalculator = new DiscountCalculator();

            transactions = discountCalculator.CalculateDiscounts(transactions);

            var outputPrinter = new OutputPrinter();

            outputPrinter.PrintOutput(transactions);

            Console.WriteLine("\nPress any button to close.");
            Console.ReadKey();
        }
Exemplo n.º 21
0
        public ITransaction GetTransactionById(string txId)
        {
            string       url  = string.Format("{0}/transactions/info/{1}", NodeUrl, txId);
            string       json = HttpHelper.Get(url);
            ITransaction tx;

            try
            {
                tx = TransactionParser.Parse(json);
            }
            catch (Exception)
            {
                throw TransactionError.FromJson(json);
            }
            if (tx != null && tx.Status.Equals("error"))
            {
                throw TransactionError.FromJson(json);
            }
            return(tx);
        }
Exemplo n.º 22
0
        private static async Task RunAsync(Options option)
        {
            var cnbProvider     = new CzechNationalBankProvider();
            var kurzyCzProvider = new KurzyCzProvider();

            var parser       = new TransactionParser();
            var transactions = new List <Transaction>();
            var filePaths    = ResolveFilePaths(option.StatementFilePaths);

            if (filePaths.Count == 0)
            {
                Console.WriteLine("No valid path to scan found. Check that file or directory exist.");
                return;
            }

            foreach (var file in filePaths)
            {
                Console.WriteLine($"Processing file: {file}");
                var result = await parser.ParseAsync(file);

                if (result != null)
                {
                    transactions.AddRange(result);
                }
            }

            Console.WriteLine("Downloading exchange rates ...");

            var builder          = new TransactionViewBuilder(kurzyCzProvider, cnbProvider);
            var transactionViews = await builder.BuildAsync(transactions);

            var summaryViews = CreateDividendSummaryViews(transactionViews);

            var views = new List <object>(transactionViews);

            views.AddRange(summaryViews);

            Print(option, views);
        }
Exemplo n.º 23
0
        private static async Task RunAsync(Options option)
        {
            var parser = new TransactionParser();

            var transactions = new List <Transaction>();
            var filePaths    = ResolveFilePaths(option.StatementFilePaths);

            if (filePaths.Count == 0)
            {
                Console.WriteLine("No valid path to scan found. Check that file or directory exist.");
                return;
            }

            foreach (var file in filePaths)
            {
                Console.WriteLine($"Processing file: {file}");
                var result = await parser.ParseAsync(file);

                if (result != null)
                {
                    transactions.AddRange(result);
                }
            }

            var printer = new Output();

            if (option.ShouldPrintAsJson)
            {
                printer.PrintAsJson(transactions);
            }
            else if (option.ExcelSheetPath != null)
            {
                printer.SaveAsExcelSheet(option.ExcelSheetPath, transactions);
            }
            else
            {
                printer.PrintAsPlainText(transactions);
            }
        }
Exemplo n.º 24
0
 public void ParseData_EmptyData_ThrowsException()
 {
     TransactionParser.Parse(new byte[0]);
 }
Exemplo n.º 25
0
 public void ParseData_NullData_ThrowsException()
 {
     TransactionParser.Parse(null as byte[]);
 }
Exemplo n.º 26
0
 public void ParseStream_NullData_ThrowsException()
 {
     TransactionParser.Parse(null as Stream);
 }