Exemplo n.º 1
0
        public void FormatException_ValidLog_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var formatter = new DefaultFormatter();
            var ex = this.GenerateExceptionWithStackTrace();
            var entry = new ExceptionTrace(ex, DateTime.Parse("2022-10-22 22:22:31.678"));

            var expectedText = "[Exception] 22:22:31.678 Attempted to divide by zero.";

            // Act
            var outputText = formatter.FormatException(22, 1, 33, 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.");
        }
Exemplo n.º 2
0
        public void HandleException_ValidLog_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var output = new DefaultOutputHandler(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.");
            output.Initialise();

            // Act
            output.HandleException(entry, 1);
            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.");
        }
        public void FormatException_ValidLog_ExpectedTextIsReturned()
        {
            // Arrange
            var filters = this.GetDefaultFilters();
            var formatter = new DelimitedValuesFormatter();
            var ex = this.GenerateExceptionWithStackTrace();
            var entry = new ExceptionTrace(ex, DateTime.Parse("2022-10-22 22:22:31.678"));

            var expectedText = @"Yalf,Exception,Attempted to divide by zero.,   at Yalf.Tests.Reporting.DelimitedValuesFormatterTests.GenerateExceptionWithStackTrace() in d:\repositories\yalf\Yalf.Tests\Reporting\DelimitedValuesFormatterTests.cs:line xxx,22:22:31.678,0,1,22";
            expectedText = expectedText.Replace(@"d:\repositories\yalf", this.GetRootFolder());

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

            // Assert
            outputText = Regex.Replace(outputText, @"DelimitedValuesFormatterTests\.cs\:line [0-9]+,", "DelimitedValuesFormatterTests.cs:line xxx,");

            Console.WriteLine(outputText);
            Console.WriteLine(System.Environment.CurrentDirectory);
            Assert.That(outputText, Is.Not.Empty, "Expected a string to be returned");
            Assert.That(outputText, Is.EqualTo(expectedText).IgnoreCase, "Not the expected output text, you may need to adjust the test if the formatter has been changed - it could be the line number of the mock exception has changed.");
        }
        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.");
        }
Exemplo n.º 5
0
 public void HandleException(ExceptionTrace entry, int indentLevel)
 {
     this.AddLine(this.Formatter.FormatException(this.CurrentThreadId, indentLevel, ++_lineNumber, entry, this.Filters), indentLevel);
 }
Exemplo n.º 6
0
 public string FormatException(int threadId, int level, int lineNo, ExceptionTrace logEntry, ILogFilters filters)
 {
     return _delayedService.HandleException(_default.FormatException(threadId, level, lineNo, logEntry, filters));
 }
Exemplo n.º 7
0
 public string FormatException(int threadId, int level, int lineNo, ExceptionTrace logEntry, ILogFilters filters)
 {
     var stackTrace = (logEntry.StackTrace == null) ? "" : logEntry.StackTrace.Replace(Environment.NewLine, " ");
     return _delayedService.HandleException(this.BuildOutputLine("Exception", logEntry.Message.Replace(Environment.NewLine, " "), stackTrace, logEntry.Time, 0, level, threadId));
 }
Exemplo n.º 8
0
 public string FormatException(int threadId, int level, int lineNo, ExceptionTrace logEntry, ILogFilters filters)
 {
     return string.Format("[Exception] {0} {1}", this.FormatTime(logEntry.Time), logEntry.Message);
 }
Exemplo n.º 9
0
 public void HandleException(ExceptionTrace entry, int indentLevel)
 {
     _outputHandler.HandleException(entry, indentLevel);
 }