public void CountLinesWithSystemNewLine(string text, int expectedLines) { using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(text))) using (var reader = new PositionAwareStreamReaderSystem(stream, new EncodingOptions())) { int lineCount = 0; while (reader.ReadLine() != null) { lineCount += 1; } Assert.AreEqual(expectedLines, lineCount, $"Unexpected lines:\n{text}"); } }
public void ReadLinesWithSystemNewLine(string text, int expectedLines) { using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(text))) using (var reader = new PositionAwareStreamReaderSystem(stream, new EncodingOptions())) { int lineCount = 0; while (true) { string line = reader.ReadLine(); if (line == null) { break; } lineCount += 1; StringAssert.StartsWith($"Line {lineCount}", line, $"Invalid line: {line}"); } Assert.AreEqual(expectedLines, lineCount, $"Unexpected lines:\n{text}"); } }
private void compareReaderImplementations(string fileName, Encoding enc, int maxPosition) { string DataPath = "..\\..\\data\\"; EncodingOptions encOpts = new EncodingOptions(); encOpts.Encoding = enc; using (Stream s1 = new FileStream(DataPath + fileName, FileMode.Open, FileAccess.Read)) using (Stream s2 = new FileStream(DataPath + fileName, FileMode.Open, FileAccess.Read)) { using (ILogStreamReader r1 = new PositionAwareStreamReaderLegacy(s1, encOpts)) using (ILogStreamReader r2 = new PositionAwareStreamReaderSystem(s2, encOpts)) { for (int lineNum = 0; ; lineNum++) { string line1 = r1.ReadLine(); string line2 = r2.ReadLine(); if (line1 == null && line2 == null) { break; } Assert.AreEqual(line1, line2, "File " + fileName); if (r1.Position != maxPosition) { Assert.AreEqual(r1.Position, r2.Position, "Line " + lineNum + ", File: " + fileName); } else { //Its desired that the position of the new implementation is 2 bytes ahead to fix the problem of empty lines every time a new line is appended. Assert.AreEqual(r1.Position, r2.Position - 2, "Line " + lineNum + ", File: " + fileName); } } } } }