/// <summary> /// Given a LogEntry instance, identifies the respective Visual Studio /// TestResult message category. /// </summary> /// <param name="entry">The LogEntry instance to test</param> /// <returns>The respective Visual Studio Message category for the provided LogEntry</returns> private string GetCategory(LogEntry entry) { BoostTestResult testCaseResult = new BoostTestResultBuilder(). For(this.TestCase). Log(entry). Build(); VSTestResult result = testCaseResult.AsVSTestResult(this.TestCase); return result.Messages.First().Category; }
/// <summary> /// Registers a log entry. /// </summary> /// <param name="entry">A log entry generated during test execution</param> /// <returns>this</returns> public BoostTestResultBuilder Log(LogEntry entry) { this.Logs.Add(entry); return this; }
/// <summary> /// Asserts that a log entry resulting in a test failure is correctly noted /// in the Visual Studio TestResult. /// </summary> /// <param name="result">The Visual Studio TestResult to test</param> /// <param name="entry">The log entry detailing a test case error</param> private void AssertVsTestModelError(VSTestResult result, LogEntry entry) { Assert.That(result.ErrorMessage, Is.EqualTo(entry.Detail)); }
private static string GetTestResultMessageText(TestUnit unit, LogEntry entry) { if ((entry is LogEntryStandardOutputMessage) || (entry is LogEntryStandardErrorMessage)) { return entry.Detail.TrimEnd() + Environment.NewLine; } StringBuilder sb = new StringBuilder(); if (entry.Source != null) { AppendSourceInfo(entry.Source, sb); } sb.Append(entry.ToString().ToLowerInvariant()). Append(" in \""). Append(unit.Name). Append("\""); LogEntryMemoryLeak memoryLeak = entry as LogEntryMemoryLeak; if (memoryLeak == null) { sb.Append(": ").Append(entry.Detail.TrimEnd()); } LogEntryException exception = entry as LogEntryException; if (exception != null) { if (exception.LastCheckpoint != null) { sb.Append(Environment.NewLine); AppendSourceInfo(exception.LastCheckpoint, sb); sb.Append("last checkpoint: ").Append(exception.CheckpointDetail); } } if (memoryLeak != null) { if ((memoryLeak.LeakSourceFilePath != null) && (memoryLeak.LeakSourceFileName != null)) { sb.Append("source file path leak detected at :"). Append(memoryLeak.LeakSourceFilePath). Append(memoryLeak.LeakSourceFileName); } if (memoryLeak.LeakLineNumber != null) { sb.Append(", "). Append("Line number: "). Append(memoryLeak.LeakLineNumber); } sb.Append(", "). Append("Memory allocation number: "). Append(memoryLeak.LeakMemoryAllocationNumber); sb.Append(", "). Append("Leak size: "). Append(memoryLeak.LeakSizeInBytes). Append(" byte"); if (memoryLeak.LeakSizeInBytes > 0) { sb.Append('s'); } sb.Append(Environment.NewLine). Append(memoryLeak.LeakLeakedDataContents); } // Append NewLine so that log entries are listed one per line return sb.Append(Environment.NewLine).ToString(); }
/// <summary> /// Asserts that a log entry resulting in a test failure is correctly noted /// in the Visual Studio TestResult. /// </summary> /// <param name="result">The Visual Studio TestResult to test</param> /// <param name="entry">The log entry detailing a test case error</param> private void AssertVsTestModelError(VSTestResult result, LogEntry entry) { Assert.That(result.ErrorMessage, Is.EqualTo(entry.Detail)); Assert.That(result.ErrorStackTrace, Is.EqualTo(entry.Source.ToString())); }
private static string GetTestResultMessageText(TestUnit unit, LogEntry entry) { Code.Require(unit, "unit"); Code.Require(entry, "entry"); if ((entry is LogEntryStandardOutputMessage) || (entry is LogEntryStandardErrorMessage)) { return entry.Detail.TrimEnd() + Environment.NewLine; } StringBuilder sb = new StringBuilder(); if (entry.Source != null) { AppendSourceInfo(entry.Source, sb); } sb.Append(entry.ToString().ToLowerInvariant()). Append(" in \""). Append(unit.Name). Append("\""); LogEntryMemoryLeak memoryLeak = entry as LogEntryMemoryLeak; if (memoryLeak == null) { sb.Append(": ").Append(entry.Detail.TrimEnd()); } LogEntryException exception = entry as LogEntryException; if (exception != null) { FormatException(exception, sb); } LogEntryError error = entry as LogEntryError; if (error != null) { FormatError(error, sb); } if (memoryLeak != null) { FormatMemoryLeak(memoryLeak, sb); } // Append NewLine so that log entries are listed one per line return sb.Append(Environment.NewLine).ToString(); }
/// <summary> /// Tests the provided LogEntry's general properties against the expected values /// </summary> /// <param name="entry">The LogEntryException to test</param> /// <param name="entryType">The expected log entry type</param> /// <param name="message">The expected log message</param> /// <param name="info">The expected source file information for the log entry</param> private void AssertLogEntryDetails(LogEntry entry, string entryType, string message, SourceFileInfo info) { Assert.That(entry.ToString(), Is.EqualTo(entryType)); Assert.That(entry.Detail, Is.EqualTo(message)); AssertSourceInfoDetails(entry.Source, info); }