void WriteOutReadIn() { string path = "MikeLiuBidirectional.txt"; using (FileDataWriter <string> w = new FileDataWriter <string>(path)) { w.Append("{First: 'Mike', Last: 'Liu'}"); w.Append("{First: 'Sergey', Last: 'Shandar'}"); Assert.True(File.Exists(path)); } string sampleText = File.ReadAllText(path); Assert.Equal("\"{First: 'Mike', Last: 'Liu'}\"\0\"{First: 'Sergey', Last: 'Shandar'}\"\0", sampleText); //now read using the functionality for FileDatareader using (FileDataReader <string> r = new FileDataReader <string>(path)) { (bool, string)currentTuple = r.Read(); Assert.Equal(true, currentTuple.Item1); Assert.Equal("{First: 'Mike', Last: 'Liu'}", currentTuple.Item2); currentTuple = r.Read(); Assert.Equal(true, currentTuple.Item1); Assert.Equal("{First: 'Sergey', Last: 'Shandar'}", currentTuple.Item2); currentTuple = r.Read(); Assert.Equal(false, currentTuple.Item1); Assert.Equal(null, currentTuple.Item2); } File.Delete(path); }
public void DataShouldReflectTheValues() { Stream s = new MemoryStream(1000); for (int x = 0; x < 1; x++) { AddRecordToStream(s, "10,2010-05-05 10:00"); } s.Position = 0; FileDataColumn[] cols = new[] { new FileDataColumn { ColumnName = "First", ColumnType = typeof(int) }, new FileDataColumn { ColumnName = "Second", ColumnType = typeof(DateTime) } }; IDataReader dataReader = new FileDataReader(s, cols, '\n', ',', Encoding.Unicode, null); bool hasRecords = dataReader.Read(); int first = (int)dataReader[0]; Assert.Equals(first, 10); DateTime second = (DateTime)dataReader[1]; Assert.Equals(second, new DateTime(2010, 5, 5, 10, 0, 0)); }
public void RecordManipulatorShouldSuccessFullyManipulate() { Stream s = new MemoryStream(1000); for (int x = 0; x < 10; x++) { AddRecordToStream(s, string.Format("{0}\n", (x * 10))); } s.Position = 0; FileDataColumn[] cols = new[] { new FileDataColumn { ColumnName = "First", ColumnType = typeof(int) } }; IDataReader dataReader = new FileDataReader( s, cols, '\n', ';', Encoding.Unicode, record => { int currentValue = record.GetInt32(0); record.SetValue(0, currentValue * 2); }); for (int x = 0; x < 10; x++) { dataReader.Read(); Assert.Equals(dataReader[0], x * 10 * 2); } }
public void ReadShouldReturnTrueIfThereAreAValidRecord() { Stream s = new MemoryStream(1000); for (int x = 0; x < 1; x++) { AddRecordToStream(s, "10,2010-05-05 10:00"); } s.Position = 0; FileDataColumn[] cols = new[] { new FileDataColumn { ColumnName = "First", ColumnType = typeof(int) }, new FileDataColumn { ColumnName = "Second", ColumnType = typeof(DateTime) } }; IDataReader dataReader = new FileDataReader(s, cols, '\n', ',', Encoding.Unicode, null); bool hasRecords = dataReader.Read(); Assert.IsTrue(hasRecords); }
public void DoubleShouldBeSupported() { Stream s = new MemoryStream(1000); for (int x = 0; x < 1; x++) { AddRecordToStream(s, "10,0008\n"); } s.Position = 0; FileDataColumn[] cols = new[] { new FileDataColumn { ColumnName = "First", ColumnType = typeof(double) } }; IDataReader dataReader = new FileDataReader(s, cols, '\n', ';', Encoding.Unicode, null); bool hasRecords = dataReader.Read(); double number = (double)dataReader[0]; Assert.Equals(number, 10.0008); }
public void DateTimeShouldBeSupported() { Stream s = new MemoryStream(1000); for (int x = 0; x < 1; x++) { AddRecordToStream(s, "2010-05-05 10:00:01.005"); } s.Position = 0; FileDataColumn[] cols = new[] { new FileDataColumn { ColumnName = "First", ColumnType = typeof(DateTime) } }; IDataReader dataReader = new FileDataReader(s, cols, '\n', ',', Encoding.Unicode, null); dataReader.Read(); DateTime dateTime = (DateTime)dataReader[0]; Assert.Equals(dateTime, new DateTime(2010, 5, 5, 10, 0, 1, 5)); }
public void BoolShouldBeSupported() { Stream s = new MemoryStream(1000); for (int x = 0; x < 1; x++) { AddRecordToStream(s, "true"); } s.Position = 0; FileDataColumn[] cols = new[] { new FileDataColumn { ColumnName = "First", ColumnType = typeof(bool) } }; IDataReader dataReader = new FileDataReader(s, cols, '\n', ';', Encoding.Unicode, null); bool hasRecords = dataReader.Read(); bool boolValue = (bool)dataReader[0]; Assert.IsTrue(boolValue); }