Skip to content

Commit 768b444

Browse files
author
Jake Ginnivan
committed
Got rid of ConventionReportFailure
1 parent e26c93b commit 768b444

15 files changed

+44
-80
lines changed

TestStack.ConventionTests.Tests/ConventionAssertionClassTests.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
using ApprovalTests.Reporters;
44
using NUnit.Framework;
5-
using TestStack.ConventionTests.Internal;
65

76
[TestFixture]
87
[UseReporter(typeof(QuietReporter))] //NOTE: Can we take care of this in IsWithApprovedExceptions?
@@ -19,19 +18,14 @@ public void approval_mismatch()
1918
StringAssert.Contains("does not match approved file", ex.Message);
2019
}
2120

22-
public class FakeData : IConventionData
21+
class FakeData : IConventionData
2322
{
2423
public string Description { get { return "Fake data"; } }
2524

2625
public bool HasData { get { return true; } }
27-
28-
public ConventionReportFailure Format(string failingData)
29-
{
30-
return new ConventionReportFailure(failingData);
31-
}
3226
}
3327

34-
public class FailingConvention : IConvention<FakeData>
28+
class FailingConvention : IConvention<FakeData>
3529
{
3630
public void Execute(FakeData data, IConventionResultContext result)
3731
{

TestStack.ConventionTests/Internal/ConventionContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ITestResultProcessor IConventionFormatContext.TestResultProcessor
3333
get { return testResultProcessor; }
3434
}
3535

36-
ConventionReportFailure IConventionFormatContext.FormatData(object failingData)
36+
string IConventionFormatContext.FormatDataAsString(object failingData)
3737
{
3838
IReportDataFormatter formatter = formatters.FirstOrDefault(f => f.CanFormat(failingData));
3939
if (formatter == null)
@@ -43,7 +43,7 @@ ConventionReportFailure IConventionFormatContext.FormatData(object failingData)
4343
" has no formatter, add one with `Convention.Formatters.Add(new MyDataFormatter());`");
4444
}
4545

46-
return formatter.Format(failingData);
46+
return formatter.FormatString(failingData);
4747
}
4848

4949
void IConventionResultContext.Is<TResult>(string resultTitle, IEnumerable<TResult> failingData)

TestStack.ConventionTests/Internal/ConventionReportFailure.cs

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

TestStack.ConventionTests/Internal/IConventionFormatContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public interface IConventionFormatContext
66
{
7-
ConventionReportFailure FormatData(object failingData);
7+
string FormatDataAsString(object failingData);
88
ITestResultProcessor TestResultProcessor { get; }
99
}
1010
}

TestStack.ConventionTests/Reporting/ConventionReportTextRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void RenderItems(ConventionResult resultInfo, StringBuilder stringBuilder
2525
foreach (var conventionFailure in resultInfo.Data)
2626
{
2727
stringBuilder.Append("\t");
28-
stringBuilder.AppendLine(context.FormatData(conventionFailure).ToString());
28+
stringBuilder.AppendLine(context.FormatDataAsString(conventionFailure));
2929
}
3030
}
3131
}

TestStack.ConventionTests/Reporting/ConvertibleFormatter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ namespace TestStack.ConventionTests.Reporting
33
using System;
44
using System.Diagnostics;
55
using System.Globalization;
6-
using TestStack.ConventionTests.Internal;
76

87
public class ConvertibleFormatter : IReportDataFormatter
98
{
@@ -12,11 +11,11 @@ public bool CanFormat(object failingData)
1211
return failingData is IConvertible;
1312
}
1413

15-
public ConventionReportFailure Format(object failingData)
14+
public string FormatString(object failingData)
1615
{
1716
var convertible = failingData as IConvertible;
1817
Debug.Assert(convertible != null, "convertible != null");
19-
return new ConventionReportFailure(convertible.ToString(CultureInfo.InvariantCulture));
18+
return convertible.ToString(CultureInfo.InvariantCulture);
2019
}
2120
}
2221
}

TestStack.ConventionTests/Reporting/DefaultFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ string Describe(PropertyInfo property)
2727

2828
public string[] DesribeItem(object result, IConventionFormatContext context)
2929
{
30-
return properties.Select(p => context.FormatData(p.GetValue(result, null)).ToString()).ToArray();
30+
return properties.Select(p => context.FormatDataAsString(p.GetValue(result, null)).ToString()).ToArray();
3131
}
3232
}
3333
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
namespace TestStack.ConventionTests.Reporting
22
{
3-
using TestStack.ConventionTests.Internal;
4-
53
public class FallbackFormatter : IReportDataFormatter
64
{
75
public bool CanFormat(object failingData)
86
{
97
return true;
108
}
119

12-
public ConventionReportFailure Format(object failingData)
10+
public string FormatString(object failingData)
1311
{
14-
// TODO: for now
15-
return new ConventionReportFailure(failingData.ToString());
12+
if (failingData == null)
13+
return "<null>";
14+
return failingData.ToString();
1615
}
1716
}
1817
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace TestStack.ConventionTests.Reporting
22
{
3-
using TestStack.ConventionTests.Internal;
4-
53
public interface IReportDataFormatter
64
{
75
bool CanFormat(object failingData);
8-
ConventionReportFailure Format(object failingData);
6+
string FormatString(object failingData);
97
}
108
}
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
namespace TestStack.ConventionTests.Reporting
1+
namespace TestStack.ConventionTests.Reporting
22
{
3-
using System.ComponentModel;
43
using System.Reflection;
5-
using ApprovalTests.Namers;
6-
using TestStack.ConventionTests.Internal;
74

8-
public class MethodInfoDataFormatter : IReportDataFormatter
9-
{
10-
public bool CanFormat(object failingData)
11-
{
12-
return failingData is MethodInfo;
13-
}
14-
15-
public ConventionReportFailure Format(object failingData)
16-
{
17-
var methodInfo = (MethodInfo)failingData;
18-
19-
return new ConventionReportFailure(methodInfo.DeclaringType + "." + methodInfo.Name);
20-
}
21-
}
5+
public class MethodInfoDataFormatter : IReportDataFormatter
6+
{
7+
public bool CanFormat(object failingData)
8+
{
9+
return failingData is MethodInfo;
10+
}
11+
12+
public string FormatString(object failingData)
13+
{
14+
var methodInfo = (MethodInfo)failingData;
15+
16+
return methodInfo.DeclaringType + "." + methodInfo.Name;
17+
}
18+
}
2219
}

0 commit comments

Comments
 (0)