1
- namespace TestStack . ConventionTests . Conventions
2
- {
3
- using System ;
4
- using System . Collections . Generic ;
5
- using System . Linq ;
6
- using TestStack . ConventionTests . ConventionData ;
7
-
8
- public class MvcControllerConvention : IConvention < Types >
9
- {
10
- public void Execute ( Types data , IConventionResultContext result )
11
- {
12
- var controllers = GetControllers ( data ) ;
13
- var typesWhichDoNotEndInController = controllers . Where ( c => ! c . Name . EndsWith ( "Controller" ) ) ;
14
-
15
- var typesWhichEndInController = data . TypesToVerify . Where ( t => t . Name . EndsWith ( "Controller" ) ) ;
16
- var controllersWhichDoNotInheritFromController =
17
- typesWhichEndInController . Where ( t => ! IsMvcController ( t ) && ! IsWebApiController ( t ) ) ;
18
-
19
- result . IsSymmetric (
20
- GetControllerTypeName ( ) + "s must be suffixed with Controller" , typesWhichDoNotEndInController ,
21
- "Types named *Controller must inherit from ApiController or Controller" ,
22
- controllersWhichDoNotInheritFromController ) ;
23
- }
24
-
25
- protected virtual string GetControllerTypeName ( )
26
- {
27
- return "Mvc Controller" ;
28
- }
29
-
30
- protected virtual IEnumerable < Type > GetControllers ( Types data )
31
- {
32
- return data . TypesToVerify . Where ( IsMvcController ) ;
33
- }
34
-
35
- static bool IsMvcController ( Type arg )
36
- {
37
- var isController = arg . FullName == "System.Web.Mvc.Controller" ;
38
- if ( arg . BaseType == null )
39
- return isController ;
40
- return isController || IsMvcController ( arg . BaseType ) ;
41
- }
42
-
43
- protected static bool IsWebApiController ( Type arg )
44
- {
45
- var isController = arg . FullName == "System.Web.Http.ApiController" ;
46
- if ( arg . BaseType == null )
47
- return isController ;
48
- return isController || IsWebApiController ( arg . BaseType ) ;
49
- }
50
- }
1
+ namespace TestStack . ConventionTests . Conventions
2
+ {
3
+ using System ;
4
+ using System . Collections . Generic ;
5
+ using System . Linq ;
6
+ using TestStack . ConventionTests . ConventionData ;
7
+
8
+ public class MvcControllerNameAndBaseClassConvention : IConvention < Types >
9
+ {
10
+ public void Execute ( Types data , IConventionResultContext result )
11
+ {
12
+ var controllers = GetControllers ( data ) ;
13
+ var typesWhichDoNotEndInController = controllers . Where ( c => ! c . Name . EndsWith ( "Controller" ) ) ;
14
+
15
+ var typesWhichEndInController = data . TypesToVerify . Where ( t => t . Name . EndsWith ( "Controller" ) ) ;
16
+ var controllersWhichDoNotInheritFromController =
17
+ typesWhichEndInController . Where ( t => ! IsMvcController ( t ) && ! IsWebApiController ( t ) ) ;
18
+
19
+ result . IsSymmetric (
20
+ GetControllerTypeName ( ) + "s must be suffixed with Controller" , typesWhichDoNotEndInController ,
21
+ "Types named *Controller must inherit from ApiController or Controller" ,
22
+ controllersWhichDoNotInheritFromController ) ;
23
+ }
24
+
25
+ protected virtual string GetControllerTypeName ( )
26
+ {
27
+ return "Mvc Controller" ;
28
+ }
29
+
30
+ protected virtual IEnumerable < Type > GetControllers ( Types data )
31
+ {
32
+ return data . TypesToVerify . Where ( IsMvcController ) ;
33
+ }
34
+
35
+ static bool IsMvcController ( Type arg )
36
+ {
37
+ var isController = arg . FullName == "System.Web.Mvc.Controller" ;
38
+ if ( arg . BaseType == null )
39
+ return isController ;
40
+ return isController || IsMvcController ( arg . BaseType ) ;
41
+ }
42
+
43
+ protected static bool IsWebApiController ( Type arg )
44
+ {
45
+ var isController = arg . FullName == "System.Web.Http.ApiController" ;
46
+ if ( arg . BaseType == null )
47
+ return isController ;
48
+ return isController || IsWebApiController ( arg . BaseType ) ;
49
+ }
50
+ }
51
51
}
0 commit comments