File tree 4 files changed +56
-7
lines changed
JsonApiDotNetCoreExample/Controllers
test/JsonApiDotNetCoreExampleTests/Acceptance/Extensibility
4 files changed +56
-7
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace JsonApiDotNetCore . Controllers
4
4
{
5
- public class JsonApiControllerMixin : Controller
5
+ public abstract class JsonApiControllerMixin : Controller
6
6
{
7
- public JsonApiControllerMixin ( )
7
+ protected JsonApiControllerMixin ( )
8
8
{ }
9
9
10
10
protected IActionResult UnprocessableEntity ( )
Original file line number Diff line number Diff line change @@ -29,12 +29,9 @@ public void Apply(ApplicationModel application)
29
29
}
30
30
}
31
31
32
- private bool IsJsonApiController ( ControllerModel controller )
32
+ private bool IsJsonApiController ( ControllerModel controller )
33
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 < > ) ) ;
34
+ return controller . ControllerType . IsSubclassOf ( typeof ( JsonApiControllerMixin ) ) ;
38
35
}
39
36
}
40
37
}
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 1
1
using System . Net ;
2
2
using System . Net . Http ;
3
3
using System . Threading . Tasks ;
4
+ using DotNetCoreDocs . Models ;
5
+ using JsonApiDotNetCore . Serialization ;
4
6
using Microsoft . AspNetCore . Hosting ;
5
7
using Microsoft . AspNetCore . TestHost ;
6
8
using Xunit ;
7
9
using JsonApiDotNetCoreExample ;
10
+ using JsonApiDotNetCoreExample . Models ;
8
11
9
12
namespace JsonApiDotNetCoreExampleTests . Acceptance . Extensibility
10
13
{
@@ -30,5 +33,25 @@ public async Task NonJsonApiControllers_DoNotUse_Dasherized_Routes()
30
33
// assert
31
34
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
32
35
}
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
+ }
33
56
}
34
57
}
You can’t perform that action at this time.
0 commit comments