Example #1
0
        public void TestCheckNoRead([Values(true, false)] bool withHeader)
        {
            const string input = "azerty\nazerty";

            using (ICsvReader reader = CreateCsvReader(input, withHeader))
            {
                Assert.DoesNotThrow(() => { bool b = reader.WithHeader; }, "Access to WithHeader should not throw exception before call to Read");
                Assert.DoesNotThrow(() => { char c = reader.Separator; }, "Access to Separator should not throw exception before call to Read");
                Assert.DoesNotThrow(() => reader.GetCurrentLine(), "Access to GetCurrentLine() should not throw exception before call to Read");
                if (withHeader)
                {
                    Assert.DoesNotThrow(() => reader.GetColumnsCount(), "Access to GetColumnsCount should not throw exception before call to Read");
                }
                else
                {
                    Assert.Throws <CsvReaderNoReadCallException>(() => reader.GetColumnsCount(), "Access to GetColumnsCount should throw CsvReaderNoReadCallException before call to Read");
                }
                Assert.DoesNotThrow(() => reader.GetHeaders(), "Access to GetHeaders() should not throw exception before call to Read");
                Assert.Throws <CsvReaderNoReadCallException>(() => reader.GetValue(0), "Access to GetValue should throw CsvReaderNoReadCallException before call to Read");
                Assert.DoesNotThrow(() => { bool b = reader.EndOfStream; }, "Access to EndOfStream should not throw exception before call to Read");

                Assert.DoesNotThrow(() => reader.Read(), "Call to Read() should not throw exception");

                Assert.DoesNotThrow(() => { bool b = reader.WithHeader; }, "Access to WithHeader should not throw exception after call to Read");
                Assert.DoesNotThrow(() => { char c = reader.Separator; }, "Access to Separator should not throw exception after call to Read");
                Assert.DoesNotThrow(() => reader.GetCurrentLine(), "Access to GetCurrentLine() should not throw exception after call to Read");
                Assert.DoesNotThrow(() => reader.GetColumnsCount(), "Access to GetColumnsCount should not throw exception  after call to Read");
                Assert.DoesNotThrow(() => reader.GetHeaders(), "Access to GetHeaders() should not throw exception after call to Read");
                Assert.DoesNotThrow(() => reader.GetValue(0), "Access to GetValue should not throw exception  after call to Read");
                Assert.DoesNotThrow(() => { bool b = reader.EndOfStream; }, "Access to EndOfStream should not throw exception before after to Read");
            }
        }
Example #2
0
        public void TestGetCurrentLine([Values(true, false)] bool withHeader)
        {
            const int     count = 10;
            StringBuilder sb    = new StringBuilder();

            for (int i = 0; i < count; i++)
            {
                sb.Append("a\r\n");
            }

            using (ICsvReader reader = CreateCsvReader(sb.ToString(), withHeader))
            {
                int expectedLine = -1;
                Assert.IsTrue(reader.GetCurrentLine() == expectedLine, "No the expected current line");
                //
                for (int i = 0; i < (count - (withHeader ? 1 : 0)); i++)
                {
                    Assert.IsTrue(reader.Read(), "Can't read!");
                    expectedLine++;
                    Assert.IsTrue(reader.GetCurrentLine() == expectedLine, "No the expected current line");
                }

                Assert.IsFalse(reader.Read(), "Should be end of file");
                Assert.IsTrue(reader.GetCurrentLine() == expectedLine, "Current must not change after and of file");
            }
        }