Skip to content

Commit 44d35dd

Browse files
committed
apply report parameter pattern to stepdefinition report too
1 parent 2a325ee commit 44d35dd

8 files changed

+83
-77
lines changed

Reporting/NUnitExecutionReport/NUnitExecutionReportGenerator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class NUnitExecutionReportGenerator
1313
{
1414
private ReportElements.NUnitExecutionReport report;
1515
private readonly SpecFlowProject specFlowProject;
16-
private readonly TestExecutionReportParameters reportParameters;
16+
private readonly NUnitExecutionReportParameters reportParameters;
1717

18-
public NUnitExecutionReportGenerator(TestExecutionReportParameters reportParameters)
18+
public NUnitExecutionReportGenerator(NUnitExecutionReportParameters reportParameters)
1919
{
2020
specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(reportParameters.ProjectFile);
2121
this.reportParameters = reportParameters;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.IO;
2+
3+
namespace TechTalk.SpecFlow.Reporting.NUnitExecutionReport
4+
{
5+
public class NUnitExecutionReportParameters : ReportParameters
6+
{
7+
public string LabelledTestOutput { get; private set; }
8+
public string XmlTestResult { get; private set; }
9+
10+
public NUnitExecutionReportParameters(string projectFile, string xmlTestResult, string labelledTestOutput, string outputFile, string xsltFile)
11+
: base(projectFile, outputFile, xsltFile)
12+
{
13+
this.XmlTestResult = Path.GetFullPath(xmlTestResult);
14+
this.LabelledTestOutput = Path.GetFullPath(labelledTestOutput);
15+
}
16+
}
17+
}

Reporting/ReportParameters.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.IO;
2+
3+
namespace TechTalk.SpecFlow.Reporting
4+
{
5+
public abstract class ReportParameters
6+
{
7+
public string XsltFile { get; private set; }
8+
public string OutputFile { get; private set; }
9+
public string ProjectFile { get; private set; }
10+
11+
protected ReportParameters(string projectFile, string outputFile, string xsltFile)
12+
{
13+
this.ProjectFile = projectFile;
14+
this.OutputFile = Path.GetFullPath(outputFile);
15+
this.XsltFile = Path.GetFullPath(xsltFile);
16+
}
17+
}
18+
}

Reporting/StepDefinitionReport/StepDefinitionReportGenerator.cs

+17-21
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
using System.Linq;
77
using System.Text;
88
using System.Text.RegularExpressions;
9-
using System.Xml;
109
using System.Xml.Serialization;
11-
using System.Xml.Xsl;
1210
using TechTalk.SpecFlow.Generator.Configuration;
1311
using TechTalk.SpecFlow.Parser.SyntaxElements;
1412
using TechTalk.SpecFlow.Reporting.StepDefinitionReport.ReportElements;
@@ -17,42 +15,33 @@ namespace TechTalk.SpecFlow.Reporting.StepDefinitionReport
1715
{
1816
public class StepDefinitionReportGenerator
1917
{
18+
public StepDefinitionReportParameters ReportParameters { get; set; }
2019
private readonly SpecFlowProject specFlowProject;
2120
private readonly List<BindingInfo> bindings;
2221
private readonly List<Feature> parsedFeatures;
23-
private readonly bool showBindingsWithoutInsance;
2422

2523
private ReportElements.StepDefinitionReport report;
2624
private Dictionary<BindingInfo, StepDefinition> stepDefByBinding;
2725
private Dictionary<StepDefinition, BindingInfo> bindingByStepDef;
2826
private readonly List<StepDefinition> stepDefsWithNoBinding = new List<StepDefinition>();
2927

30-
public StepDefinitionReportGenerator(string projectFile, string binFolder, bool showBindingsWithoutInsance)
28+
public StepDefinitionReportGenerator(StepDefinitionReportParameters reportParameters)
3129
{
32-
specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(projectFile);
30+
ReportParameters = reportParameters;
3331

32+
specFlowProject = MsBuildProjectReader.LoadSpecFlowProjectFromMsBuild(reportParameters.ProjectFile);
3433
parsedFeatures = ParserHelper.GetParsedFeatures(specFlowProject);
3534

36-
var basePath = Path.Combine(specFlowProject.ProjectFolder, binFolder);
35+
var basePath = Path.Combine(specFlowProject.ProjectFolder, reportParameters.BinFolder);
3736
bindings = BindingCollector.CollectBindings(specFlowProject, basePath);
38-
39-
this.showBindingsWithoutInsance = showBindingsWithoutInsance;
40-
}
41-
42-
public StepDefinitionReportGenerator(SpecFlowProject specFlowProject, List<BindingInfo> bindings, List<Feature> parsedFeatures, bool showBindingsWithoutInsance)
43-
{
44-
this.specFlowProject = specFlowProject;
45-
this.showBindingsWithoutInsance = showBindingsWithoutInsance;
46-
this.bindings = bindings;
47-
this.parsedFeatures = parsedFeatures;
4837
}
4938

5039
public ReportElements.StepDefinitionReport GenerateReport()
5140
{
5241
report = new ReportElements.StepDefinitionReport();
5342
report.ProjectName = specFlowProject.ProjectName;
5443
report.GeneratedAt = DateTime.Now.ToString("g", CultureInfo.InvariantCulture);
55-
report.ShowBindingsWithoutInsance = showBindingsWithoutInsance;
44+
report.ShowBindingsWithoutInsance = ReportParameters.ShowBindingsWithoutInsance;
5645

5746
stepDefByBinding = new Dictionary<BindingInfo, StepDefinition>();
5847
bindingByStepDef = new Dictionary<StepDefinition, BindingInfo>();
@@ -215,17 +204,17 @@ private string GetSampleText(BindingInfo bindingInfo)
215204
return sampleText;
216205
}
217206

218-
public void TransformReport(string outputFilePath, string xsltFile)
207+
public void TransformReport()
219208
{
220209
XmlSerializer serializer = new XmlSerializer(typeof(ReportElements.StepDefinitionReport), ReportElements.StepDefinitionReport.XmlNamespace);
221210

222-
if (XsltHelper.IsXmlOutput(outputFilePath))
211+
if (XsltHelper.IsXmlOutput(ReportParameters.OutputFile))
223212
{
224-
XsltHelper.TransformXml(serializer, report, outputFilePath);
213+
XsltHelper.TransformXml(serializer, report, ReportParameters.OutputFile);
225214
}
226215
else
227216
{
228-
XsltHelper.TransformHtml(serializer, report, GetType(), outputFilePath, specFlowProject.GeneratorConfiguration, xsltFile);
217+
XsltHelper.TransformHtml(serializer, report, GetType(), ReportParameters.OutputFile, specFlowProject.GeneratorConfiguration, ReportParameters.XsltFile);
229218
}
230219
}
231220

@@ -355,5 +344,12 @@ private ScenarioStep CloneTo(ScenarioStep step, string currentBlock)
355344
newStep.TableArg = Clone(step.TableArg);
356345
return newStep;
357346
}
347+
348+
349+
public void GenerateAndTransformReport()
350+
{
351+
GenerateReport();
352+
TransformReport();
353+
}
358354
}
359355
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace TechTalk.SpecFlow.Reporting.StepDefinitionReport
7+
{
8+
public class StepDefinitionReportParameters : ReportParameters
9+
{
10+
public string BinFolder { get; private set; }
11+
public bool ShowBindingsWithoutInsance { get; private set; }
12+
13+
public StepDefinitionReportParameters(string projectFile, string outputFile, string xsltFile, string binFolder, bool showBindingsWithoutInsance)
14+
: base(projectFile, outputFile, xsltFile)
15+
{
16+
BinFolder = binFolder;
17+
ShowBindingsWithoutInsance = showBindingsWithoutInsance;
18+
}
19+
}
20+
}

Reporting/TechTalk.SpecFlow.Reporting.csproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="NUnitExecutionReport\NUnitExecutionReportGenerator.cs" />
6161
<Compile Include="NUnitExecutionReport\ReportElements\NUnitExecutionReport.cs" />
6262
<Compile Include="NUnitExecutionReport\ReportElements\ScenarioOutput.cs" />
63+
<Compile Include="ReportParameters.cs" />
6364
<Compile Include="ParserHelper.cs" />
6465
<Compile Include="Program.cs" />
6566
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -73,7 +74,8 @@
7374
<Compile Include="StepDefinitionReport\ReportElements\StepDefinitionReport.cs" />
7475
<Compile Include="ResourceXmlReader.cs" />
7576
<Compile Include="StepDefinitionReport\StepDefinitionReportGenerator.cs" />
76-
<Compile Include="TestExecutionReportParameters.cs" />
77+
<Compile Include="NUnitExecutionReport\NUnitExecutionReportParameters.cs" />
78+
<Compile Include="StepDefinitionReport\StepDefinitionReportParameters.cs" />
7779
<Compile Include="XmlResourceResolver.cs" />
7880
<Compile Include="XsltHelper.cs" />
7981
</ItemGroup>

Reporting/TestExecutionReportParameters.cs

-47
This file was deleted.

Tools/Program.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using NConsoler;
44
using TechTalk.SpecFlow.Generator;
55
using TechTalk.SpecFlow.Generator.Configuration;
6-
using TechTalk.SpecFlow.Reporting;
76
using TechTalk.SpecFlow.Reporting.NUnitExecutionReport;
87
using TechTalk.SpecFlow.Reporting.StepDefinitionReport;
98
using MsBuildProjectReader = TechTalk.SpecFlow.Generator.Configuration.MsBuildProjectReader;
@@ -38,9 +37,10 @@ public static void StepDefinitionReport(
3837
[Optional("bin\\Debug", Description = @"Path for Spec dll e.g. Company.Specs.dll. Defaults to bin\Debug ")] string binFolder,
3938
[Optional("StepDefinitionReport.html", "out", Description = "Generated Output File. Defaults to StepDefinitionReport.html")] string outputFile)
4039
{
41-
var generator = new StepDefinitionReportGenerator(projectFile, binFolder, true);
42-
generator.GenerateReport();
43-
generator.TransformReport(Path.GetFullPath(outputFile), xsltFile);
40+
StepDefinitionReportParameters reportParameters =
41+
new StepDefinitionReportParameters(projectFile, outputFile, xsltFile, binFolder, true);
42+
var generator = new StepDefinitionReportGenerator(reportParameters);
43+
generator.GenerateAndTransformReport();
4444
}
4545

4646
[Action("Formats an NUnit execution report to SpecFlow style")]
@@ -50,8 +50,8 @@ public static void NUnitExecutionReport([Required(Description = "Visual Studio P
5050
[Optional("TestResult.txt", "testOutput")] string labeledTestOutput,
5151
[Optional("TestResult.html", "out", Description = "Generated Output File. Defaults to TestResult.html")] string outputFile)
5252
{
53-
TestExecutionReportParameters reportParameters = new TestExecutionReportParameters
54-
(projectFile, xmlTestResult, labeledTestOutput, outputFile, xsltFile);
53+
NUnitExecutionReportParameters reportParameters =
54+
new NUnitExecutionReportParameters(projectFile, xmlTestResult, labeledTestOutput, outputFile, xsltFile);
5555
var generator = new NUnitExecutionReportGenerator(reportParameters);
5656
generator.GenerateAndTransformReport();
5757
}

0 commit comments

Comments
 (0)