Skip to content

Commit cb3d9a5

Browse files
committed
folded HtmlReportRenderer to be treated just like any other processor
1 parent 216ac1e commit cb3d9a5

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

TestStack.ConventionTests/Convention.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
public static class Convention
1111
{
1212
static readonly HtmlReportRenderer HtmlRenderer = new HtmlReportRenderer(AssemblyDirectory);
13-
static readonly List<ConventionResult> Reports = new List<ConventionResult>();
1413

1514
static Convention()
1615
{
@@ -24,38 +23,41 @@ static Convention()
2423
};
2524
}
2625

27-
public static IEnumerable<ConventionResult> ConventionReports { get { return Reports; } }
28-
public static IList<IReportDataFormatter> Formatters { get; set; }
26+
public static IList<IReportDataFormatter> Formatters { get; set; }
2927

3028
public static void Is<TDataSource>(IConvention<TDataSource> convention, TDataSource data)
3129
where TDataSource : IConventionData
3230
{
33-
Is(convention, data, new ThrowOnFailureResultsProcessor());
31+
Is(convention, data, new IResultsProcessor[]
32+
{
33+
HtmlRenderer,
34+
new ConventionReportTraceRenderer(),
35+
new ThrowOnFailureResultsProcessor()
36+
});
3437
}
3538

3639
public static void Is<TDataSource>(IConvention<TDataSource> convention, TDataSource data,
37-
IResultsProcessor processor)
40+
IResultsProcessor[] processors)
3841
where TDataSource : IConventionData
3942
{
40-
try
41-
{
42-
var context = new ConventionContext(data.Description, Formatters);
43-
var conventionResult = context.Execute(convention, data);
44-
Reports.AddRange(conventionResult);
43+
var context = new ConventionContext(data.Description, Formatters);
44+
var conventionResult = context.Execute(convention, data);
4545

46-
new ConventionReportTraceRenderer().Process(conventionResult);
47-
processor.Process(conventionResult);
48-
}
49-
finally
46+
foreach (var processor in processors)
5047
{
51-
HtmlRenderer.Process(Reports.ToArray());
48+
processor.Process(conventionResult);
5249
}
5350
}
5451

5552
public static void IsWithApprovedExeptions<TDataSource>(IConvention<TDataSource> convention, TDataSource data)
5653
where TDataSource : IConventionData
5754
{
58-
Is(convention, data, new ApproveResultsProcessor());
55+
Is(convention, data, new IResultsProcessor[]
56+
{
57+
HtmlRenderer,
58+
new ConventionReportTraceRenderer(),
59+
new ApproveResultsProcessor()
60+
});
5961
}
6062

6163
// http://stackoverflow.com/questions/52797/c-how-do-i-get-the-path-of-the-assembly-the-code-is-in#answer-283917

TestStack.ConventionTests/Reporting/HtmlReportRenderer.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace TestStack.ConventionTests.Reporting
22
{
3+
using System;
4+
using System.Collections.Generic;
35
using System.IO;
46
using System.Text;
57
using System.Web.UI;
@@ -8,6 +10,8 @@
810
public class HtmlReportRenderer : IResultsProcessor
911
{
1012
readonly string file;
13+
static readonly List<ConventionResult> Reports = new List<ConventionResult>();
14+
public static IEnumerable<ConventionResult> ConventionReports { get { return Reports; } }
1115

1216
public HtmlReportRenderer(string assemblyDirectory)
1317
{
@@ -16,6 +20,7 @@ public HtmlReportRenderer(string assemblyDirectory)
1620

1721
public void Process(params ConventionResult[] results)
1822
{
23+
Reports.AddRange(results);
1924
var sb = new StringBuilder();
2025
var html = new HtmlTextWriter(new StringWriter(sb));
2126
html.WriteLine("<!DOCTYPE html>");
@@ -29,16 +34,16 @@ public void Process(params ConventionResult[] results)
2934
html.Write("Project Conventions");
3035
html.RenderEndTag();
3136

32-
foreach (var conventionReport in results)
37+
foreach (var conventionReport in Reports)
3338
{
3439
html.RenderBeginTag(HtmlTextWriterTag.P);
3540
html.RenderBeginTag(HtmlTextWriterTag.Div);
3641
html.RenderBeginTag(HtmlTextWriterTag.Strong);
3742
html.Write(conventionReport.Result+": ");
3843
html.RenderEndTag();
39-
var title = string.Format("{0} for {1}", conventionReport.ConventionTitle, conventionReport.DataDescription);
44+
var title = String.Format("{0} for {1}", conventionReport.ConventionTitle, conventionReport.DataDescription);
4045
html.Write(title);
41-
if (!string.IsNullOrEmpty(conventionReport.ApprovedException))
46+
if (!String.IsNullOrEmpty(conventionReport.ApprovedException))
4247
{
4348
html.RenderBeginTag(HtmlTextWriterTag.Div);
4449
html.RenderBeginTag(HtmlTextWriterTag.Strong);
@@ -49,7 +54,7 @@ public void Process(params ConventionResult[] results)
4954

5055
html.RenderBeginTag(HtmlTextWriterTag.Ul);
5156

52-
if (!string.IsNullOrEmpty(conventionReport.ApprovedException))
57+
if (!String.IsNullOrEmpty(conventionReport.ApprovedException))
5358
{
5459
html.RenderBeginTag(HtmlTextWriterTag.Li);
5560
html.WriteLine(conventionReport.ApprovedException);

0 commit comments

Comments
 (0)