public void InitializesTallyForNewFile() { using (RollingFlatFileTraceListener.TallyKeepingFileStreamWriter writer = new RollingFlatFileTraceListener.TallyKeepingFileStreamWriter(File.Open(fileName, FileMode.Append, FileAccess.Write, FileShare.Read))) { Assert.AreEqual(0L, writer.Tally); } }
public void WritingToFileUpdatesTally() { using (RollingFlatFileTraceListener.TallyKeepingFileStreamWriter writer = new RollingFlatFileTraceListener.TallyKeepingFileStreamWriter(File.Open(fileName, FileMode.Append, FileAccess.Write, FileShare.Read))) { writer.Write("12345"); writer.Flush(); Assert.AreEqual(5L, writer.Tally); } }
public void WritingToFileWithEncodingUpdatesTally() { using (RollingFlatFileTraceListener.TallyKeepingFileStreamWriter writer = new RollingFlatFileTraceListener.TallyKeepingFileStreamWriter(File.Open(fileName, FileMode.Append, FileAccess.Write, FileShare.Read), Encoding.UTF32)) { writer.Write("12345"); writer.Flush(); Assert.AreEqual(20L, writer.Tally); // BOM is not part of tally - minimal fidelity loss on new files. } }
public void InitializesTallyForExistingFile() { File.WriteAllText(fileName, "12345"); using (RollingFlatFileTraceListener.TallyKeepingFileStreamWriter writer = new RollingFlatFileTraceListener.TallyKeepingFileStreamWriter(File.Open(fileName, FileMode.Append, FileAccess.Write, FileShare.Read))) { Assert.AreEqual(5L, writer.Tally); } File.WriteAllText(fileName, "12345"); using (RollingFlatFileTraceListener.TallyKeepingFileStreamWriter writer = new RollingFlatFileTraceListener.TallyKeepingFileStreamWriter(File.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.Read))) { Assert.AreEqual(0L, writer.Tally); } File.WriteAllText(fileName, "12345"); using (RollingFlatFileTraceListener.TallyKeepingFileStreamWriter writer = new RollingFlatFileTraceListener.TallyKeepingFileStreamWriter(File.Open(fileName, FileMode.Truncate, FileAccess.Write, FileShare.Read))) { Assert.AreEqual(0L, writer.Tally); } }