@@ -28,7 +28,7 @@ public async Task NoEndpoint_AnonymousUser_Allows()
2828 policyProvider . Setup ( p => p . GetDefaultPolicyAsync ( ) ) . ReturnsAsync ( policy ) ;
2929 var next = new TestRequestDelegate ( ) ;
3030
31- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
31+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
3232 var context = GetHttpContext ( anonymous : true ) ;
3333
3434 // Act
@@ -47,7 +47,7 @@ public async Task HasEndpointWithoutAuth_AnonymousUser_Allows()
4747 policyProvider . Setup ( p => p . GetDefaultPolicyAsync ( ) ) . ReturnsAsync ( policy ) ;
4848 var next = new TestRequestDelegate ( ) ;
4949
50- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
50+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
5151 var context = GetHttpContext ( anonymous : true , endpoint : CreateEndpoint ( ) ) ;
5252
5353 // Act
@@ -67,7 +67,7 @@ public async Task HasEndpointWithAuth_AnonymousUser_Challenges()
6767 var next = new TestRequestDelegate ( ) ;
6868 var authenticationService = new TestAuthenticationService ( ) ;
6969
70- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
70+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
7171 var context = GetHttpContext ( anonymous : true , endpoint : CreateEndpoint ( new AuthorizeAttribute ( ) ) , authenticationService : authenticationService ) ;
7272
7373 // Act
@@ -88,7 +88,7 @@ public async Task OnAuthorizationAsync_WillCallPolicyProvider()
8888 policyProvider . Setup ( p => p . GetPolicyAsync ( It . IsAny < string > ( ) ) ) . ReturnsAsync ( policy )
8989 . Callback ( ( ) => getPolicyCount ++ ) ;
9090 var next = new TestRequestDelegate ( ) ;
91- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
91+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
9292 var context = GetHttpContext ( anonymous : true , endpoint : CreateEndpoint ( new AuthorizeAttribute ( "whatever" ) ) ) ;
9393
9494 // Act & Assert
@@ -114,7 +114,7 @@ public async Task Invoke_ValidClaimShouldNotFail()
114114 policyProvider . Setup ( p => p . GetDefaultPolicyAsync ( ) ) . ReturnsAsync ( policy ) ;
115115 var next = new TestRequestDelegate ( ) ;
116116
117- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
117+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
118118 var context = GetHttpContext ( endpoint : CreateEndpoint ( new AuthorizeAttribute ( ) ) ) ;
119119
120120 // Act
@@ -134,7 +134,7 @@ public async Task HasEndpointWithAuthAndAllowAnonymous_AnonymousUser_Allows()
134134 var next = new TestRequestDelegate ( ) ;
135135 var authenticationService = new TestAuthenticationService ( ) ;
136136
137- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
137+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
138138 var context = GetHttpContext ( anonymous : true , endpoint : CreateEndpoint ( new AuthorizeAttribute ( ) , new AllowAnonymousAttribute ( ) ) , authenticationService : authenticationService ) ;
139139
140140 // Act
@@ -155,7 +155,7 @@ public async Task HasEndpointWithAuth_AuthenticatedUser_Allows()
155155 var next = new TestRequestDelegate ( ) ;
156156 var authenticationService = new TestAuthenticationService ( ) ;
157157
158- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
158+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
159159 var context = GetHttpContext ( endpoint : CreateEndpoint ( new AuthorizeAttribute ( ) ) , authenticationService : authenticationService ) ;
160160
161161 // Act
@@ -176,7 +176,7 @@ public async Task Invoke_AuthSchemesFailShouldSetEmptyPrincipalOnContext()
176176 var next = new TestRequestDelegate ( ) ;
177177 var authenticationService = new TestAuthenticationService ( ) ;
178178
179- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
179+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
180180 var context = GetHttpContext ( endpoint : CreateEndpoint ( new AuthorizeAttribute ( ) ) , authenticationService : authenticationService ) ;
181181
182182 // Act
@@ -198,7 +198,7 @@ public async Task Invoke_SingleValidClaimShouldSucceed()
198198 policyProvider . Setup ( p => p . GetDefaultPolicyAsync ( ) ) . ReturnsAsync ( policy ) ;
199199 var next = new TestRequestDelegate ( ) ;
200200
201- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
201+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
202202 var context = GetHttpContext ( endpoint : CreateEndpoint ( new AuthorizeAttribute ( ) ) ) ;
203203
204204 // Act
@@ -222,7 +222,7 @@ public async Task AuthZResourceShouldBeEndpoint()
222222 policyProvider . Setup ( p => p . GetDefaultPolicyAsync ( ) ) . ReturnsAsync ( policy ) ;
223223 var next = new TestRequestDelegate ( ) ;
224224
225- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
225+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
226226 var endpoint = CreateEndpoint ( new AuthorizeAttribute ( ) ) ;
227227 var context = GetHttpContext ( endpoint : endpoint ) ;
228228
@@ -243,7 +243,7 @@ public async Task Invoke_RequireUnknownRoleShouldForbid()
243243 var next = new TestRequestDelegate ( ) ;
244244 var authenticationService = new TestAuthenticationService ( ) ;
245245
246- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
246+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
247247 var context = GetHttpContext ( endpoint : CreateEndpoint ( new AuthorizeAttribute ( ) ) , authenticationService : authenticationService ) ;
248248
249249 // Act
@@ -267,7 +267,7 @@ public async Task Invoke_InvalidClaimShouldForbid()
267267 var next = new TestRequestDelegate ( ) ;
268268 var authenticationService = new TestAuthenticationService ( ) ;
269269
270- var middleware = CreateMiddleware ( next . RequestDelegate , policyProvider . Object ) ;
270+ var middleware = CreateMiddleware ( next . Invoke , policyProvider . Object ) ;
271271 var context = GetHttpContext ( endpoint : CreateEndpoint ( new AuthorizeAttribute ( ) ) , authenticationService : authenticationService ) ;
272272
273273 // Act
@@ -396,16 +396,16 @@ private class TestRequestDelegate
396396 public bool Called => CalledCount > 0 ;
397397 public int CalledCount { get ; private set ; }
398398
399- public Task RequestDelegate ( HttpContext context )
399+ public TestRequestDelegate ( int statusCode = 200 )
400400 {
401- CalledCount ++ ;
402- context . Response . StatusCode = _statusCode ;
403- return Task . CompletedTask ;
401+ _statusCode = statusCode ;
404402 }
405403
406- public TestRequestDelegate ( int statusCode = 200 )
404+ public Task Invoke ( HttpContext context )
407405 {
408- _statusCode = statusCode ;
406+ CalledCount ++ ;
407+ context . Response . StatusCode = _statusCode ;
408+ return Task . CompletedTask ;
409409 }
410410 }
411411 }
0 commit comments