Exemplo n.º 1
0
        public void TestDataOriginal()
        {
            const String line1 = "10/26/18 15:09:26 2> [fetch] hell";
            const String line2 = "10/26/18 15:09:26 2> o";

            // test with one line of data
            var entry1 = new LogEntry();

            entry1.AddLine(line1);
            entry1.Parse();

            Assert.Equal("hell", entry1.Data);
            Assert.Equal(line1, entry1.DataOriginal);

            // test with two lines of data
            var entry2 = new LogEntry();

            entry2.AddLine(line1);
            entry2.AddLine(line2);
            entry2.Parse();

            Assert.Equal("hello", entry2.Data);
            var dataOriginal = line1 + System.Environment.NewLine + line2;

            Assert.Equal(entry2.DataOriginal, dataOriginal);
        }
Exemplo n.º 2
0
        public void TestCompileLines()
        {
            const String line1 = "10/26/18 15:09:26 1> [compile] SELECT SYSDATE F";
            const String line2 = "10/26/18 15:09:26 1> ROM DUAL";

            var entry = new LogEntry();

            entry.AddLine(line1);
            entry.AddLine(line2);
            entry.Parse();

            Assert.True(entry.Parsed);
            Assert.Equal(2, entry.Lines.Count);
            Assert.Equal("compile", entry.Type);
            Assert.Equal("SELECT SYSDATE FROM DUAL", entry.Data);
        }
Exemplo n.º 3
0
        public void TestConnectLine()
        {
            const String line1      = "10/26/18 15:09:26 1> [connect] dbname = XE username = SCOTT";
            DateTime     timeStamp1 = new DateTime(2018, 10, 26, 15, 9, 26);

            var entry1 = new LogEntry();

            entry1.AddLine(line1);
            entry1.Parse();
            Assert.True(entry1.Parsed);
            Assert.Equal(1, entry1.Lines.Count);
            Assert.True(timeStamp1.Equals(entry1.TimeStamp));
            Assert.Equal("1", entry1.Level);
            Assert.Equal("connect", entry1.Type);
            Assert.Equal("dbname = XE username = SCOTT", entry1.Data);

            const string line2      = "11/2/18 15:09:26 1> [connect] dbname = XE username = SCOTT";
            DateTime     timeStamp2 = new DateTime(2018, 11, 2, 15, 9, 26);

            var entry2 = new LogEntry();

            entry2.AddLine(line2);
            entry2.Parse();
            Assert.True(entry2.Parsed);
            Assert.Equal(1, entry2.Lines.Count);
            Assert.True(timeStamp2.Equals(entry2.TimeStamp));
            Assert.Equal("1", entry2.Level);
            Assert.Equal("connect", entry1.Type);
            Assert.Equal("dbname = XE username = SCOTT", entry2.Data);
        }
Exemplo n.º 4
0
        public async Task <List <LogEntry> > ParseStream(Stream stream, LogSource file)
        {
            return(await Task.Run(() =>
            {
                LogEntry currentEntry = null;
                var logEntries = new List <LogEntry>();
                using (var bs = new BufferedStream(stream))
                {
                    using (var reader = new StreamReader(bs, Encoding.Default))
                    {
                        string line = null;
                        while ((line = reader.ReadLine()) != null)
                        {
                            var entry = ParseLine(line, file);
                            if (entry != null)
                            {
                                logEntries.Add(entry);
                                currentEntry = entry;
                            }
                            else
                            {
                                currentEntry?.AddLine(line);
                            }
                        }
                    }
                }

                return logEntries;
            }));
        }
Exemplo n.º 5
0
        public void TestAddLine()
        {
            var entry = new LogEntry();

            entry.AddLine("newLine");
            Assert.False(entry.Parsed);
            Assert.NotEmpty(entry.Lines);
            Assert.Equal(1, entry.Lines.Count);
        }
Exemplo n.º 6
0
        public void TestFetch()
        {
            const String line  = "10/26/18 15:09:26 2> [fetch]";
            var          entry = new LogEntry();

            entry.AddLine(line);
            entry.Parse();

            Assert.True(entry.Parsed);
            Assert.Equal("fetch", entry.Type);
            Assert.Equal("", entry.Data);
        }
Exemplo n.º 7
0
        public void TestGetDatabaseParameter()
        {
            const String line  = "10/26/18 15:09:26 2> [get database parameter] param = 1004";
            var          entry = new LogEntry();

            entry.AddLine(line);
            entry.Parse();

            Assert.True(entry.Parsed);
            Assert.Equal("get database parameter", entry.Type);
            Assert.Equal("param = 1004", entry.Data);
        }