Esempio n. 1
0
        public string FormatThread(ThreadData logEntry, ILogFilters filters)
        {
            var outputFormat = "[Thread {0} '{1}']";
            if (String.IsNullOrEmpty(logEntry.ThreadName))
                outputFormat = "[Thread {0}]";

            return String.Format(outputFormat, logEntry.ThreadId, logEntry.ThreadName);
        }
        public void HandleLogEntry_LogNotEnabled_NoTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new ThreadCollectionOutputHandler(filters);
            var entry = new LogEvent(LogLevel.Info, DateTime.Parse("2022-10-22 22:22:31.678"), "This is a log entry");

            int threadId = 22;
            var threadData = new ThreadData(threadId, "cotton", null);
            output.Initialise();

            // Act
            output.HandleThread(threadData);
            output.HandleLogEvent(entry, 1, false);
            output.Complete();

            // Assert
            var outputText = output.GetThreadEntries();
            Assert.That(outputText[threadId].Count, Is.EqualTo(0), "Expected no text in the report output");
        }
        public void HandleException_ValidLog_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new ThreadCollectionOutputHandler(filters);
            var ex = this.GenerateExceptionWithStackTrace();
            var entry = new ExceptionTrace(ex, DateTime.Parse("2022-10-22 22:22:31.678"));
            var expectedText = String.Concat("".PadLeft(2, output.Formatter.IndentChar), "[Exception] 22:22:31.678 Attempted to divide by zero.");

            int threadId = 22;
            var threadData = new ThreadData(threadId, "cotton", null);
            output.Initialise();

            // Act
            output.HandleThread(threadData);
            output.HandleException(entry, 1);
            output.Complete();

            // Assert
            var outputText = output.GetThreadEntries();
            Assert.That(outputText.Count, Is.EqualTo(1), "Expected one string entry to be returned");
            Assert.That(outputText[threadId][0], Is.EqualTo(expectedText), "Not the expected output text, you may need to adjust the test if the formatter has been changed.");
        }
Esempio n. 4
0
        public void FormatThread_ValidLogWithThreadName_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var formatter = new DefaultFormatter();

            var entry1 = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            var entry2 = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");
            var entry = new ThreadData(22, "YalfThread", new BaseEntry[] { entry1, entry2 });

            var expectedText = "[Thread 22 'YalfThread']";

            // Act
            var outputText = formatter.FormatThread(entry, filters);

            // Assert
            Assert.That(outputText, Is.Not.Empty, "Expected a string to be returned");
            Assert.That(outputText, Is.EqualTo(expectedText), "Not the expected output text, you may need to adjust the test if the formatter has been changed.");
        }
Esempio n. 5
0
 public string FormatThread(ThreadData logEntry, ILogFilters filters)
 {
     return _default.FormatThread(logEntry, filters);
 }
 public string FormatThread(ThreadData logEntry, ILogFilters filters)
 {
     return null;
 }
Esempio n. 7
0
        private void HandleThreadChange(ThreadData entry)
        {
            if ((this.LogEntries.Filters.ThreadId > 0) && (entry.ThreadId != this.LogEntries.Filters.ThreadId))
                return;

            this.OutputHandler.HandleThread(entry);

            if (entry.Entries != null && entry.Entries.Any())
                this.GenerateOutput(entry.Entries, 0);
        }
 public void HandleThread(ThreadData entry)
 {
     this.CurrentThreadId = entry.ThreadId;
     _threadEntries.Add(entry.ThreadId, new List<String>());
     base.Buffer = _threadEntries[entry.ThreadId];
 }
        public void HandleLogEntry_ValidLog_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new ThreadCollectionOutputHandler(filters);
            var entry = new LogEvent(LogLevel.Info, DateTime.Parse("2022-10-22 22:22:31.678"), "This is a log entry");

            var expectedText = String.Concat("".PadLeft(2, output.Formatter.IndentChar), "[Log] [Info] This is a log entry");

            int threadId = 22;
            var threadData = new ThreadData(threadId, "cotton", null);
            output.Initialise();
            output.HandleThread(threadData);

            // Act
            output.HandleLogEvent(entry, 1, true);
            output.Complete();

            // Assert
            var outputText = output.GetThreadEntries();
            Assert.That(outputText.Count, Is.EqualTo(1), "Expected one thread collection");
            Assert.That(outputText[threadId].Count, Is.EqualTo(1), "Expected the thread to have one log entry");
            Assert.That(outputText[threadId][0], Is.EqualTo(expectedText), "Not the expected output text, you may need to adjust the test if the formatter has been changed.");
        }
