Expand file tree Collapse file tree 5 files changed +70
-8
lines changed Original file line number Diff line number Diff line change @@ -44,24 +44,55 @@ public override async Task<ConventionResult> IsSatisfiedBy(Type type)
44
44
45
45
public class AsyncConformistScenarios
46
46
{
47
+ [ SetUp ]
48
+ public void Setup ( )
49
+ {
50
+ ConventionConfiguration . GlobalTypeFilter = type => type != typeof ( YouCantSeeMe ) ;
51
+ }
52
+
47
53
[ Test ]
48
54
public void HappyPath_DoesNotThrowExceptions ( )
49
55
{
50
- Action action = async ( ) => await typeof ( String ) . MustConformTo ( new AlwaysSuccessfulAsyncConvention ( ) ) ;
56
+ Action action = async ( ) => await typeof ( String ) . MustConformTo ( new AlwaysSuccessfulAsyncConvention ( ) ) ;
51
57
52
58
action . ShouldNotThrow ( ) ;
53
59
}
54
60
55
61
[ Test ]
56
62
public async Task FluentSyntax_OutputsExpectedFailuresInCorrectOrder ( )
57
63
{
58
- var results = await new [ ] { typeof ( String ) }
64
+ var results = await new [ ] { typeof ( String ) }
59
65
. MustConformTo ( new NeverSuccessfulAsyncConvention ( ) )
60
66
. AndMustConformTo ( new AlsoNeverSuccessfulAsyncConvention ( ) ) ;
61
67
62
68
results . Failures . Should ( ) . HaveCount ( 2 ) ;
63
69
results . Failures [ 0 ] . Should ( ) . StartWith ( "I failed!" ) ;
64
70
results . Failures [ 1 ] . Should ( ) . StartWith ( "I also failed!" ) ;
65
71
}
72
+
73
+ private class YouCantSeeMe
74
+ {
75
+ public string Name { get ; set ; }
76
+ }
77
+
78
+ private class YouCanSeeMe
79
+ {
80
+ public string Name { get ; set ; }
81
+ }
82
+
83
+ [ Test ]
84
+ public async Task WhenDefaultTypeFilterIsSet_ItIsAppliedToAllConventions ( )
85
+ {
86
+ var result = await new [ ] { typeof ( YouCantSeeMe ) , typeof ( YouCanSeeMe ) }
87
+ . MustConformTo ( new NeverSuccessfulAsyncConvention ( ) ) ;
88
+
89
+ result . Failures . Should ( ) . HaveCount ( 1 ) ;
90
+ }
91
+
92
+ [ TearDown ]
93
+ public void TearDown ( )
94
+ {
95
+ ConventionConfiguration . ResetGlobalTypeFilter ( ) ;
96
+ }
66
97
}
67
98
}
Original file line number Diff line number Diff line change 1
- using NUnit . Framework ;
1
+ using FluentAssertions ;
2
+ using NUnit . Framework ;
2
3
3
4
namespace Conventional . Tests
4
5
{
@@ -8,8 +9,9 @@ public class ConventionConfigurationScenarios
8
9
public void Setup ( )
9
10
{
10
11
ConventionConfiguration . DefaultFailureAssertionCallback = Assert . Pass ;
12
+ ConventionConfiguration . GlobalTypeFilter = type => type != typeof ( YouCantSeeMe ) ;
11
13
}
12
-
14
+
13
15
private class AbjectConformanceFailure
14
16
{
15
17
public AbjectConformanceFailure ( string name , string description )
@@ -39,11 +41,30 @@ public void WhenDefaultFailureAssertionIsSet_AndWeHaveACompositeConvention_Autom
39
41
Convention . PropertiesMustHavePublicSetters . And (
40
42
Convention . MustHaveADefaultConstructor ) ) ) ;
41
43
}
44
+
45
+ private class YouCantSeeMe
46
+ {
47
+ public string Name { get ; set ; }
48
+ }
49
+
50
+ private class YouCanSeeMe
51
+ {
52
+ public string Name { get ; set ; }
53
+ }
54
+
55
+ [ Test ]
56
+ public void WhenDefaultTypeFilterIsSet_ItIsAppliedToAllConventions ( )
57
+ {
58
+ new [ ] { typeof ( YouCantSeeMe ) , typeof ( YouCanSeeMe ) }
59
+ . MustConformTo ( Convention . PropertiesMustHavePrivateSetters )
60
+ . Failures . Should ( ) . HaveCount ( 1 ) ;
61
+ }
42
62
43
63
[ TearDown ]
44
64
public void TearDown ( )
45
65
{
46
66
ConventionConfiguration . DefaultFailureAssertionCallback = null ;
67
+ ConventionConfiguration . ResetGlobalTypeFilter ( ) ;
47
68
}
48
69
}
49
70
}
Original file line number Diff line number Diff line change @@ -15,9 +15,11 @@ public static async Task<ConventionResult> MustConformTo(this Type type, IAsyncC
15
15
16
16
public static async Task < WrappedConventionResult > MustConformTo ( this IEnumerable < Type > types , IAsyncConventionSpecification conventionSpecification )
17
17
{
18
+ var filteredTypes = types . Where ( ConventionConfiguration . GlobalTypeFilter ) . ToArray ( ) ;
19
+
18
20
return Conformist . EnforceConformance ( new WrappedConventionResult (
19
- types ,
20
- await Task . WhenAll ( types . Select ( conventionSpecification . IsSatisfiedBy ) ) ) ) ;
21
+ filteredTypes ,
22
+ await Task . WhenAll ( filteredTypes . Select ( conventionSpecification . IsSatisfiedBy ) ) ) ) ;
21
23
}
22
24
23
25
public static async Task < WrappedConventionResult > AndMustConformTo ( this Task < WrappedConventionResult > results , IAsyncConventionSpecification conventionSpecification )
Original file line number Diff line number Diff line change @@ -15,9 +15,11 @@ public static ConventionResult MustConformTo(this Type type, IConventionSpecific
15
15
16
16
public static WrappedConventionResult MustConformTo ( this IEnumerable < Type > types , IConventionSpecification conventionSpecification )
17
17
{
18
+ var filteredTypes = types . Where ( ConventionConfiguration . GlobalTypeFilter ) . ToArray ( ) ;
19
+
18
20
return EnforceConformance ( new WrappedConventionResult (
19
- types ,
20
- types . Select ( conventionSpecification . IsSatisfiedBy ) ) ) ;
21
+ filteredTypes ,
22
+ filteredTypes . Select ( conventionSpecification . IsSatisfiedBy ) ) ) ;
21
23
}
22
24
23
25
public static ConventionResult MustConformTo ( this Assembly assembly , IAssemblyConventionSpecification assemblyConventionSpecification )
Original file line number Diff line number Diff line change @@ -7,5 +7,11 @@ public static class ConventionConfiguration
7
7
public static Action < string > DefaultFailureAssertionCallback { get ; set ; }
8
8
public static Action < string > DefaultWarningAssertionCallback { get ; set ; }
9
9
public static Func < DateTime > DefaultCurrentDateResolver { get ; set ; } = ( ) => DateTime . UtcNow ;
10
+ private static readonly Func < Type , bool > DefaultGlobalTypeFilter = t => true ;
11
+ public static Func < Type , bool > GlobalTypeFilter { get ; set ; } = DefaultGlobalTypeFilter ;
12
+ public static void ResetGlobalTypeFilter ( )
13
+ {
14
+ GlobalTypeFilter = DefaultGlobalTypeFilter ;
15
+ }
10
16
}
11
17
}
0 commit comments