Пример #1
0
 public void TestDictionaryRemoveEntries()
 {
     using (var reader = new CsvDictionaryStreamReader("test.csv", new CsvStreamOptions()
     {
         RemoveEmptyEntries = true
     }))
     {
         var entries = reader.AsEnumerable().ToList();
         Assert.AreEqual(entries.Count(), 20);
     }
 }
Пример #2
0
        public void TestRowSeperator()
        {
            var options = new CsvStreamOptions()
            {
                HeaderRowDelimiter = "\r\n", RowDelimiter = "\r\n"
            };

            using (var reader = new CsvDictionaryStreamReader("./test2.csv", options))
            {
                var result = reader.AsEnumerable().ToList();
                Assert.AreEqual(result.Count, 39);
            }
        }
Пример #3
0
        public void TestDictionaryStringParser()
        {
            using (var reader = new CsvDictionaryStreamReader(StreamHelper.GenerateStream("name,type,cost,id,date\r\nClaws,Attachment,10,\"34.5\",03/27/1987")))
            {
                var result = reader.AsEnumerable().FirstOrDefault();

                Assert.AreEqual(result["name"], "Claws");
                Assert.AreEqual(result["type"], "Attachment");
                Assert.AreEqual(result["cost"], "10");
                Assert.AreEqual(result["id"], "34.5");
                Assert.AreEqual(result["date"], "03/27/1987");
            }
        }
Пример #4
0
        public void TestFileDictionaryNoHeaders()
        {
            using (var reader = new CsvDictionaryStreamReader("./large-csv.csv", new CsvStreamOptions()
            {
                ParseHeaders = false, DataRow = 0
            }))
            {
                var result = reader.AsEnumerable(x => $"v{x}").FirstOrDefault();

                for (var i = 0; i < result.Count; ++i)
                {
                    Assert.AreEqual(result[$"v{i}"], $"Column {i}");
                }
            }
        }
Пример #5
0
        public void TestDictionaryNoHeaders()
        {
            using (var reader = new CsvDictionaryStreamReader(StreamHelper.GenerateStream("Claws,Effect,10,60.05,9-5-1029"), new CsvStreamOptions()
            {
                ParseHeaders = false, DataRow = 0
            }))
            {
                var result = reader.AsEnumerable(x => $"v{x}").FirstOrDefault();

                Assert.AreEqual(result["v0"], "Claws");
                Assert.AreEqual(result["v1"], "Effect");
                Assert.AreEqual(result["v2"], "10");
                Assert.AreEqual(result["v3"], "60.05");
                Assert.AreEqual(result["v4"], "9-5-1029");
            }
        }