예제 #1
0
        public string FormatMethodEntry(int threadId, int level, int lineNo, MethodEntry logEntry, ILogFilters filters, bool displayEnabled)
        {
            if ((filters.HideEnterMethodLogs) || (!displayEnabled))
                return null;

            var args = ((logEntry.Arguments == null) || filters.HideMethodParameters) ? "" : string.Join(", ", logEntry.Arguments);
            var timeText = filters.HideTimeStampInMethod ? "" : string.Concat(this.FormatTime(logEntry.Time), " ");
            return string.Format("[Enter] {0}{1}({2})", timeText, logEntry.MethodName, args);
        }
예제 #2
0
        public string HandleMethodEntry(MethodEntry logEntry, bool displayEnabled)
        {
            // entry details are merged with exit details
            if (displayEnabled)
            {
                _lastMethodEntry.Push(logEntry);
                _orderedBuffer.Add(new LogEntryTracker(_currentNestedLevel, logEntry, null));
            }

            _currentNestedLevel++;
            return null;
        }
예제 #3
0
        public void FormatMethodEntry_ValidLog_NullIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var formatter = new SingleLineFormatter();
            var entry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));

            // Act
            var outputText = formatter.FormatMethodEntry(1, 2, 33, entry, filters, true);

            // Assert
            Assert.That(outputText, Is.Null, "Expected nothing to be returned for a method entry, everything is printed in the methodExit handling.");
        }
예제 #4
0
        public void FormatMethodEntry_HideTimeStampInMethodIsSet_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = LogFiltersBuilder.Create().WithTimeStampInMethodHidden().Build();
            var formatter = new DefaultFormatter();
            var entry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            var expectedText = "[Enter] Yalf.TestMethod(param1, param2)";

            // Act
            var outputText = formatter.FormatMethodEntry(22, 1, 33, entry, filters, true);

            // 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.");
        }
예제 #5
0
 public string FormatMethodEntry(int threadId, int level, int lineNo, MethodEntry logEntry, ILogFilters filters, bool displayEnabled)
 {
     // entry details are merged with exit details
     return _delayedService.HandleMethodEntry(logEntry, displayEnabled);
 }
예제 #6
0
 public MethodLogInformation(MethodEntry logEntry, bool enabled)
 {
     this.LogEntry = logEntry;
     this.Enabled = enabled;
 }
예제 #7
0
        private int FindLastIndexOf(MethodEntry logEntry)
        {
            for (int index = _orderedBuffer.Count-1; index >= 0; index--)
            {
                if ((_orderedBuffer[index].RelatedEntry != null) && (_orderedBuffer[index].RelatedEntry.MethodName == logEntry.MethodName))
                    return index;
            }

            return -1;
        }
        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.");
        }
예제 #9
0
        public void HandleMethodEntry_ValidLog_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new DefaultOutputHandler(filters);
            var entry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            var expectedText = String.Concat("".PadLeft(2, output.Formatter.IndentChar), "[Enter] 22:22:31.678 Yalf.TestMethod(param1, param2)");
            output.Initialise();

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

            // Assert
            var outputText = output.GetReport();
            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.");
        }
예제 #10
0
 public void HandleMethodEntry(MethodEntry entry, int indentLevel, bool displayEnabled)
 {
     this.AddLine(this.Formatter.FormatMethodEntry(this.CurrentThreadId, indentLevel, ++_lineNumber, entry, this.Filters, displayEnabled), indentLevel);
 }
