Skip to content

Commit 018c67f

Browse files
author
Jake Ginnivan
committed
More descripting convention names
1 parent 2ac3039 commit 018c67f

File tree

4 files changed

+54
-54
lines changed

4 files changed

+54
-54
lines changed

TestStack.ConventionTests.Tests/MvcConventions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void controller_conventions()
2525
public void api_controller_conventions()
2626
{
2727
var types = Types.InAssemblyOf<TestController>();
28-
var convention = new ApiControllerConvention();
28+
var convention = new ApiControllerNamingAndBaseClassConvention();
2929

3030
var ex = Assert.Throws<ConventionFailedException>(() => Convention.Is(convention, types));
3131
Approvals.Verify(ex.Message);

TestStack.ConventionTests/Conventions/ApiControllerConvention.cs renamed to TestStack.ConventionTests/Conventions/ApiControllerNamingAndBaseClassConvention.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Linq;
66
using TestStack.ConventionTests.ConventionData;
77

8-
public class ApiControllerConvention : MvcControllerConvention
8+
public class ApiControllerNamingAndBaseClassConvention : MvcControllerNameAndBaseClassConvention
99
{
1010
protected override IEnumerable<Type> GetControllers(Types data)
1111
{
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
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+
}
5151
}

TestStack.ConventionTests/TestStack.ConventionTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
<Compile Include="ConventionData\TypeExtensions.cs" />
6262
<Compile Include="ConventionFailedException.cs" />
6363
<Compile Include="IConventionResultContext.cs" />
64-
<Compile Include="Conventions\ApiControllerConvention.cs" />
65-
<Compile Include="Conventions\MvcControllerConvention.cs" />
64+
<Compile Include="Conventions\ApiControllerNamingAndBaseClassConvention.cs" />
65+
<Compile Include="Conventions\MvcControllerNameAndBaseClassConvention.cs" />
6666
<Compile Include="Internal\ConventionReportFailure.cs" />
6767
<Compile Include="Internal\ConventionContext.cs" />
6868
<Compile Include="Internal\ConventionResult.cs" />

0 commit comments

Comments
 (0)