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"); } }
public void TestGetColumnsCount([Values(true, false)] bool withHeader) { const string input = "azerty,azerty\r\ntttt,ttttt"; using (ICsvReader reader = CreateCsvReader(input, withHeader)) { if (withHeader) { Assert.AreEqual(2, reader.GetColumnsCount(), "Not the excepted ColumnsCount before call to Read"); } else { Assert.Throws <CsvReaderNoReadCallException>(() => reader.GetColumnsCount(), "Access to GetColumnsCount should throw CsvReaderNoReadCallException before call to Read"); } Assert.IsTrue(reader.Read(), "Can't read first line"); Assert.AreEqual(2, reader.GetColumnsCount(), "Not the excepted ColumnsCount after call to Read"); } }