Exemple #1
0
        public async Task <IEnumerable <Transaction> > ProcessTransactionFile(Stream fileStream)
        {
            if (_transactionParser == null)
            {
                throw new ApplicationException("Setup parser first");
            }

            var result = new List <Transaction>();

            try
            {
                var transactions = await _transactionParser.GetTransactions(fileStream);

                foreach (var trans in transactions)
                {
                    result.Add(_transactionParser.ParseTransaction(trans));
                }
            }
            catch (TCGException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new TCGException($"Bad file format! {ex.Message}");
            }

            return(result);
        }
Exemple #2
0
        public void ShouldParseLine()
        {
            var transaction = _transactionParser.ParseTransaction("2015-02-01 S MR ");

            Assert.Null(transaction.CorruptedData);
            Assert.Equal(Constants.Sizes.Small, transaction.Size);
            Assert.Equal(Constants.Providers.MondialRelay, transaction.ShippingProvider);
            Assert.NotNull(transaction.Date);
            Assert.Equal(2, transaction.Date.Value.Month);
            Assert.Equal(1, transaction.Date.Value.Day);
            Assert.Equal(2015, transaction.Date.Value.Year);
        }
        public List <Transaction> ReadTransactions()
        {
            var file = File.ReadAllText(@"Resources\" + Constants.InputFile);

            var transactionList = new List <Transaction>();

            using (var reader = new StringReader(file))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var transaction = _transactionParser.ParseTransaction(line);
                    transactionList.Add(transaction);
                }
            }

            return(transactionList);
        }