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 TestGetHeaders([Values(true, false)] bool withHeader) { const string input = "azerty,azerty\r\ntttt,ttttt"; string[] exceptedResult = withHeader ? new[] { "azerty", "azerty" } : Array.Empty <string>(); using (ICsvReader reader = CreateCsvReader(input, withHeader)) { string[] header = reader.GetHeaders(); Assert.AreEqual(exceptedResult.Length, header.Length, "Not the excepted length"); for (int i = 0; i < exceptedResult.Length; i++) { Assert.AreEqual(exceptedResult[i], header[i], "Not the excepted value at i={0}", i); } Assert.IsTrue(reader.Read(), "Can't read first line"); header = reader.GetHeaders(); Assert.AreEqual(exceptedResult.Length, header.Length, "Not the excepted length after read"); for (int i = 0; i < exceptedResult.Length; i++) { Assert.AreEqual(exceptedResult[i], header[i], "Not the excepted value at i={0} after read", i); } } }