Exemple #1
0
        private void ReadDataFromFile()
        {
            _transactions.Clear();

            if (!File.Exists(_path))
            {
                var fs = File.Create(_path);
                fs.Close();
            }

            var lines = File.ReadAllLines(_path);

            foreach (var line in lines)
            {
                try
                {
                    var transaction = _parser.Parse(line);
                    _transactions.Add(transaction);
                }
                catch (Exception e)
                {
                    Trace.WriteLine($"Parse error: {line}. Message: {e.Message}");
                }
            }
        }
        public async Task <IActionResult> UploadFile(IFormFile file)
        {
            var stream = file.OpenReadStream();
            var result = await _transactionParser.Parse(stream);

            return(Ok(result.Transactions.Count()));
        }
Exemple #3
0
 public void AddTransaction(string input)
 {
     try
     {
         var transaction = _transactionParser.Parse(input);
         _transactionRepository.AddTransaction(transaction);
     }
     catch (Exception e)
     {
         Console.WriteLine($"Не верно указали строку: {e.Message}");
     }
 }
        public async Task CsvParserTest_AllOk()
        {
            //Arrange
            using var streamReader = new StreamReader(TestData.File_CorrectCsvData);

            //Act
            var items = await _csvParser.Parse(streamReader).ToListAsync();

            //Assert
            Assert.Equal(2, items.Count());
            Assert.Equal("Invoice0000001", items[0].TransactionId);
            Assert.Equal(1000, items[0].Amount);
            Assert.Equal("USD", items[0].Currency);
            Assert.Equal(TransactionStatus.A, items[0].Status);
            Assert.Equal("20/02/2019 12:33:16", items[0].TransactionDate.ToString("dd/MM/yyyy hh:mm:ss"));

            Assert.Equal("Invoice0000002", items[1].TransactionId);
            Assert.Equal(300, items[1].Amount);
            Assert.Equal("USD", items[1].Currency);
            Assert.Equal(TransactionStatus.R, items[1].Status);
            Assert.Equal("21/02/2019 02:04:59", items[1].TransactionDate.ToString("dd/MM/yyyy hh:mm:ss"));
        }
Exemple #5
0
        public void AddTransaction(string input)
        {
            var transaction = _transactionParser.Parse(input);

            _transactionRepository.AddTransaction(transaction);

            var commission = _commissionCalculator.Calc(transaction);

            if (commission != null)
            {
                _transactionRepository.AddTransaction(commission);
            }

            //if (transaction is Transfer)
            //{
            //    var commission = new Commission(transaction);
            //    _transactionRepository.AddTransaction(commission);
            //}
        }
        public async Task XmlParserTest_AllOk()
        {
            //Arrange
            using var streamReader = new StreamReader(TestData.File_CorrectXmlData);

            //Act
            var items = await _xmlParser.Parse(streamReader).ToListAsync();

            //Assert
            Assert.Equal(2, items.Count());
            Assert.Equal("Inv00001", items[0].TransactionId);
            Assert.Equal(200, items[0].Amount);
            Assert.Equal("USD", items[0].Currency);
            Assert.Equal(TransactionStatus.D, items[0].Status);
            Assert.Equal("2019-01-23T13:45:10", items[0].TransactionDate.ToString("yyyy-MM-ddTHH:mm:ss"));

            Assert.Equal("Inv00002", items[1].TransactionId);
            Assert.Equal(10000, items[1].Amount);
            Assert.Equal("EUR", items[1].Currency);
            Assert.Equal(TransactionStatus.R, items[1].Status);
            Assert.Equal("2019-01-24T16:09:15", items[1].TransactionDate.ToString("yyyy-MM-ddTHH:mm:ss"));
        }
Exemple #7
0
        /// <summary>
        /// parse entire block including its tx
        /// </summary>
        /// <param name="hash"></param>
        /// <returns></returns>
        public uint Parse(string hash)
        {
            if (parsedHash.ContainsKey(hash))
            {
                return(parsedHash[hash]);
            }

            var block = GetBlock(hash);

            Store(block);

            if (block.nTx > 0)
            {
                transactionParser.Parse((uint)block.height, block.tx.ToList(), (uint)block.time);
            }

            if (!parsedHash.ContainsKey(hash))
            {
                parsedHash.Add(hash, (uint)block.height);
            }

            return((uint)block.height);
        }
Exemple #8
0
 public decimal GetTotalAmount()
 {
     parser.Parse();
     return(CalculateSumOfAllTransactions());
 }
        public void AddTransaction(string input)
        {
            var transaction = _transactionParser.Parse(input);

            _transactionRepository.AddTransaction(transaction);
        }