File tree Expand file tree Collapse file tree
XtremeIdiots.Portal.Web.Tests/ApiControllers
XtremeIdiots.Portal.Web/ApiControllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using Microsoft . AspNetCore . Authorization ;
2+ using XtremeIdiots . Portal . Web . ApiControllers ;
3+
4+ namespace XtremeIdiots . Portal . Web . Tests . ApiControllers ;
5+
6+ public class BannersControllerTests
7+ {
8+ [ Fact ]
9+ public void BannersController_HasClassLevelAuthorizeAttribute ( )
10+ {
11+ var authorizeAttribute = typeof ( BannersController ) . GetCustomAttributes ( typeof ( AuthorizeAttribute ) , true ) . SingleOrDefault ( ) ;
12+
13+ Assert . NotNull ( authorizeAttribute ) ;
14+ }
15+
16+ [ Fact ]
17+ public void GetGameServers_HasAllowAnonymousAttribute_OnlyAnonymousActionInController ( )
18+ {
19+ var methods = typeof ( BannersController ) . GetMethods ( ) ;
20+ var allowAnonymousMethods = methods
21+ . Where ( method => method . GetCustomAttributes ( typeof ( AllowAnonymousAttribute ) , true ) . Length > 0 )
22+ . ToList ( ) ;
23+
24+ Assert . Single ( allowAnonymousMethods ) ;
25+ Assert . Equal ( nameof ( BannersController . GetGameServers ) , allowAnonymousMethods [ 0 ] . Name ) ;
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ public class BannersController(
4848 /// <param name="cancellationToken">Cancellation token for the request</param>
4949 /// <returns>List of HTML banner content</returns>
5050 [ HttpGet ( "GetGameServers" ) ]
51+ [ AllowAnonymous ]
5152 [ EnableCors ( "CorsPolicy" ) ]
5253 public async Task < IActionResult > GetGameServers ( CancellationToken cancellationToken = default )
5354 {
You can’t perform that action at this time.
0 commit comments