1
1
namespace TestStack . ConventionTests
2
2
{
3
3
using System ;
4
- using System . Collections . Generic ;
5
- using System . Linq ;
6
- using System . Reflection ;
7
- using System . Text ;
4
+ using ApprovalTests ;
8
5
9
6
public static class Convention
10
7
{
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 ( ) ;
39
9
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
42
11
{
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 ) ;
65
31
}
66
32
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
69
34
{
70
- var results = Result ( convention , itemsToVerify , itemFilter ) ;
71
- if ( ! string . IsNullOrEmpty ( results ) )
72
- throw new ConventionFailedException ( results ) ;
73
- }
35
+ public Action < String > AssertInclunclusive ;
74
36
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 ;
80
38
81
- message . AppendLine ( convention . Description ?? "Convention has failing items" ) ;
82
- foreach ( var invalidType in invalidItems )
39
+ public ConventionSettings ( )
83
40
{
84
- message . Append ( '\t ' ) ;
85
- convention . ItemDescription ( invalidType , message ) ;
41
+ // TODO: initialize the type;
86
42
}
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 ) ;
96
43
}
97
44
}
98
45
}
0 commit comments