Skip to content

Commit c5d702d

Browse files
author
Jake Ginnivan
committed
Added MvcConventions test
1 parent 9ca09f0 commit c5d702d

9 files changed

+96
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace TestAssembly.Controllers
2+
{
3+
using System.Web.Http;
4+
5+
public class BarApiControler : ApiController
6+
{
7+
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace TestAssembly.Controllers
2+
{
3+
using System.Web.Mvc;
4+
5+
public class FooControler : Controller
6+
{
7+
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace TestAssembly.Controllers
2+
{
3+
using System.Web.Http;
4+
5+
public class MyApiController : ApiController
6+
{
7+
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace TestAssembly.Controllers
2+
{
3+
public class TestController
4+
{
5+
6+
}
7+
}

TestAssembly/TestAssembly.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
<Compile Include="Collections\ICanRemove.cs" />
7474
<Compile Include="Collections\Leaf.cs" />
7575
<Compile Include="Collections\Tree.cs" />
76+
<Compile Include="Controllers\BarApiControler.cs" />
77+
<Compile Include="Controllers\FooControler.cs" />
78+
<Compile Include="Controllers\MyApiController.cs" />
79+
<Compile Include="Controllers\TestApiController.cs" />
80+
<Compile Include="Controllers\TestController.cs" />
7681
<Compile Include="Dtos\AnotherClass.cs" />
7782
<Compile Include="Dtos\BlahDto.cs" />
7883
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Failed: 'WebApi controllers must be suffixed with Controller' for 'TestAssembly'
2+
--------------------------------------------------------------------------------
3+
4+
TestAssembly.Controllers.BarApiControler
5+
6+
7+
Failed: 'Types named *Controller must inherit from ApiController or Controller' for 'TestAssembly'
8+
--------------------------------------------------------------------------------------------------
9+
10+
TestAssembly.Controllers.TestApiController
11+
TestAssembly.Controllers.TestController
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Failed: 'Mvc controllers must be suffixed with Controller' for 'TestAssembly'
2+
-----------------------------------------------------------------------------
3+
4+
TestAssembly.Controllers.FooControler
5+
6+
7+
Failed: 'Types named *Controller must inherit from ApiController or Controller' for 'TestAssembly'
8+
--------------------------------------------------------------------------------------------------
9+
10+
TestAssembly.Controllers.TestApiController
11+
TestAssembly.Controllers.TestController
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace TestStack.ConventionTests.Tests
2+
{
3+
using ApprovalTests;
4+
using ApprovalTests.Reporters;
5+
using NUnit.Framework;
6+
using TestAssembly.Controllers;
7+
using TestStack.ConventionTests.ConventionData;
8+
using TestStack.ConventionTests.Conventions;
9+
10+
[TestFixture]
11+
[UseReporter(typeof(DiffReporter))]
12+
public class MvcConventions
13+
{
14+
[Test]
15+
public void controller_conventions()
16+
{
17+
var types = Types.InAssemblyOf<TestController>();
18+
var convention = new MvcControllerConvention();
19+
20+
var ex = Assert.Throws<ConventionFailedException>(() => Convention.Is(convention, types));
21+
Approvals.Verify(ex.Message);
22+
}
23+
24+
[Test]
25+
public void api_controller_conventions()
26+
{
27+
var types = Types.InAssemblyOf<TestController>();
28+
var convention = new ApiControllerConvention();
29+
30+
var ex = Assert.Throws<ConventionFailedException>(() => Convention.Is(convention, types));
31+
Approvals.Verify(ex.Message);
32+
}
33+
}
34+
}

TestStack.ConventionTests.Tests/TestStack.ConventionTests.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<ItemGroup>
5454
<Compile Include="ConventionAssertionClassTests.cs" />
5555
<Compile Include="CsvReportTests.cs" />
56+
<Compile Include="MvcConventions.cs" />
5657
<Compile Include="ProjectBasedConventions.cs" />
5758
<Compile Include="Properties\AssemblyInfo.cs" />
5859
<Compile Include="Properties\Resources.Designer.cs">

0 commit comments

Comments
 (0)