public void Process(string inputFile) { var reader = new CSVReaderWriter(); reader.Open(inputFile, CSVReaderWriter.Mode.Read); string column1, column2; while(reader.Read(out column1, out column2)) { _mailShot.SendMailShot(column1, column2); } reader.Close(); }
public void ReadWrite_OpenRealFilesForReadAndWriteForOneInstance_Success() { // Arrange var mockWriter = new Mock<IWriter>(); #pragma warning disable 618 // obsolete warning using (var readerWriterUnderTest = new CSVReaderWriter(mockWriter.Object)) { // Act // writing string[] columns = { "1", "2" }; readerWriterUnderTest.Write(columns); // reading readerWriterUnderTest.Open(_testFileForRead, CSVReaderWriter.Mode.Read); var isReadSuccess = readerWriterUnderTest.Read(out columns); // Assert mockWriter.Verify(writer => writer.Write(It.IsAny<string[]>()), Times.Once); Assert.IsTrue(isReadSuccess); } #pragma warning restore 618 }
public void Read_UselessParamsPassed_ReturnSuccessAndNotSuccess() { // Arrange var columnsInLines = new List<string[]> { new [] {"123"}, }; var mockReader = CreateMockReader(columnsInLines); #pragma warning disable 618 // obsolete warning using (var readerWriterUnderTest = new CSVReaderWriter(mockReader.Object)) { // Act var column1 = string.Empty; var column2 = string.Empty; var isReadSuccess = readerWriterUnderTest.Read(column1, column2); Assert.IsTrue(isReadSuccess); isReadSuccess = readerWriterUnderTest.Read(column1, column2); Assert.IsFalse(isReadSuccess); #pragma warning restore 618 } }
public void Read_StreamWasNotOpened_ThrowException() { // Arrange var columnsInLines = new List<string[]> { new [] {"123"}, }; var mockReader = CreateMockReader(columnsInLines); #pragma warning disable 618 // obsolete warning var readerWriterUnderTest = new CSVReaderWriter(mockReader.Object); #pragma warning restore 618 readerWriterUnderTest.Close(); // Act var column1 = string.Empty; var column2 = string.Empty; #pragma warning disable 618 // obsolete warning readerWriterUnderTest.Read(column1, column2); #pragma warning restore 618 }
public void Read_ReadLines_Success() { // Arrange var columnsInLines = new List<string[]> { new [] {"123", "456", }, new [] {"789", "101", }, }; var mockReader = CreateMockReader(columnsInLines); using (var readerWriterUnderTest = new CSVReaderWriter(mockReader.Object)) { // Act string[] columns; var isReadSuccess = readerWriterUnderTest.Read(out columns); Assert.IsTrue(isReadSuccess); Assert.AreEqual(2, columns.Length); Assert.AreEqual("123", columns[0]); Assert.AreEqual("456", columns[1]); isReadSuccess = readerWriterUnderTest.Read(out columns); Assert.IsTrue(isReadSuccess); Assert.AreEqual(2, columns.Length); Assert.AreEqual("789", columns[0]); Assert.AreEqual("101", columns[1]); isReadSuccess = readerWriterUnderTest.Read(out columns); Assert.IsFalse(isReadSuccess); Assert.IsNull(columns); } }
public void Read_ReadDisposed_ThrowException() { // Arrange var columnsInLines = new List<string[]> { new [] {"1", "2"}, new [] {"3", "4"}, }; var mockReader = CreateMockReader(columnsInLines); using (var readerWriterUnderTest = new CSVReaderWriter(mockReader.Object)) { // Act string[] columns; readerWriterUnderTest.Read(out columns); readerWriterUnderTest.Dispose(); readerWriterUnderTest.Read(out columns); } }
public void Read_OpenRealFile_Success() { // Arrange #pragma warning disable 618 // obsolete warning using (var readerWriterUnderTest = new CSVReaderWriter()) { // Act // reading readerWriterUnderTest.Open(_testFileForRead, CSVReaderWriter.Mode.Read); string[] columns; var isReadSuccess = readerWriterUnderTest.Read(out columns); // Assert Assert.IsTrue(isReadSuccess); } #pragma warning restore 618 }
public void Read_FieldsLessThenNeed_ThrowException() { // Arrange var columnsInLines = new List<string[]> { new [] {"789"}, }; var mockReader = CreateMockReader(columnsInLines); using (var readerWriterUnderTest = new CSVReaderWriter(mockReader.Object)) { // Act string[] columns; readerWriterUnderTest.Read(out columns); } }