Skip to content

Commit 6c3a40f

Browse files
author
Jake Ginnivan
committed
Introduced some base classes to help make the html reporter more understandable and introduced markdown reporter
1 parent d9d8abe commit 6c3a40f

File tree

5 files changed

+97
-16
lines changed

5 files changed

+97
-16
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace TestStack.ConventionTests.Reporting
2+
{
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using TestStack.ConventionTests.Internal;
6+
7+
/// <summary>
8+
/// Aggregates all previous results
9+
/// </summary>
10+
public abstract class AggregatedRenderer : IResultsProcessor
11+
{
12+
static readonly List<ConventionResult> Reports = new List<ConventionResult>();
13+
public IEnumerable<ConventionResult> AggregatedReports { get { return Reports; } }
14+
15+
public void Process(IConventionFormatContext context, params ConventionResult[] results)
16+
{
17+
Reports.AddRange(results.Except(Reports));
18+
Process(context);
19+
}
20+
21+
protected abstract void Process(IConventionFormatContext context);
22+
}
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace TestStack.ConventionTests.Reporting
2+
{
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using TestStack.ConventionTests.Internal;
6+
7+
public abstract class GroupedByDataTypeRendererBase : AggregatedRenderer
8+
{
9+
protected override void Process(IConventionFormatContext context)
10+
{
11+
Process(AggregatedReports.OrderBy(c => c.ConventionTitle).GroupBy(r => r.DataDescription));
12+
}
13+
14+
protected abstract void Process(IEnumerable<IGrouping<string, ConventionResult>> resultsGroupedByDataType);
15+
}
16+
}

TestStack.ConventionTests/Reporting/HtmlReportRenderer.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
namespace TestStack.ConventionTests.Reporting
22
{
3-
using System;
43
using System.Collections.Generic;
54
using System.IO;
5+
using System.Linq;
66
using System.Text;
77
using System.Web.UI;
88
using TestStack.ConventionTests.Internal;
99

10-
public class HtmlReportRenderer : IResultsProcessor
10+
public class HtmlReportRenderer : GroupedByDataTypeRendererBase
1111
{
1212
readonly string file;
13-
static readonly List<ConventionResult> Reports = new List<ConventionResult>();
14-
public static IEnumerable<ConventionResult> ConventionReports { get { return Reports; } }
1513

1614
public HtmlReportRenderer(string assemblyDirectory)
1715
{
1816
file = Path.Combine(assemblyDirectory, "Conventions.htm");
1917
}
2018

21-
public void Process(IConventionFormatContext context, params ConventionResult[] results)
19+
protected override void Process(IEnumerable<IGrouping<string, ConventionResult>> resultsGroupedByDataType)
2220
{
23-
Reports.AddRange(results);
2421
var sb = new StringBuilder();
2522
var html = new HtmlTextWriter(new StringWriter(sb));
2623
html.WriteLine("<!DOCTYPE html>");
2724
html.RenderBeginTag(HtmlTextWriterTag.Html); // <html>
2825
html.RenderBeginTag(HtmlTextWriterTag.Head); // <head>
26+
html.Write(@"
27+
<style type=""text/css"">
28+
h1 {
29+
color: #3c6eb4;
30+
}
31+
32+
h2 {
33+
background: #f1f1f1;
34+
}
35+
</style>");
2936
html.RenderEndTag(); // </head>
3037
html.WriteLine();
3138
html.RenderBeginTag(HtmlTextWriterTag.Body); // <body>
@@ -34,25 +41,20 @@ public void Process(IConventionFormatContext context, params ConventionResult[]
3441
html.Write("Project Conventions");
3542
html.RenderEndTag();
3643

37-
foreach (var conventionReport in Reports)
44+
foreach (var conventionReport in resultsGroupedByDataType)
3845
{
3946
html.RenderBeginTag(HtmlTextWriterTag.P);
4047
html.RenderBeginTag(HtmlTextWriterTag.Div);
41-
html.RenderBeginTag(HtmlTextWriterTag.Strong);
48+
html.RenderBeginTag(HtmlTextWriterTag.H2);
49+
html.Write("Conventions for '<strong>{0}</strong>'", conventionReport.Key);
4250
html.RenderEndTag();
43-
var title = String.Format("{0} for {1}", conventionReport.ConventionTitle, conventionReport.DataDescription);
44-
html.Write(title);
45-
4651
html.RenderBeginTag(HtmlTextWriterTag.Ul);
47-
48-
49-
foreach (var conventionFailure in conventionReport.Data)
52+
foreach (var conventionResult in conventionReport)
5053
{
5154
html.RenderBeginTag(HtmlTextWriterTag.Li);
52-
html.Write(context.FormatData(conventionFailure).ToString());
55+
html.Write(conventionResult.ConventionTitle);
5356
html.RenderEndTag();
5457
}
55-
5658
html.RenderEndTag();
5759
html.RenderEndTag();
5860
html.RenderEndTag();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace TestStack.ConventionTests.Reporting
2+
{
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using TestStack.ConventionTests.Internal;
8+
9+
public class MarkdownReportRenderer : GroupedByDataTypeRendererBase
10+
{
11+
readonly string file;
12+
13+
public MarkdownReportRenderer(string assemblyDirectory)
14+
{
15+
file = Path.Combine(assemblyDirectory, "Conventions.md");
16+
}
17+
18+
protected override void Process(IEnumerable<IGrouping<string, ConventionResult>> resultsGroupedByDataType)
19+
{
20+
var sb = new StringBuilder();
21+
sb.AppendLine("# Project Conventions");
22+
foreach (var conventionReport in resultsGroupedByDataType)
23+
{
24+
sb.Append("## ");
25+
sb.AppendLine(conventionReport.Key);
26+
27+
foreach (var conventionResult in conventionReport)
28+
{
29+
sb.Append(" - ");
30+
sb.AppendLine(conventionResult.ConventionTitle);
31+
}
32+
}
33+
34+
File.WriteAllText(file, sb.ToString());
35+
}
36+
}
37+
}

TestStack.ConventionTests/TestStack.ConventionTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@
7070
<Compile Include="Internal\ConventionTestsApprovalTextWriter.cs" />
7171
<Compile Include="Internal\IConventionFormatContext.cs" />
7272
<Compile Include="Internal\NoDataFormatterFoundException.cs" />
73+
<Compile Include="Reporting\AggregatedRenderer.cs" />
7374
<Compile Include="Reporting\ApproveResultsProcessor.cs" />
7475
<Compile Include="Reporting\ConvertibleFormatter.cs" />
7576
<Compile Include="Reporting\CsvReporter.cs" />
7677
<Compile Include="Reporting\DefaultFormatter.cs" />
7778
<Compile Include="Reporting\FallbackFormatter.cs" />
79+
<Compile Include="Reporting\GroupedByDataTypeRendererBase.cs" />
7880
<Compile Include="Reporting\HtmlReportRenderer.cs" />
7981
<Compile Include="Reporting\ConventionReportTextRenderer.cs" />
8082
<Compile Include="Reporting\ConventionReportTraceRenderer.cs" />
83+
<Compile Include="Reporting\MarkdownReportRenderer.cs" />
8184
<Compile Include="Reporting\ThrowOnFailureResultsProcessor.cs" />
8285
<Compile Include="Conventions\ClassTypeHasSpecificNamespace.cs" />
8386
<Compile Include="Conventions\ConventionSourceInvalidException.cs" />

0 commit comments

Comments
 (0)