Skip to content

Commit 84e448f

Browse files
committed
removed Executor, sidenote - Resharper is the bee's knees
All it took was two refactorings: - move method to another type - make method non-static that's it - no extra manual work, it even folded the ConventionContext parameter and replaced it with 'this' where required. Respect
1 parent ceec835 commit 84e448f

File tree

4 files changed

+35
-43
lines changed

4 files changed

+35
-43
lines changed

TestStack.ConventionTests/Convention.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public static void Is<TDataSource>(IConvention<TDataSource> convention, TDataSou
4040
{
4141
try
4242
{
43-
var conventionResult = Executor.GetConventionResults(convention, data);
43+
var context = new ConventionContext(data.Description, Formatters);
44+
var conventionResult = context.GetConventionResults(convention, data);
4445
Reports.AddRange(conventionResult);
4546

4647
new ConventionReportTraceRenderer().Render(conventionResult);
@@ -55,7 +56,8 @@ public static void Is<TDataSource>(IConvention<TDataSource> convention, TDataSou
5556
public static void IsWithApprovedExeptions<TDataSource>(IConvention<TDataSource> convention, TDataSource data)
5657
where TDataSource : IConventionData
5758
{
58-
var conventionResult = Executor.GetConventionResultsWithApprovedExeptions(convention, data);
59+
var context = new ConventionContext(data.Description, Formatters);
60+
var conventionResult = context.GetConventionResultsWithApprovedExeptions(convention, data);
5961
Reports.AddRange(conventionResult);
6062

6163
try

TestStack.ConventionTests/Internal/ConventionContext.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using TestStack.ConventionTests.Conventions;
67
using TestStack.ConventionTests.Reporting;
78

89
public class ConventionContext : IConventionResultContext
@@ -75,5 +76,35 @@ ConventionReportFailure FormatData<T>(T failingData)
7576

7677
return formatter.Format(failingData);
7778
}
79+
80+
public ConventionResult[] GetConventionResults<TDataSource>(IConvention<TDataSource> convention, TDataSource data)
81+
where TDataSource : IConventionData
82+
{
83+
if (!data.HasData)
84+
throw new ConventionSourceInvalidException(String.Format("{0} has no data", data.Description));
85+
86+
convention.Execute(data, this);
87+
88+
return ConventionResults;
89+
}
90+
91+
public ConventionResult[] GetConventionResultsWithApprovedExeptions<TDataSource>(
92+
IConvention<TDataSource> convention, TDataSource data)
93+
where TDataSource : IConventionData
94+
{
95+
var conventionReportTextRenderer = new ConventionReportTextRenderer();
96+
// Add approved exceptions to report
97+
if (!data.HasData)
98+
throw new ConventionSourceInvalidException(String.Format("{0} has no data", data.Description));
99+
100+
convention.Execute(data, this);
101+
foreach (var conventionResult in ConventionResults)
102+
{
103+
conventionReportTextRenderer.RenderItems(conventionResult);
104+
conventionResult.WithApprovedException(conventionReportTextRenderer.Output);
105+
}
106+
107+
return ConventionResults;
108+
}
78109
}
79110
}

TestStack.ConventionTests/Internal/Executor.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

TestStack.ConventionTests/TestStack.ConventionTests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
<Compile Include="IConventionResultContext.cs" />
6565
<Compile Include="Internal\ConventionReportFailure.cs" />
6666
<Compile Include="Internal\ConventionContext.cs" />
67-
<Compile Include="Internal\Executor.cs" />
6867
<Compile Include="Internal\ConventionResult.cs" />
6968
<Compile Include="Internal\NoDataFormatterFoundException.cs" />
7069
<Compile Include="Reporting\CsvReporter.cs" />

0 commit comments

Comments
 (0)