Exemple #1
0
        public async Task <IList <T> > ExtractAsync <T>(
            string fileName,
            Func <IList <string>, T> transform
            )
        {
            var heading = true;
            var list    = new List <T>();
            var record  = new List <string>();
            var parser  = new Rfc4180Parser(
                field => record.Add(field),
                () =>
            {
                if (heading)
                {
                    heading = false;
                }

                else
                {
                    var t = transform(record);

                    if (t != null)
                    {
                        list.Add(t);
                    }
                }

                record.Clear();
            });

            parser.Parse(await ReadAllTextAsync(fileName));

            return(list);
        }
Exemple #2
0
        public async Task LoadFile(
            string fileName
            )
        {
            var content = await CsvExtractor.ReadAllTextAsync(fileName);

            int count  = 0;
            var parser = new Rfc4180Parser(
                field => { },
                () => count += 1);
            var length = parser.Parse(content);

            Assert.That(length, Is.EqualTo(content.Length));
        }
Exemple #3
0
        public void Parse(
            string input,
            IList <IList <string> > expected,
            int expectedLength
            )
        {
            var row    = 0;
            var record = new List <string>();
            var parser = new Rfc4180Parser(
                field => record.Add(field),
                () =>
            {
                Assert.That(record.SequenceEqual(expected[row]), Is.True);
                row += 1;
                record.Clear();
            });
            var length = parser.Parse(input);

            Assert.That(length, Is.EqualTo(expectedLength));
        }