File tree Expand file tree Collapse file tree 4 files changed +56
-7
lines changed
JsonApiDotNetCoreExample/Controllers
test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility Expand file tree Collapse file tree 4 files changed +56
-7
lines changed Original file line number Diff line number Diff line change 22
33namespace JsonApiDotNetCore . Controllers
44{
5- public class JsonApiControllerMixin : Controller
5+ public abstract class JsonApiControllerMixin : Controller
66 {
7- public JsonApiControllerMixin ( )
7+ protected JsonApiControllerMixin ( )
88 { }
99
1010 protected IActionResult UnprocessableEntity ( )
Original file line number Diff line number Diff line change @@ -29,12 +29,9 @@ public void Apply(ApplicationModel application)
2929 }
3030 }
3131
32- private bool IsJsonApiController ( ControllerModel controller )
32+ private bool IsJsonApiController ( ControllerModel controller )
3333 {
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 < > ) ) ;
34+ return controller . ControllerType . IsSubclassOf ( typeof ( JsonApiControllerMixin ) ) ;
3835 }
3936 }
4037}
Original file line number Diff line number Diff line change 1+ using JsonApiDotNetCore . Controllers ;
2+ using JsonApiDotNetCore . Data ;
3+ using JsonApiDotNetCore . Models ;
4+ using JsonApiDotNetCore . Services ;
5+ using JsonApiDotNetCoreExample . Models ;
6+ using Microsoft . Extensions . Logging ;
7+
8+ namespace JsonApiDotNetCoreExample . Controllers
9+ {
10+ public abstract class AbstractTodoItemsController < T > : JsonApiController < T > where T : class , IIdentifiable < int >
11+ {
12+ protected AbstractTodoItemsController (
13+ IJsonApiContext jsonApiContext ,
14+ IEntityRepository < T , int > entityRepository ,
15+ ILoggerFactory loggerFactory )
16+ : base ( jsonApiContext , entityRepository , loggerFactory )
17+ {
18+ }
19+ }
20+ public class TodoItemsTestController : AbstractTodoItemsController < TodoItem >
21+ {
22+ public TodoItemsTestController (
23+ IJsonApiContext jsonApiContext ,
24+ IEntityRepository < TodoItem > entityRepository ,
25+ ILoggerFactory loggerFactory )
26+ : base ( jsonApiContext , entityRepository , loggerFactory )
27+ { }
28+ }
29+ }
Original file line number Diff line number Diff line change 11using System . Net ;
22using System . Net . Http ;
33using System . Threading . Tasks ;
4+ using DotNetCoreDocs . Models ;
5+ using JsonApiDotNetCore . Serialization ;
46using Microsoft . AspNetCore . Hosting ;
57using Microsoft . AspNetCore . TestHost ;
68using Xunit ;
79using JsonApiDotNetCoreExample ;
10+ using JsonApiDotNetCoreExample . Models ;
811
912namespace JsonApiDotNetCoreExampleTests . Acceptance . Extensibility
1013{
@@ -30,5 +33,25 @@ public async Task NonJsonApiControllers_DoNotUse_Dasherized_Routes()
3033 // assert
3134 Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
3235 }
36+
37+ [ Fact ]
38+ public async Task InheritedJsonApiControllers_Uses_Dasherized_Routes ( )
39+ {
40+ // Arrange
41+ var builder = new WebHostBuilder ( )
42+ . UseStartup < Startup > ( ) ;
43+ var httpMethod = new HttpMethod ( "GET" ) ;
44+ var route = "/api/v1/todo-items-test" ;
45+
46+ var server = new TestServer ( builder ) ;
47+ var client = server . CreateClient ( ) ;
48+ var request = new HttpRequestMessage ( httpMethod , route ) ;
49+
50+ // act
51+ var response = await client . SendAsync ( request ) ;
52+
53+ // assert
54+ Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
55+ }
3356 }
3457}
You can’t perform that action at this time.
0 commit comments