Пример #1
0
        public void Process(string inputFile)
        {
            using (_csvReaderWriter)
            {
                _csvReaderWriter.Open(inputFile, CSVReaderWriter.Mode.Read);

                string column1, column2;

                while (_csvReaderWriter.Read(out column1, out column2))
                {
                    _mailShot.SendMailShot(column1, column2);
                }
            }
        }
        private void AssertReturnsTrueOrThrowsException(ICsvReaderWriter csvReaderWriter)
        {
            // Arrange
            const string dataFile  = @"test_data\contacts.csv";
            var          lineCount = File.ReadAllLines(dataFile).Length;

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

            // Act and Assert
            for (var i = 0; i < lineCount; i++)
            {
                Assert.AreEqual(true, csvReaderWriter.Read("", ""));
            }
            Assert.Throws <NullReferenceException>(() => csvReaderWriter.Read("", ""));
        }
        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);
        }
        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]);
        }