public async Task TestParseInvalidLines()
        {
            var parser  = new SingleLineJsonTextParser(NullLogger.Instance, null, null, null);
            var context = new LogContext {
                FilePath = _testFile
            };
            var records = new List <IEnvelope <JObject> >();

            await File.AppendAllTextAsync(_testFile, $"{{\"a\":1}}{Environment.NewLine}");

            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Single(records);
            records.Clear();

            // write an in valid json line
            await File.AppendAllTextAsync(_testFile, $"{{\"b\":{Environment.NewLine}");

            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Empty(records);

            // write another valid line, make sure the parser moves on
            await File.AppendAllTextAsync(_testFile, $"{{\"c\":3}}{Environment.NewLine}");

            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Single(records);
        }
        public async Task TestParseInterleavedWrites()
        {
            var parser  = new SingleLineJsonTextParser(NullLogger.Instance, null, null, null);
            var context = new LogContext {
                FilePath = _testFile
            };
            var records = new List <IEnvelope <JObject> >();

            await File.AppendAllTextAsync(_testFile, $"{{\"a\":1}}{Environment.NewLine}");

            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Single(records);
            records.Clear();

            await File.AppendAllTextAsync(_testFile, $"{{\"b\":");

            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Empty(records);

            await File.AppendAllTextAsync(_testFile, $"2}}{Environment.NewLine}");

            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Single(records);
        }
        public async Task TestParseLongRecords(int size)
        {
            var parser  = new SingleLineJsonTextParser(NullLogger.Instance, null, null, null);
            var context = new LogContext {
                FilePath = _testFile
            };
            var records = new List <IEnvelope <JObject> >();
            var value   = new string('a', size);

            File.AppendAllText(_testFile, $"{{\"a\":\"{value}\"}}{Environment.NewLine}");
            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Single(records);
            Assert.Equal(value, (string)records[0].Data["a"]);

            records.Clear();
            File.AppendAllText(_testFile, $"{{\"b\":");
            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Empty(records);

            File.AppendAllText(_testFile, $"\"{value}\"}}{Environment.NewLine}");
            await parser.ParseRecordsAsync(context, records, 100);

            Assert.Single(records);
            Assert.Equal(value, (string)records[0].Data["b"]);
        }
        public async Task TestJsonLog(string timestampField, string timestampFormat)
        {
            await File.WriteAllTextAsync(_testFile, LOG);

            var parser  = new SingleLineJsonTextParser(NullLogger.Instance, timestampField, timestampFormat, null);
            var records = new List <IEnvelope <JObject> >();
            await parser.ParseRecordsAsync(new LogContext { FilePath = _testFile }, records, 100);

            Assert.Equal(2, records.Count);
            var record0 = records[0] as LogEnvelope <JObject>;

            Assert.Equal(new DateTime(2018, 9, 21, 8, 38, 50, 972), record0.Timestamp);
            Assert.Equal("UserProfile", record0.Data["ul-log-data"]["method_name"]);
            Assert.Equal("INFO", record0.Data["ul-tag-status"]);
        }