Skip to content

Commit 603f628

Browse files
committed
brought back the original reporter/formatter for CSV
1 parent 75d5efd commit 603f628

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace TestStack.ConventionTests.Reporting
2+
{
3+
using System.Collections;
4+
using System.Text;
5+
6+
public class CsvReporter
7+
{
8+
public string Build(IEnumerable results, string header, DefaultFormatter formatter)
9+
{
10+
var message = new StringBuilder();
11+
message.AppendLine(string.Join(",", formatter.DesribeType()));
12+
foreach (var result in results)
13+
{
14+
message.AppendLine(string.Join(",", formatter.DesribeItem(result)));
15+
}
16+
return message.ToString();
17+
}
18+
}
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace TestStack.ConventionTests.Reporting
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Reflection;
6+
7+
public class DefaultFormatter
8+
{
9+
readonly PropertyInfo[] properties;
10+
readonly Type type;
11+
12+
public DefaultFormatter(Type type)
13+
{
14+
this.type = type;
15+
properties = type.GetProperties();
16+
}
17+
18+
// TODO: this is a very crappy name for a method
19+
public string[] DesribeType()
20+
{
21+
return properties.Select(Describe).ToArray();
22+
}
23+
24+
string Describe(PropertyInfo property)
25+
{
26+
return property.Name.Replace('_', ' ');
27+
}
28+
29+
public string[] DesribeItem(object result)
30+
{
31+
return properties.Select(p => p.GetValue(result, null).ToString()).ToArray();
32+
}
33+
}
34+
}

TestStack.ConventionTests/TestStack.ConventionTests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
<Compile Include="Internal\Executor.cs" />
6868
<Compile Include="Internal\ResultInfo.cs" />
6969
<Compile Include="Internal\NoDataFormatterFoundException.cs" />
70+
<Compile Include="Reporting\CsvReporter.cs" />
71+
<Compile Include="Reporting\DefaultFormatter.cs" />
7072
<Compile Include="Reporting\HtmlReportRenderer.cs" />
7173
<Compile Include="Reporting\ConventionReportTextRenderer.cs" />
7274
<Compile Include="Reporting\ConventionReportTraceRenderer.cs" />

0 commit comments

Comments
 (0)