public string markAsException(string fragment, string expression, string errorMessage) { var exception = new StackTraceSettingException(errorMessage); exception.StackTraceElements.AddRange(stackTraceElements); var document = new TestRig() .ProcessFragment(fragment) .GetXDocument(); var element = new Element(document.Descendants("p").ToArray()[0]); new ExceptionRenderer().ExceptionCaught(new ExceptionCaughtEvent(exception, element, expression)); return element.ToXml(); }