public void ConvertFailToVSTestResult() { LogEntryError error = new LogEntryError("Error: 1 != 2", new SourceFileInfo("file.cpp", 10)); BoostTestResult testCaseResult = new BoostTestResultBuilder(). For(this.TestCase). Failed(). Duration(2500). Log(error). Build(); VSTestResult result = testCaseResult.AsVSTestResult(this.TestCase); AssertVSTestModelProperties(result); Assert.That(result.Outcome, Is.EqualTo(TestOutcome.Failed)); Assert.That(result.Duration, Is.EqualTo(Microseconds(2500))); AssertVsTestModelError(result, error); Assert.That(result.Messages.Count, Is.EqualTo(1)); TestResultMessage message = result.Messages.First(); Assert.That(message.Category, Is.EqualTo(TestResultMessage.StandardErrorCategory)); }
/// <summary> /// Formats a LogEntryException to append to test result string /// </summary> /// <param name="error">The error to format</param> /// <param name="sb">The StringBuilder which will host the output</param> /// <returns>sb</returns> private static StringBuilder FormatError(LogEntryError error, StringBuilder sb) { if (error.ContextFrames != null) { sb.Append(Environment.NewLine). Append("Failure occurred in a following context:"). Append(Environment.NewLine); foreach (string frame in error.ContextFrames) { sb.Append(" ").Append(frame).Append(Environment.NewLine); } // Remove redundant NewLine at the end sb.Remove((sb.Length - Environment.NewLine.Length), Environment.NewLine.Length); } return sb; }
/// <summary> /// Parses Log Entries from the collection of log nodes. /// </summary> /// <param name="nodes">The collection of Xml nodes which are valid LogEntry nodes.</param> /// <param name="result">The TestResult which will host the parsed LogEntries.</param> private static void ParseTestCaseLogEntries(XmlNodeList nodes, TestResult result) { foreach (XmlNode child in nodes) { if (child.NodeType == XmlNodeType.Element) { LogEntry entry = null; switch (child.Name) { case Xml.Info: entry = new LogEntryInfo(child.InnerText); break; case Xml.Message: entry = new LogEntryMessage(child.InnerText); break; case Xml.Warning: entry = new LogEntryWarning(child.InnerText); break; case Xml.Error: entry = new LogEntryError(child.InnerText); break; case Xml.FatalError: entry = new LogEntryFatalError(child.InnerText); break; case Xml.Exception: entry = ParseTestCaseLogException(child); break; } if (entry != null) { entry.Source = ParseSourceInfo(child); result.LogEntries.Add(entry); } } } }
/// <summary> /// Parse a LogEntryError from the provided node. /// </summary> /// <param name="node">The Xml node which contains error information.</param> /// <returns>A LogEntryError populated from the provided Xml node.</returns> private static LogEntryError ParseTestCaseLogError(XmlNode node) { LogEntryError error = new LogEntryError(); foreach (XmlNode child in node.ChildNodes) { if (child.NodeType == XmlNodeType.CDATA) { error.Detail = child.InnerText; } else if ((child.NodeType == XmlNodeType.Element) && (child.Name == Xml.Context)) { error.ContextFrames = child.SelectNodes(Xml.Frame).Cast<XmlNode>().Select(frame => frame.InnerText.Trim()).ToList(); } } return error; }