Esempio n. 10
0
 public void HandleThread(ThreadData entry)
 {
     _outputHandler.HandleThread(entry);
 }
        public void SingleLineFormatter_NestedMethodCalls_ReportHasCorrectIndenting()
        {
            // Arrange
            var formatter = new SingleLineFormatter();
            var startDateTime = DateTime.Now;
            var entries = new BaseEntry[]
                {
                    new MethodEntry(1, "TopLevelMethod", null, startDateTime),
                    new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep"),
                    new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12)),
                    new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)),
                    new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here"),
                    new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53)),
                    new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)),
                    new MethodExit(3, "ThirdMethod", 100, false, null),
                    new MethodEntry(3, "FourthMethod", null, startDateTime.AddSeconds(80)),
                    new MethodExit(3, "FourthMethod", 57, false, null),
                    new MethodExit(2, "SecondMethod", 178, false, null),
                    new MethodExit(1, "FirstMethod", 200, false, null),
                    new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99)),
                    new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep"),
                };

            var expectedText = (new string[]
                                    {
                                        string.Format("TopLevelMethod(blackSheep) started {0:HH:mm:ss.fff} duration 233ms", startDateTime),
                                        string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime.AddSeconds(12)),
                                        string.Format("  SecondMethod() started {0:HH:mm:ss.fff} duration 178ms", startDateTime.AddSeconds(45)),
                                        string.Format("    [Log] [Info] Information log message here"),
                                        string.Format("    [Exception] {0:HH:mm:ss.fff} Test the log\r\nParameter name: lineNo", startDateTime.AddSeconds(53)),
                                        string.Format("    ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)),
                                        string.Format("    FourthMethod() started {0:HH:mm:ss.fff} duration 57ms", startDateTime.AddSeconds(80)),
                                        string.Format("TopLevelMethod2(whiteSheep) started {0:HH:mm:ss.fff} duration 488ms", startDateTime.AddSeconds(99))
                                    }
                               ).ToList();

            var filters = this.GetDefaultFilters();
            var indentLevel = 0;

            int threadId = 22;
            var threadData = new ThreadData(threadId, "cotton", null);
            var outputter = new ThreadCollectionOutputHandler(filters, formatter);
            outputter.Initialise();
            outputter.HandleThread(threadData);

            // Act
            foreach (var entry in entries)
            {
                if (entry is MethodEntry)
                {
                    outputter.HandleMethodEntry((entry as MethodEntry), indentLevel, true);
                    ++indentLevel;
                }
                else if (entry is MethodExit)
                {
                    --indentLevel;
                    outputter.HandleMethodExit((entry as MethodExit), indentLevel, true);
                }
                else if (entry is LogEvent)
                {
                    outputter.HandleLogEvent((entry as LogEvent), indentLevel, true);
                }
                else if (entry is ExceptionTrace)
                {
                    outputter.HandleException((entry as ExceptionTrace), indentLevel);
                }
            }

            outputter.Complete();

            // Assert
            var reportText = outputter.GetThreadEntries();
            Assert.That(reportText.Count, Is.EqualTo(1), "Expected one thread collection");

            var output = reportText[threadId];
            Assert.That(output.Count, Is.EqualTo(expectedText.Count), "Expected {0} output lines, but have {1}\n{2}", expectedText.Count, output.Count, this.CreateComparisonReport(output, expectedText));
            for (int index = 0; index < expectedText.Count; index++)
            {
                Assert.That(output[index], Is.EqualTo(expectedText[index]), "Not the expected text for line {0}\n\n{1}", index + 1, this.CreateComparisonReport(output, expectedText));
            }
        }
        public void HandleThread_ValidLogWithBlankThreadName_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new ThreadCollectionOutputHandler(filters);

            var entry1 = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            var entry2 = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");

            int threadId = 22;
            var entry = new ThreadData(threadId, String.Empty, new BaseEntry[] { entry1, entry2 });
            output.Initialise();

            // Act
            output.HandleThread(entry);
            output.Complete();

            // Assert
            Assert.That(output.CurrentThreadId, Is.EqualTo(threadId), "Not the expected thread id for the current thread.");

            var outputText = output.GetThreadEntries();
            Assert.That(outputText.Count, Is.EqualTo(1), "Expected one thread collection");
            Assert.That(outputText[threadId].Count, Is.EqualTo(0), "Expected the thread to have no log entries");
        }
        public void HandleMethodExit_ValidLog_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new ThreadCollectionOutputHandler(filters);
            var entry = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");
            var expectedText = String.Concat("".PadLeft(2, output.Formatter.IndentChar), "[Exit] Yalf.TestMethod(returnVal) duration 345ms");

            int threadId = 22;
            var threadData = new ThreadData(threadId, "cotton", null);
            output.Initialise();
            output.HandleThread(threadData);

            // Act
            output.HandleMethodExit(entry, 1, true);
            output.Complete();

            // Assert
            var outputText = output.GetThreadEntries();
            Assert.That(outputText.Count, Is.EqualTo(1), "Expected one thread collection");
            Assert.That(outputText[threadId].Count, Is.EqualTo(1), "Expected the thread to have one log entry");
            Assert.That(outputText[threadId][0], Is.EqualTo(expectedText), "Not the expected output text, you may need to adjust the test if the formatter has been changed.");
        }
        public void HandleMethodExit_LogNotEnabled_NoTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new ThreadCollectionOutputHandler(filters);
            var entry = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");
            output.Initialise();

            int threadId = 22;
            var threadData = new ThreadData(threadId, "cotton", null);
            output.Initialise();
            output.HandleThread(threadData);

            // Act
            output.HandleMethodExit(entry, 1, false);
            output.Complete();

            // Assert
            var outputText = output.GetThreadEntries();
            Assert.That(outputText.Count, Is.EqualTo(1), "Expected one thread collection");
            Assert.That(outputText[threadId].Count, Is.EqualTo(0), "Expected the thread to have no log entries");
        }
        public void HandleMethodEntry_LogNotEnabled_NoTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new ThreadCollectionOutputHandler(filters);
            var entry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            output.Initialise();

            int threadId = 22;
            var threadData = new ThreadData(threadId, "cotton", null);
            output.Initialise();
            output.HandleThread(threadData);

            // Act
            output.HandleMethodEntry(entry, 1, false);
            output.Complete();

            // Assert
            var outputText = output.GetThreadEntries();
            Assert.That(outputText.Count, Is.EqualTo(1), "Expected one thread collection");
            Assert.That(outputText[threadId].Count, Is.EqualTo(0), "Expected the thread to have no log entries");
        }
