11namespace TestStack . ConventionTests
22{
33 using System ;
4- using System . Collections . Generic ;
5- using System . Linq ;
6- using System . Reflection ;
7- using System . Text ;
4+ using ApprovalTests ;
85
96 public static class Convention
107 {
11- public static void Is < T , T2 > ( IEnumerable < T2 > itemsToVerify ) where T : ConventionData < T2 > , new ( )
12- {
13- Is ( new T ( ) , itemsToVerify ) ;
14- }
15- public static void Is < T , T2 > ( IEnumerable < T2 > itemsToVerify , Func < string , bool > filter )
16- where T : ConventionData < T2 > , IRuntimeFilter < string > , new ( )
17- {
18- Is ( new T ( ) , itemsToVerify ) ;
19- }
20- public static void Is < T , T2 , TItem > ( IEnumerable < T2 > itemsToVerify , Func < TItem , bool > filter )
21- where T : ConventionData < T2 > , IRuntimeFilter < TItem > , new ( )
22- {
23- Is ( new T ( ) , itemsToVerify ) ;
24- }
25-
26- //Item.Is<ConventionData<Type>>
27- public static void Is < T > ( IEnumerable < Type > itemsToVerify ) where T : ConventionData < Type > , new ( )
28- {
29- Is ( new T ( ) , itemsToVerify ) ;
30- }
31- public static void Is < T > ( IEnumerable < Type > itemsToVerify , Func < string , bool > filter ) where T : ConventionData < Type > , IRuntimeFilter < string > , new ( )
32- {
33- Is ( new T ( ) , itemsToVerify , filter ) ;
34- }
35- public static void Is < T , TItem > ( IEnumerable < Type > itemsToVerify , Func < TItem , bool > filter ) where T : ConventionData < Type > , IRuntimeFilter < TItem > , new ( )
36- {
37- Is ( new T ( ) , itemsToVerify , filter ) ;
38- }
8+ public static readonly ConventionSettings Settings = new ConventionSettings ( ) ;
399
40- //Item.Is<ConventionData<Assembly>>
41- public static void Is < T > ( IEnumerable < Assembly > itemsToVerify ) where T : ConventionData < Assembly > , new ( )
10+ public static void Is < TData > ( IConvention < TData > convention , TData data ) where TData : IConventionData
4211 {
43- Is ( new T ( ) , itemsToVerify ) ;
44- }
45- public static void Is < T > ( IEnumerable < Assembly > itemsToVerify , Func < string , bool > filter ) where T : ConventionData < Assembly > , IRuntimeFilter < string > , new ( )
46- {
47- Is ( new T ( ) , itemsToVerify , filter ) ;
48- }
49- public static void Is < T , TItem > ( IEnumerable < Assembly > itemsToVerify , Func < TItem , bool > filter ) where T : ConventionData < Assembly > , IRuntimeFilter < TItem > , new ( )
50- {
51- Is ( new T ( ) , itemsToVerify , filter ) ;
52- }
53-
54- public static void Is < T > ( ConventionData < T > convention , IEnumerable < T > itemsToVerify )
55- {
56- var results = Result ( convention , itemsToVerify ) ;
57- if ( ! string . IsNullOrEmpty ( results ) )
58- throw new ConventionFailedException ( results ) ;
59- }
60-
61- public static void Is < TConvention , T > ( TConvention convention , IEnumerable < T > itemsToVerify , Func < string , bool > itemFilter )
62- where TConvention : ConventionData < T > , IRuntimeFilter < string >
63- {
64- Is < TConvention , T , string > ( convention , itemsToVerify , itemFilter ) ;
12+ if ( data . HasValidSource == false )
13+ {
14+ // TODO: this would have to have a more reasonable and helpful message...
15+ Settings . AssertInclunclusive ( "No valid source in " + data ) ;
16+ return ;
17+ }
18+ var result = convention . Execute ( data ) ;
19+ if ( result . IsConclusive == false )
20+ {
21+ Settings . AssertInclunclusive ( result . Message ) ;
22+ return ;
23+ }
24+ if ( data . HasApprovedExceptions )
25+ {
26+ // should we encapsulate Approvals behind Settings?
27+ Approvals . Verify ( result . Message ) ;
28+ return ;
29+ }
30+ Settings . AssertZero ( result . InvalidResultsCount , result . Message ) ;
6531 }
6632
67- public static void Is < TConvention , T , TItem > ( TConvention convention , IEnumerable < T > itemsToVerify , Func < TItem , bool > itemFilter )
68- where TConvention : ConventionData < T > , IRuntimeFilter < TItem >
33+ public class ConventionSettings
6934 {
70- var results = Result ( convention , itemsToVerify , itemFilter ) ;
71- if ( ! string . IsNullOrEmpty ( results ) )
72- throw new ConventionFailedException ( results ) ;
73- }
35+ public Action < String > AssertInclunclusive ;
7436
75- public static string Result < T > ( ConventionData < T > convention , IEnumerable < T > itemsToVerify )
76- {
77- var message = new StringBuilder ( ) ;
78- var invalidItems = itemsToVerify . Where ( i => ! convention . Must ( i ) ) . ToArray ( ) ;
79- if ( ! invalidItems . Any ( ) ) return null ;
37+ public Action < int , string > AssertZero ;
8038
81- message . AppendLine ( convention . Description ?? "Convention has failing items" ) ;
82- foreach ( var invalidType in invalidItems )
39+ public ConventionSettings ( )
8340 {
84- message . Append ( '\t ' ) ;
85- convention . ItemDescription ( invalidType , message ) ;
41+ // TODO: initialize the type;
8642 }
87-
88- return message . ToString ( ) ;
89- }
90-
91- public static string Result < TConvention , T , TItem > ( TConvention convention , IEnumerable < T > itemsToVerify , Func < TItem , bool > itemFilter )
92- where TConvention : ConventionData < T > , IRuntimeFilter < TItem >
93- {
94- convention . SetFilter ( itemFilter ) ;
95- return Result ( convention , itemsToVerify ) ;
9643 }
9744 }
9845}
0 commit comments