Skip to content

Commit c211004

Browse files
author
Jake Ginnivan
committed
Removed EnsureHasNonEmptySource
1 parent 7766214 commit c211004

File tree

5 files changed

+50
-58
lines changed

5 files changed

+50
-58
lines changed

TestStack.ConventionTests.Tests/ConventionAssertionClassTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ public class FakeData : IConventionData
2424
{
2525
public string Description { get { return "Fake data"; } }
2626

27-
public void EnsureHasNonEmptySource()
28-
{
29-
}
27+
public bool HasData { get { return true; } }
3028

3129
public ConventionReportFailure Format(string failingData)
3230
{
@@ -39,7 +37,7 @@ public class FailingConvention : IConvention<FakeData>
3937
public string ConventionTitle { get { return "Header"; } }
4038
public IEnumerable<object> GetFailingData(FakeData data)
4139
{
42-
return new[] {"Different"};
40+
return new[] { "Different" };
4341
}
4442
}
4543
}

TestStack.ConventionTests/ConventionData/AbstractProjectData.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ protected AbstractProjectData(Assembly assembly, IProjectProvider projectProvide
2222

2323
public string Description { get { return Assembly.GetName().Name; } }
2424

25-
public void EnsureHasNonEmptySource()
26-
{
27-
if (ProjectLocator.ResolveProjectFilePath(Assembly) == null)
28-
throw new ConventionSourceInvalidException("Cannot resolve project file for assembly {0}");
29-
}
25+
public bool HasData { get { return ProjectLocator.ResolveProjectFilePath(Assembly) != null; } }
3026

3127
protected XDocument GetProject()
3228
{

TestStack.ConventionTests/ConventionData/Types.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
namespace TestStack.ConventionTests.ConventionData
22
{
33
using System;
4-
using TestStack.ConventionTests.Conventions;
5-
using TestStack.ConventionTests.Internal;
4+
using System.Linq;
65

76
/// <summary>
87
/// This is where we set what our convention is all about.
@@ -18,10 +17,6 @@ public Types(string descriptionOfTypes)
1817

1918
public string Description { get; private set; }
2019

21-
public void EnsureHasNonEmptySource()
22-
{
23-
if (TypesToVerify.None())
24-
throw new ConventionSourceInvalidException("You must supply types to verify");
25-
}
20+
public bool HasData {get { return TypesToVerify.Any(); }}
2621
}
2722
}

TestStack.ConventionTests/IConventionData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
public interface IConventionData
44
{
55
string Description { get; }
6-
void EnsureHasNonEmptySource();
6+
bool HasData { get; }
77
}
88
}
Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
namespace TestStack.ConventionTests.Internal
2-
{
3-
using System.Linq;
4-
using TestStack.ConventionTests.Reporting;
5-
6-
public static class Executor
7-
{
8-
public static ResultInfo GetConventionReport(string conventionTitle, object[] failingData, IConventionData data)
9-
{
10-
data.EnsureHasNonEmptySource();
11-
var passed = failingData.None();
12-
13-
var conventionResult = new ResultInfo(
14-
passed ? TestResult.Passed : TestResult.Failed,
15-
conventionTitle,
16-
data.Description,
17-
failingData.Select(FormatData).ToArray());
18-
return conventionResult;
19-
}
20-
21-
public static ResultInfo GetConventionReportWithApprovedExeptions(string conventionTitle, object[] failingData, IConventionData data)
22-
{
23-
var conventionResult = Executor.GetConventionReport(conventionTitle, failingData, data);
24-
var conventionReportTextRenderer = new ConventionReportTextRenderer();
25-
// Add approved exceptions to report
26-
conventionReportTextRenderer.RenderItems(conventionResult);
27-
conventionResult.WithApprovedException(conventionReportTextRenderer.Output);
28-
29-
return conventionResult;
30-
}
31-
32-
static ConventionReportFailure FormatData<T>(T failingData)
33-
{
34-
var formatter = Convention.Formatters.FirstOrDefault(f => f.CanFormat(failingData));
35-
36-
if (formatter == null)
37-
throw new NoDataFormatterFoundException(typeof(T).Name + " has no formatter, add one with `Convention.Formatters.Add(new MyDataFormatter());`");
38-
39-
return formatter.Format(failingData);
40-
}
41-
}
1+
namespace TestStack.ConventionTests.Internal
2+
{
3+
using System.Linq;
4+
using TestStack.ConventionTests.Conventions;
5+
using TestStack.ConventionTests.Reporting;
6+
7+
public static class Executor
8+
{
9+
public static ResultInfo GetConventionReport(string conventionTitle, object[] failingData, IConventionData data)
10+
{
11+
if (!data.HasData)
12+
throw new ConventionSourceInvalidException(string.Format("{0} has no data", data.Description));
13+
14+
var passed = failingData.None();
15+
16+
var conventionResult = new ResultInfo(
17+
passed ? TestResult.Passed : TestResult.Failed,
18+
conventionTitle,
19+
data.Description,
20+
failingData.Select(FormatData).ToArray());
21+
return conventionResult;
22+
}
23+
24+
public static ResultInfo GetConventionReportWithApprovedExeptions(string conventionTitle, object[] failingData, IConventionData data)
25+
{
26+
var conventionResult = Executor.GetConventionReport(conventionTitle, failingData, data);
27+
var conventionReportTextRenderer = new ConventionReportTextRenderer();
28+
// Add approved exceptions to report
29+
conventionReportTextRenderer.RenderItems(conventionResult);
30+
conventionResult.WithApprovedException(conventionReportTextRenderer.Output);
31+
32+
return conventionResult;
33+
}
34+
35+
static ConventionReportFailure FormatData<T>(T failingData)
36+
{
37+
var formatter = Convention.Formatters.FirstOrDefault(f => f.CanFormat(failingData));
38+
39+
if (formatter == null)
40+
throw new NoDataFormatterFoundException(typeof(T).Name + " has no formatter, add one with `Convention.Formatters.Add(new MyDataFormatter());`");
41+
42+
return formatter.Format(failingData);
43+
}
44+
}
4245
}

0 commit comments

Comments
 (0)