private void AssertWritesColumns(ICsvReaderWriter csvReaderWriter)
        {
            // Arrange
            const string dataFile = @"test_data\emptyFile.csv";

            csvReaderWriter.Open(dataFile, CSVReaderWriterForAnnotation.Mode.Write);

            // Act
            csvReaderWriter.Write("Column 1A", "Column 1B");
            csvReaderWriter.Write("Column 2A", "Column 2B");
            csvReaderWriter.Close();
            var linesAfterWrite = File.ReadAllLines(dataFile);

            // Assert

            // Check only correct number of lines have been written
            Assert.AreEqual(2, linesAfterWrite.Length);

            // Check line added is expected string
            Assert.AreEqual("Column 1A\tColumn 1B", linesAfterWrite[0]);
            Assert.AreEqual("Column 2A\tColumn 2B", linesAfterWrite[1]);
        }
        private void AssertReadsAllLines(ICsvReaderWriter csvReaderWriter)
        {
            // Arrange
            const string dataFile = @"test_data\contacts.csv";
            var          allLines = File.ReadAllLines(dataFile);

            csvReaderWriter.Open(dataFile, CSVReaderWriterForAnnotation.Mode.Read);

            // Act and Assert
            var lineNumber = 0;

            while (csvReaderWriter.Read(out var column1, out var column2))
            {
                var nextLine = allLines[lineNumber];
                var columns  = nextLine.Split('\t');
                Assert.AreEqual(columns[0], column1);
                Assert.AreEqual(columns[1], column2);
                lineNumber++;
            }
            csvReaderWriter.Close();
            Assert.AreEqual(allLines.Length, lineNumber);
        }
Ejemplo n.º 3
0
 public void ShouldNotThrow_IfCloseTwice()
 {
     _csvReaderWriter.Close();
     _csvReaderWriter.Close();
 }