예제 #11
0
        public void FormatMethodExit_NoEntryMethodSupplied_ExceptionIsThrown()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var formatter = new SingleLineFormatter();
            var entry = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");

            var relatedEntry = new MethodEntry(1, "Yalf.DifferentMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            formatter.FormatMethodEntry(1, 2, 33, relatedEntry, filters, true);

            // Act, Assert
            var outputText = formatter.FormatMethodExitForSingleLineOutput(1, 2, 33, entry, filters, true);
        }
        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 HandleMethodEntry_ValidLog_ExpectedTextIsReturned()
        {
            // 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"));
            var expectedText = String.Concat("".PadLeft(2, output.Formatter.IndentChar), "[Enter] 22:22:31.678 Yalf.TestMethod(param1, param2)");

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

            // Act
            output.HandleMethodEntry(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 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");
        }
예제 #15
0
 public void HandleMethodEntry(MethodEntry entry, int indentLevel, bool displayEnabled)
 {
     _outputHandler.HandleMethodEntry(entry, indentLevel, displayEnabled);
 }
예제 #16
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.");
        }
예제 #17
0
        public void FormatMethodExit_ReturnRecordedIsFalse_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var formatter = new SingleLineFormatter();
            var entry = new MethodExit(1, "Yalf.TestMethod", 345, false, "returnVal");
            var expectedText = "Yalf.TestMethod() started 22:22:31.678 duration 345ms";

            var relatedEntry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            formatter.FormatMethodEntry(1, 2, 33, relatedEntry, filters, true);

            // Act
            var orderedOutput = formatter.FormatMethodExitForSingleLineOutput(1, 2, 33, entry, filters, true);

            // Assert
            Assert.That(orderedOutput.Count, Is.EqualTo(1), "Expected one string to be returned");
            Assert.That(orderedOutput[0].Level, Is.EqualTo(0), "Not the expected nested level, you may need to adjust the test if the formatter has been changed.");
            Assert.That(orderedOutput[0].FormattedLine, Is.EqualTo(expectedText), "Not the expected formatted line, you may need to adjust the test if the formatter has been changed.");
        }
예제 #18
0
        public void FormatMethodExit_HideMethodDurationIsSet_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = LogFiltersBuilder.Create().WithMethodDurationHidden().Build();
            var formatter = new SingleLineFormatter();
            var entry = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");
            var expectedText = "Yalf.TestMethod(returnVal) started 22:22:31.678";

            var relatedEntry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            formatter.FormatMethodEntry(1, 2, 33, relatedEntry, filters, true);

            // Act
            var orderedOutput = formatter.FormatMethodExitForSingleLineOutput(1, 2, 33, entry, filters, true);

            // Assert
            Assert.That(orderedOutput.Count, Is.EqualTo(1), "Expected one string to be returned");
            Assert.That(orderedOutput[0].Level, Is.EqualTo(0), "Not the expected nested level, you may need to adjust the test if the formatter has been changed.");
            Assert.That(orderedOutput[0].FormattedLine, Is.EqualTo(expectedText), "Not the expected formatted line, you may need to adjust the test if the formatter has been changed.");
        }
예제 #19
0
        public void HandleMethodEntry_LogNotEnabled_NoTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new DefaultOutputHandler(filters);
            var entry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            output.Initialise();

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

            // Assert
            var outputText = output.GetReport();
            Assert.That(outputText, Is.Empty, "Expected no text in the report output");
        }
예제 #20
0
 public LogEntryTracker(int level, MethodEntry relatedEntry, String formattedLine)
 {
     this.Level = level;
     this.RelatedEntry = relatedEntry;
     this.FormattedLine = formattedLine;
 }
예제 #21
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 FormatMethodExit_ValidLog_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var formatter = new DelimitedValuesFormatter();
            var entry = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal");
            var expectedText = "Yalf,Method,Yalf.TestMethod,returnVal,22:22:31.678,345,2,1";

            var relatedEntry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678"));
            formatter.FormatMethodEntry(1, 2, 33, relatedEntry, filters, true);

            // Act
            var orderedOutput = formatter.FormatMethodExitForSingleLineOutput(1, 2, 33, entry, filters, true);

            // Assert
            Assert.That(orderedOutput.Count, Is.Not.EqualTo(0), "Expected one string to be returned");
            Assert.That(orderedOutput[0].FormattedLine, Is.EqualTo(expectedText), "Not the expected output text, you may need to adjust the test if the formatter has been changed.");
        }