66 using TestStack . ConventionTests . Conventions ;
77 using TestStack . ConventionTests . Reporting ;
88
9- public class ConventionContext : IConventionResultContext
9+ public class ConventionContext : IConventionResultContext , IConventionFormatContext
1010 {
1111 readonly string dataDescription ;
1212 readonly IList < IReportDataFormatter > formatters ;
@@ -26,12 +26,25 @@ public ConventionResult[] ConventionResults
2626 get { return results . ToArray ( ) ; }
2727 }
2828
29+ ConventionReportFailure IConventionFormatContext . FormatData ( object failingData )
30+ {
31+ var formatter = formatters . FirstOrDefault ( f => f . CanFormat ( failingData ) ) ;
32+ if ( formatter == null )
33+ {
34+ throw new NoDataFormatterFoundException (
35+ failingData . GetType ( ) . Name +
36+ " has no formatter, add one with `Convention.Formatters.Add(new MyDataFormatter());`" ) ;
37+ }
38+
39+ return formatter . Format ( failingData ) ;
40+ }
41+
2942 void IConventionResultContext . Is < T > ( string resultTitle , IEnumerable < T > failingData )
3043 {
3144 // ReSharper disable PossibleMultipleEnumeration
3245 results . Add ( new ConventionResult ( resultTitle ,
3346 dataDescription ,
34- failingData . Select ( FormatData ) . ToArray ( ) ) ) ;
47+ failingData . ToObjectArray ( ) ) ) ;
3548 }
3649
3750 void IConventionResultContext . IsSymmetric < TResult > (
@@ -40,10 +53,10 @@ void IConventionResultContext.IsSymmetric<TResult>(
4053 {
4154 results . Add ( new ConventionResult ( firstSetFailureTitle ,
4255 dataDescription ,
43- firstSetFailureData . Select ( FormatData ) . ToArray ( ) ) ) ;
56+ firstSetFailureData . ToObjectArray ( ) ) ) ;
4457 results . Add ( new ConventionResult ( secondSetFailureTitle ,
4558 dataDescription ,
46- secondSetFailureData . Select ( FormatData ) . ToArray ( ) ) ) ;
59+ secondSetFailureData . ToObjectArray ( ) ) ) ;
4760 }
4861
4962 void IConventionResultContext . IsSymmetric < TResult > (
@@ -61,19 +74,6 @@ void IConventionResultContext.IsSymmetric<TResult>(
6174 secondSetFailureTitle , secondSetFailingData ) ;
6275 }
6376
64- ConventionReportFailure FormatData < T > ( T failingData )
65- {
66- var formatter = formatters . FirstOrDefault ( f => f . CanFormat ( failingData ) ) ;
67- if ( formatter == null )
68- {
69- throw new NoDataFormatterFoundException (
70- typeof ( T ) . Name +
71- " has no formatter, add one with `Convention.Formatters.Add(new MyDataFormatter());`" ) ;
72- }
73-
74- return formatter . Format ( failingData ) ;
75- }
76-
7777 public void Execute < TDataSource > ( IConvention < TDataSource > convention , TDataSource data )
7878 where TDataSource : IConventionData
7979 {
@@ -83,7 +83,7 @@ public void Execute<TDataSource>(IConvention<TDataSource> convention, TDataSourc
8383
8484 foreach ( var resultsProcessor in processors )
8585 {
86- resultsProcessor . Process ( ConventionResults ) ;
86+ resultsProcessor . Process ( this , ConventionResults ) ;
8787 }
8888 }
8989 }
0 commit comments