private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult) { using (OpenTag("<tr>", HtmlTag.tr)) { AddLine(string.Format("<td><Span class='{0}' style='margin-right:4px;' /></td>", scenario.Result)); foreach (var exampleValue in scenario.Example.Values) { AddLine(string.Format("<td>{0}</td>", WebUtility.HtmlEncode(exampleValue.GetValueAsString()))); } if (scenarioResult != Result.Failed) { return; } using (OpenTag("<td>", HtmlTag.td)) { var failingStep = scenario.Steps.FirstOrDefault(s => s.Result == Result.Failed); if (failingStep == null) { return; } var exceptionId = Configurator.IdGenerator.GetStepId(); var encodedExceptionMessage = WebUtility.HtmlEncode(failingStep.Exception.Message); AddLine(string.Format("<span class='canToggle' data-toggle-target='{0}'>{1}</span>", exceptionId, encodedExceptionMessage)); using (OpenTag(string.Format("<div class='step FailedException' id='{0}'>", exceptionId), HtmlTag.div)) { AddLine(string.Format("<code>{0}</code>", failingStep.Exception.StackTrace)); } } } }
/// <summary> /// Invokes the <see cref="ScenarioCompleted"/> event. /// </summary> /// <param name="scenario">The scenario.</param> protected virtual void InvokeScenarioCompleted(ReportModel.Scenario scenario) { var args = new ScenarioCompletedEventArgs { Scenario = scenario }; ScenarioCompleted?.Invoke(this, args); }
private void WriteExamples(StringBuilder report, ReportModel.Scenario exampleScenario, IEnumerable <ReportModel.Scenario> scenarioGroup) { report.AppendLine("### Examples: "); report.AppendLine(); var scenarios = scenarioGroup.ToArray(); var allPassed = scenarios.All(s => s.Result == Result.Passed); var exampleColumns = exampleScenario.Example.Headers.Length; var numberColumns = allPassed ? exampleColumns : exampleColumns + 2; var maxWidth = new int[numberColumns]; var rows = new List <string[]>(); Action <IEnumerable <string>, string, string> addRow = (cells, result, error) => { var row = new string[numberColumns]; var index = 0; foreach (var cellText in cells) { row[index++] = cellText; } if (!allPassed) { row[numberColumns - 2] = result; row[numberColumns - 1] = error; } for (var i = 0; i < numberColumns; i++) { var rowValue = row[i]; if (rowValue != null && rowValue.Length > maxWidth[i]) { maxWidth[i] = rowValue.Length; } } rows.Add(row); }; addRow(exampleScenario.Example.Headers, "Result", "Errors"); foreach (var scenario in scenarios) { var failingStep = scenario.Steps.FirstOrDefault(s => s.Result == Result.Failed); var error = failingStep == null ? null : string.Format("Step: {0} failed with exception: {1}", HttpUtility.HtmlEncode(failingStep.Title), CreateExceptionMessage(failingStep)); addRow(scenario.Example.Values.Select(e => e.GetValueAsString()), scenario.Result.ToString(), error); } foreach (var row in rows) { WriteExampleRow(report, row, maxWidth); } }
private void AddScenario(ReportModel.Scenario scenario) { AddLine(string.Format("<div class='{0} canToggle scenarioTitle' data-toggle-target='{1}'>{2}{3}</div>", scenario.Result, scenario.Id, WebUtility.HtmlEncode(scenario.Title), FormatTags(scenario.Tags))); using (OpenTag(string.Format("<ul class='steps' id='{0}'>", scenario.Id), HtmlTag.ul)) { foreach (var step in scenario.Steps.Where(s => s.ShouldReport)) { string stepClass = string.Empty; var reportException = step.Exception != null && step.Result == Result.Failed; string canToggle = reportException ? "canToggle" : string.Empty; using (OpenTag(string.Format("<li class='step {0} {1} {2} {3}' data-toggle-target='{4}' >", step.Result, stepClass, step.ExecutionOrder, canToggle, step.Id), HtmlTag.li)) { var titleLines = step.Title.Split(new[] { Environment.NewLine }, StringSplitOptions.None); var title = titleLines[0]; if (reportException) { stepClass = step.Result + "Exception"; if (!string.IsNullOrEmpty(step.Exception.Message)) { title += " [Exception Message: '" + step.Exception.Message + "']"; } } AddLine(string.Format("<span>{0}</span>", title)); for (int i = 1; i < titleLines.Length; i++) { AddLine(string.Format("<div class='step-title-extra-lines'>{0}</div>", titleLines[i])); } if (reportException) { using (OpenTag(string.Format("<div class='step {0}' id='{1}'>", stepClass, step.Id), HtmlTag.div)) { AddLine(string.Format("<code>{0}</code>", step.Exception.StackTrace)); } } } } } }