Esempio n. 16
0
 public void HandleThread(ThreadData entry)
 {
     this.CurrentThreadId = entry.ThreadId;
     this.AddLine(this.Formatter.FormatThread(entry, this.Filters), 0);
 }
Esempio n. 17
0
        public void HandleThread_ValidLogWithThreadName_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new DefaultOutputHandler(filters);

            var entry1 = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            var entry2 = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");
            var entry = new ThreadData(22, "YalfThread", new BaseEntry[] { entry1, entry2 });

            var expectedText = String.Concat("[Thread 22 'YalfThread']");
            output.Initialise();

            // Act
            output.HandleThread(entry);
            output.Complete();

            // Assert
            var outputText = output.GetReport();
            Assert.That(outputText, Is.Not.Empty, "Expected a string to be returned");
            Assert.That(output.CurrentThreadId, Is.EqualTo(22), "Not the expected thread id for the current thread.");
            Assert.That(outputText, Is.EqualTo(expectedText), "Not the expected output text, you may need to adjust the test if the formatter has been changed.");
        }
        public void FormatThread_ValidLog_NullIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var formatter = new DelimitedValuesFormatter();

            var entry1 = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            var entry2 = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");
            var entry = new ThreadData(22, String.Empty, new BaseEntry[] { entry1, entry2 });

            // Act
            var outputText = formatter.FormatThread(entry, filters);

            // Assert
            Assert.That(outputText, Is.Null, "Did not expect any formatted text back for a delimited values formatter, threadid is in each row.");
        }