File tree 4 files changed +68
-7
lines changed
JsonApiDotNetCoreExample/Controllers
test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility
4 files changed +68
-7
lines changed Original file line number Diff line number Diff line change 1
1
// REF: https://github.com/aspnet/Entropy/blob/dev/samples/Mvc.CustomRoutingConvention/NameSpaceRoutingConvention.cs
2
2
// REF: https://github.com/aspnet/Mvc/issues/5691
3
+ using JsonApiDotNetCore . Controllers ;
3
4
using JsonApiDotNetCore . Extensions ;
4
5
using Microsoft . AspNetCore . Mvc . ApplicationModels ;
5
6
@@ -12,17 +13,28 @@ public DasherizedRoutingConvention(string nspace)
12
13
{
13
14
_namespace = nspace ;
14
15
}
15
-
16
+
16
17
public void Apply ( ApplicationModel application )
17
18
{
18
19
foreach ( var controller in application . Controllers )
19
- {
20
- var template = $ "{ _namespace } /{ controller . ControllerName . Dasherize ( ) } ";
21
- controller . Selectors [ 0 ] . AttributeRouteModel = new AttributeRouteModel ( )
20
+ {
21
+ if ( IsJsonApiController ( controller ) )
22
22
{
23
- Template = template
24
- } ;
23
+ var template = $ "{ _namespace } /{ controller . ControllerName . Dasherize ( ) } ";
24
+ controller . Selectors [ 0 ] . AttributeRouteModel = new AttributeRouteModel ( )
25
+ {
26
+ Template = template
27
+ } ;
28
+ }
25
29
}
26
30
}
31
+
32
+ private bool IsJsonApiController ( ControllerModel controller )
33
+ {
34
+ var controllerBaseType = controller . ControllerType . BaseType ;
35
+ if ( ! controllerBaseType . IsConstructedGenericType ) return false ;
36
+ var genericTypeDefinition = controllerBaseType . GetGenericTypeDefinition ( ) ;
37
+ return ( genericTypeDefinition == typeof ( JsonApiController < , > ) || genericTypeDefinition == typeof ( JsonApiController < > ) ) ;
38
+ }
27
39
}
28
40
}
Original file line number Diff line number Diff line change 1
1
<Project Sdk =" Microsoft.NET.Sdk" >
2
2
<PropertyGroup >
3
- <VersionPrefix >1.3.0 </VersionPrefix >
3
+ <VersionPrefix >1.3.1 </VersionPrefix >
4
4
<TargetFramework >netcoreapp1.0</TargetFramework >
5
5
<AssemblyName >JsonApiDotNetCore</AssemblyName >
6
6
<PackageId >JsonApiDotNetCore</PackageId >
Original file line number Diff line number Diff line change
1
+ using Microsoft . AspNetCore . Mvc ;
2
+
3
+ namespace JsonApiDotNetCoreExample . Controllers
4
+ {
5
+ [ Route ( "[controller]" ) ]
6
+ public class TestValuesController : Controller
7
+ {
8
+ [ HttpGet ]
9
+ public IActionResult Get ( )
10
+ {
11
+ var result = new string [ ] { "value" } ;
12
+ return Ok ( result ) ;
13
+ }
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ using System . Net ;
2
+ using System . Net . Http ;
3
+ using System . Threading . Tasks ;
4
+ using Microsoft . AspNetCore . Hosting ;
5
+ using Microsoft . AspNetCore . TestHost ;
6
+ using Xunit ;
7
+ using JsonApiDotNetCoreExample ;
8
+
9
+ namespace JsonApiDotNetCoreExampleTests . Acceptance . Extensibility
10
+ {
11
+ [ Collection ( "WebHostCollection" ) ]
12
+ public class CustomControllerTests
13
+ {
14
+ [ Fact ]
15
+ public async Task NonJsonApiControllers_DoNotUse_Dasherized_Routes ( )
16
+ {
17
+ // arrange
18
+ var builder = new WebHostBuilder ( )
19
+ . UseStartup < Startup > ( ) ;
20
+ var httpMethod = new HttpMethod ( "GET" ) ;
21
+ var route = $ "testValues";
22
+
23
+ var server = new TestServer ( builder ) ;
24
+ var client = server . CreateClient ( ) ;
25
+ var request = new HttpRequestMessage ( httpMethod , route ) ;
26
+
27
+ // act
28
+ var response = await client . SendAsync ( request ) ;
29
+
30
+ // assert
31
+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
32
+ }
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments