public void Close_with_Mode_Read_closes_CsvReader() { //arrange _csvReaderWriter.Open(FileName, Mode.Read); //act _csvReaderWriter.Close(); //assert _csvStreamReader.Verify(c => c.Close()); }
public void Should_ReadThrowException_WhenReaderWriterIsClosed() { // Arrange _subject.Open("TestFileName.csv", CSVReaderWriter.Mode.Read); _subject.Close(); // Act // Assert var ex = Assert.Throws <ApplicationException>(() => _subject.Read(out var column1, out var column2)); Assert.That(ex.Message, Is.EqualTo("File is closed or hasn't been opened in read mode.")); }
public void Open_For_Write_When_WriterStream_Initialized_Write_Data() { var csvReadWriter = new CSVReaderWriter(); csvReadWriter.Open(@"test_data\test.txt", CSVReaderWriter.Mode.Write); csvReadWriter.Write("test line 1 Column 1", "test line 1 Column 2");// The functionality forces to create the file with two columns which is quite rigid. csvReadWriter.Close(); string column1 = null; string column2 = null; csvReadWriter.Open(@"test_data\test.txt", CSVReaderWriter.Mode.Read); csvReadWriter.Read(out column1, out column2); csvReadWriter.Close(); Assert.AreEqual("test line 1 Column 1", column1); Assert.AreEqual("test line 1 Column 2", column2); }
private Tuple <int, Exception> CountLines(string filename, bool withOutValues) { var csvReader = new CSVReaderWriter(); string string1 = null; string string2 = null; Exception ex = null; csvReader.Open(filename, CSVReaderWriter.Mode.Read); int lineCount = 0; try { while (withOutValues ? csvReader.Read(out string1, out string2) : csvReader.Read(string1, string2)) { lineCount++; } } catch (Exception e) { ex = e; } csvReader.Close(); return(new Tuple <int, Exception>(lineCount, ex)); }
public void Should_close_the_state() { _CSVReaderWriter.Open(TestInputFile, CSVReaderWriter.Mode.Write); _CSVReaderWriter.Close(); Assert.That(_stream.CanRead, Is.EqualTo(false)); }
public void canOpenAndCloseFile() { CSVReaderWriter rw = new CSVReaderWriter(); rw.Open(TestInputFile, Mode.Read); rw.Close(); }
public void WriteCsvFile() { //Write test file using (var writer = new CSVReaderWriter()) { writer.Open(_testWriteDataFile, CSVReaderWriter.Mode.Write); foreach (var testAddress in _mailAddressTests) { writer.Write(testAddress.Name, testAddress.Address); } writer.Close(); } //Read test file var contacts = new List <Contact>(); using (var reader = new CSVReaderWriter()) { reader.Open(_testWriteDataFile, CSVReaderWriter.Mode.Read); string column1, column2; while (reader.Read(out column1, out column2)) { contacts.Add(new Contact(column1, column2)); } reader.Close(); } CollectionAssert.AreEqual(_mailAddressTests, contacts); }
public void Open_Method_to_write_Should_not_throw_Exception() { var csvReaderWriter = new CSVReaderWriter(); Assert.DoesNotThrow(() => csvReaderWriter.Open(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TestOutputFile), CSVReaderWriter.Mode.Write)); csvReaderWriter.Close(); }
public void Write_Method_Should_not_throw_Exception_when_empty_string_array_is_passed() { var csvReaderWriter = new CSVReaderWriter(); Assert.DoesNotThrow(() => csvReaderWriter.Write(new string[] {})); csvReaderWriter.Close(); }
public void Write_WriterIsDisposed_ThrowException() { var csv = new CSVReaderWriter(It.IsAny <ICSVReader>(), null); csv.Close(); var ex = Assert.Throws <NullReferenceException>(() => csv.Write(It.IsAny <string[]>())); Assert.AreEqual("The file writer is closed. Please reopen it.", ex.Message); }
public void CloseCleansReader() { var readerMock = new Mock <ICsvFileReader>(); readerMock.Setup(x => x.Close()); var sut = new CSVReaderWriter(readerMock.Object, null); sut.Close(); readerMock.Verify(x => x.Close(), Times.Once); }
public void CloseCleansWriter() { var writerMock = new Mock <ICsvFileWriter>(); writerMock.Setup(x => x.Close()); var sut = new CSVReaderWriter(null, writerMock.Object); sut.Close(); writerMock.Verify(x => x.Close(), Times.Once); }
public void canWriteToFile() { CSVReaderWriter rw = new CSVReaderWriter(); //write could generate a random string to compare with the read but keeping it simple for now rw.Open(TestInputFileForEditing, Mode.Write); rw.Write(new string[] { "some data col1 asdfasdfasdf", "some more data for col2" }); rw.Close(); //read what was written rw.Open(TestInputFileForEditing, Mode.Read); string col1 = "", col2 = ""; bool result = rw.Read(out col1, out col2); rw.Close(); Assert.That(col1, Is.EquivalentTo("some data col1 asdfasdfasdf")); Assert.That(col2, Is.EquivalentTo("some more data for col2")); Assert.That(result, Is.True); }
public void Read_ReaderIsDisposed_ThrowException() { var mockReader = new Mock <ICSVReader>(); var csv = new CSVReaderWriter(mockReader.Object, It.IsAny <ICSVWriter>()); csv.Close(); string c1; string c2; var ex = Assert.Throws <NullReferenceException>(() => csv.Read(out c1, out c2)); Assert.AreEqual("The file reader is closed. Please reopen it.", ex.Message); }
public void Write_Method_Should_write_to_the_file() { var csvReaderWriter = new CSVReaderWriter(); csvReaderWriter.Open(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TestOutputFile), CSVReaderWriter.Mode.Write); csvReaderWriter.Write(new string[] { "This", "should", "be", "written", "to", "the", "file" }); csvReaderWriter.Close(); Assert.True(File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TestOutputFile))); File.Delete(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TestOutputFile)); }
public void canReadFileDisgardingOutput() { CSVReaderWriter rw = new CSVReaderWriter(); rw.Open(TestInputFile, Mode.Read); string col1 = "", col2 = ""; bool result = rw.Read(col1, col2); rw.Close(); Assert.That(result, Is.True); }
public void Process(string inputFile) { _reader.Open(inputFile, CSVReaderWriter.Mode.Read); string column1, column2; while (_reader.Read(out column1, out column2)) { _mailShot.SendMailShot(column1, column2); } _reader.Close(); }
public void canNotWriteToFileIfInReadMode() { CSVReaderWriter rw = new CSVReaderWriter(); try { rw.Open(TestInputFileForEditing, Mode.Read); rw.Write(new string[] { "some data col1", "some more data for col2" }); } finally { rw.Close(); } }
public void ShouldOpenCSVReader() { _csvReaderWriter.Open(Filename, CSVReaderWriter.Mode.Read); _csvReader.Verify(x => x.Open(Filename)); _csvReaderWriter.Close(); }
public void Should_write_columns_faster_with_updates() { CSVReaderWriter csvReaderWriter = new CSVReaderWriter(); string fileName = GetTempFilePath(); csvReaderWriter.Open(fileName, CSVReaderWriter.Mode.Write); DateTime startTime = DateTime.Now; for (int i = 0; i < 10000; i++) { csvReaderWriter.Write("COL 1", "column 2", "Test"); } DateTime endTime = DateTime.Now; csvReaderWriter.Close(); TimeSpan updatedDuration = endTime.Subtract(startTime); CSVReaderWriterForAnnotation oldCsvReaderWriter = new CSVReaderWriterForAnnotation(); fileName = GetTempFilePath(); oldCsvReaderWriter.Open(fileName, CSVReaderWriterForAnnotation.Mode.Write); startTime = DateTime.Now; for (int i = 0; i < 100000; i++) { oldCsvReaderWriter.Write("COL 1", "column 2", "Test"); } endTime = DateTime.Now; oldCsvReaderWriter.Close(); TimeSpan oldDuration = endTime.Subtract(startTime); string newTime = updatedDuration.ToString("c"); string oldTime = oldDuration.ToString("c"); System.Diagnostics.Debug.Write(newTime); System.Diagnostics.Debug.Write(oldTime); Assert.Less(updatedDuration.Ticks, oldDuration.Ticks); }
public void Read_When_Only_First_Column_Exists_Throws_Exception() { var csvReadWriter = new CSVReaderWriter(); csvReadWriter.Open(@"test_data\test.txt", CSVReaderWriter.Mode.Write); csvReadWriter.Write("test line 1 Column 1");// The Read functionality forces to create the file with two columns which is quite rigid. csvReadWriter.Close(); string column1 = null; string column2 = null; csvReadWriter.Open(@"test_data\test.txt", CSVReaderWriter.Mode.Read); Assert.Throws <IndexOutOfRangeException>(() => csvReadWriter.Read(out column1, out column2)); }
public void Close_when_open_with_read_should_set_read_stream_to_null() { //arrange var sut = new CSVReaderWriter(); //act sut.Open(TestInputFile, CSVReaderWriter.Mode.Read); sut.Close(); //assert Assert.That(sut.ReadStreamValid, Is.False); }
public void Open_when_mode_is_read_and_file_is_valid_will_return_ReadStreamValid() { //arrange var sut = new CSVReaderWriter(); //act sut.Open(TestInputFile, CSVReaderWriter.Mode.Read); //assert Assert.That(sut.ReadStreamValid, "Unable to open text file"); //clean up sut.Close(); }
public void Read_WithOut_Split() { var csvReader = new CSVReaderWriter(); string string1 = null; string string2 = null; csvReader.Open(TestInputFileBlank, CSVReaderWriter.Mode.Read); var output = csvReader.Read(out string1, out string2); csvReader.Close(); Assert.That(output, Is.True); Assert.That(string1, Is.EqualTo("Shelby Macias")); Assert.That(string2, Is.EqualTo("3027 Lorem St.|Kokomo|Hertfordshire|L9T 3D5|England")); }
public void canReadFileKeepOutput() { CSVReaderWriter rw = new CSVReaderWriter(); rw.Open(TestInputFile, Mode.Read); string col1 = "", col2 = ""; bool result = rw.Read(out col1, out col2); rw.Close(); Assert.That(col1, Is.Not.Empty); Assert.That(col2, Is.Not.Empty); Assert.That(result, Is.True); }
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)) { emailProvider.Send(column1, column2); } reader.Close(); }
public void Read_Method_Should_read_first_line_of_file() { var csvReaderWriter = new CSVReaderWriter(); csvReaderWriter.Open(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, TestInputFile), CSVReaderWriter.Mode.Read); string column1, column2; csvReaderWriter.Read(out column1, out column2); csvReaderWriter.Close(); Assert.IsTrue(string.Equals(column1, "Shelby Macias")); Assert.IsTrue(string.Equals(column2, "3027 Lorem St.|Kokomo|Hertfordshire|L9T 3D5|England")); }
public void Process(string inputFile) { var reader = new CSVReaderWriter(new CSVReader(), new CSVWriter()); reader.Open(inputFile, CSVReaderWriter.Mode.Read); string column1, column2; while (reader.Read(out column1, out column2)) { _mailShot.SendMailShot(column1, column2); } reader.Close(); }
public void Read_EdgeCase_Open_read_no_tabs_file() { //arrange var sut = new CSVReaderWriter(); string column1 = ""; string column2 = ""; //act sut.Open(TestOtherFile, CSVReaderWriter.Mode.Read); sut.Read(out column1, out column2); sut.Close(); //assert Assert.That(sut.ReadStreamValid, Is.False); }
public void canNotReadFromFileIfInWriteMode() { CSVReaderWriter rw = new CSVReaderWriter(); try { rw.Open(TestInputFileForEditing, Mode.Write); string col1 = "", col2 = ""; bool result = rw.Read(col1, col2); } finally { rw.Close(); } }