Skip to content

Commit 1e9770d

Browse files
author
Jake Ginnivan
committed
Improved Html reporting, much happier with this. Except the styles, they still blow
1 parent b782207 commit 1e9770d

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

TestStack.ConventionTests/Convention.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Reflection;
66
using System.Text.RegularExpressions;
7+
using TestStack.ConventionTests.ConventionData;
78
using TestStack.ConventionTests.Internal;
89
using TestStack.ConventionTests.Reporting;
910

@@ -50,7 +51,7 @@ static void Execute<TDataSource>(IConvention<TDataSource> convention, TDataSourc
5051
IResultsProcessor[] processors, ITestResultProcessor resultProcessor)
5152
where TDataSource : IConventionData
5253
{
53-
var dataDescription = string.Format("{0} in {1}", ToSentenceCase(data.GetType().Name), data.Description);
54+
var dataDescription = string.Format("{0} in {1}", data.GetType().GetSentenceCaseName(), data.Description);
5455
var context = new ConventionContext(dataDescription, Formatters, processors, resultProcessor);
5556
context.Execute(convention, data);
5657
}
@@ -76,10 +77,5 @@ static void Init(Assembly assembly)
7677
defaultProcessors[defaultProcessors.Length - 1] = new ThrowOnFailureResultsProcessor();
7778
defaultApprovalProcessors[defaultProcessors.Length - 1] = new ApproveResultsProcessor();
7879
}
79-
80-
static string ToSentenceCase(string str)
81-
{
82-
return Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1]));
83-
}
8480
}
8581
}

TestStack.ConventionTests/ConventionData/TypeExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Reflection;
7+
using System.Text.RegularExpressions;
78

89
public static class TypeExtensions
910
{
@@ -66,5 +67,10 @@ public static bool ClosesInterface(this Type t, Type openGeneric)
6667
{
6768
return t.GetClosedInterfacesOf(openGeneric).Any();
6869
}
70+
71+
internal static string GetSentenceCaseName(this Type type)
72+
{
73+
return Regex.Replace(type.Name, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1]));
74+
}
6975
}
7076
}

TestStack.ConventionTests/Reporting/HtmlConventionResultsReporter.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using System.Web.UI;
8+
using TestStack.ConventionTests.ConventionData;
89
using TestStack.ConventionTests.Internal;
910

1011
public class HtmlConventionResultsReporter : GroupedByDataTypeConventionResultsReporterBase
@@ -61,28 +62,35 @@ protected override string Process(IConventionFormatContext context, IEnumerable<
6162
conventionResult.DataDescription.Replace("'", string.Empty).Replace(" ", string.Empty).Replace(".", string.Empty);
6263
html.AddAttribute("style", "margin-left:20px;");
6364
html.RenderBeginTag(HtmlTextWriterTag.H4);
64-
65-
html.AddAttribute("class", "menu-toggle");
66-
html.AddAttribute("data-toggle", "collapse");
67-
html.AddAttribute("data-target", "." + targetId);
68-
html.RenderBeginTag(HtmlTextWriterTag.A);
69-
html.AddAttribute("class", "icon-angle-down");
70-
html.RenderBeginTag(HtmlTextWriterTag.I);
71-
html.RenderEndTag();
72-
html.RenderEndTag();
7365
html.Write(conventionResult.ConventionTitle);
7466
html.RenderEndTag();
75-
html.AddAttribute("class", targetId + " collapse");
76-
html.AddAttribute("style", "margin-left:20px;");
77-
html.RenderBeginTag(HtmlTextWriterTag.Div);
78-
html.RenderBeginTag(HtmlTextWriterTag.Ul);
79-
foreach (var o in conventionResult.Data)
67+
if (conventionResult.Data.Any())
8068
{
81-
html.RenderBeginTag(HtmlTextWriterTag.Li);
82-
html.Write(context.FormatDataAsHtml(o));
69+
html.AddAttribute("style", "margin-left:20px;");
70+
html.RenderBeginTag(HtmlTextWriterTag.Div);
71+
html.AddAttribute("class", "menu-toggle");
72+
html.AddAttribute("data-toggle", "collapse");
73+
html.AddAttribute("data-target", "." + targetId);
74+
html.RenderBeginTag(HtmlTextWriterTag.A);
75+
html.AddAttribute("class", "icon-angle-down");
76+
html.RenderBeginTag(HtmlTextWriterTag.I);
77+
html.RenderEndTag();
78+
html.Write("With the exception of the following {0}: ", conventionResult.DataType.GetSentenceCaseName());
79+
html.RenderEndTag();
80+
html.AddAttribute("class", targetId + " collapse");
81+
html.AddAttribute("style", "margin-left:20px;");
82+
html.RenderBeginTag(HtmlTextWriterTag.Div);
83+
html.RenderBeginTag(HtmlTextWriterTag.Ul);
84+
foreach (var o in conventionResult.Data)
85+
{
86+
html.RenderBeginTag(HtmlTextWriterTag.Li);
87+
html.Write(context.FormatDataAsHtml(o));
88+
html.RenderEndTag();
89+
}
90+
html.RenderEndTag();
8391
html.RenderEndTag();
8492
}
85-
html.RenderEndTag();
93+
8694
html.RenderEndTag();
8795
}
8896
html.RenderEndTag();

0 commit comments

Comments
 (0)