File tree 3 files changed +61
-1
lines changed
tests/Kros.AspNetCore.Tests
3 files changed +61
-1
lines changed Original file line number Diff line number Diff line change
1
+ using Microsoft . AspNetCore . Authorization ;
2
+ using Microsoft . AspNetCore . Mvc ;
3
+
4
+ namespace Kros . AspNetCore
5
+ {
6
+ /// <summary>
7
+ /// A base class for all api controllers.
8
+ /// </summary>
9
+ [ Route ( "api/[controller]" ) ]
10
+ [ ApiController ]
11
+ [ Authorize ]
12
+ public abstract class ApiBaseController : ControllerBase
13
+ {
14
+ }
15
+ }
Original file line number Diff line number Diff line change 2
2
3
3
<PropertyGroup >
4
4
<TargetFramework >netstandard2.0</TargetFramework >
5
- <Version >1.1.5 </Version >
5
+ <Version >1.1.6 </Version >
6
6
<Authors >KROS a.s.</Authors >
7
7
<Description >General utilities and helpers for building ASP.NET Core WEB API</Description >
8
8
<PackageProjectUrl >https://github.com/Kros-sk/Kros.AspNetCore/tree/master/src/Kros.AspNetCore</PackageProjectUrl >
Original file line number Diff line number Diff line change
1
+ using FluentAssertions ;
2
+ using Microsoft . AspNetCore . Authorization ;
3
+ using Microsoft . AspNetCore . Mvc ;
4
+ using System ;
5
+ using System . Linq ;
6
+ using Xunit ;
7
+
8
+ namespace Kros . AspNetCore . Tests
9
+ {
10
+ public class ApiBaseControllerShould
11
+ {
12
+ #region Test classes
13
+
14
+ public class TestApiBaseController : ApiBaseController
15
+ { }
16
+
17
+ #endregion
18
+
19
+ [ Fact ]
20
+ public void BeAuthorized ( )
21
+ {
22
+ GetControllerAttribute < AuthorizeAttribute > ( new TestApiBaseController ( ) ) . Should ( ) . NotBeNull ( ) ;
23
+ }
24
+
25
+ [ Fact ]
26
+ public void BeApiController ( )
27
+ {
28
+ GetControllerAttribute < ApiControllerAttribute > ( new TestApiBaseController ( ) ) . Should ( ) . NotBeNull ( ) ;
29
+ }
30
+
31
+ [ Fact ]
32
+ public void HasRouteAttribute ( )
33
+ {
34
+ GetControllerAttribute < RouteAttribute > ( new TestApiBaseController ( ) ) . Should ( ) . NotBeNull ( ) ;
35
+ }
36
+
37
+ private static T GetControllerAttribute < T > ( ApiBaseController controller ) where T : Attribute
38
+ {
39
+ Type type = controller . GetType ( ) ;
40
+ object [ ] attributes = type . BaseType . GetCustomAttributes ( typeof ( T ) , true ) ;
41
+ T attribute = attributes . Count ( ) == 0 ? null : ( T ) attributes [ 0 ] ;
42
+ return attribute ;
43
+ }
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments