public void TestWriteRecord()
{
string filename = Path.Combine(CsvOutputDirectory, "test-write-record.csv");
string[] record = new string[] { "AAAA", "BBBB", "CCCC" };
const int lenRecord = 14; // Strings, commas.
Stream stream = null;
try
{
// Create the temp file (or overwrite if already there).
stream = File.Open(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
stream.SetLength(0);
stream.Close();
// Check it's empty.
FileInfo info = new FileInfo(filename);
Assert.AreEqual(0, info.Length, "File length not zero.");
// Open for append
stream = File.OpenWrite(filename);
// Append a record.
CsvWriter writer = new CsvWriter(stream);
writer.WriteRecord(record);
stream.Flush();
stream.Close();
// Check it's not empty.
info = new FileInfo(filename);
Assert.AreEqual(lenRecord, info.Length, "File length not increased.");
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
finally
{
if (stream != null)
{
stream.Close();
//File.Delete( filename ); // Keep it for debugging.
}
}
}