@@ -851,38 +851,33 @@ private class FakeResponseFeature : HttpResponseFeature
851
851
public override void OnStarting ( Func < object , Task > callback , object state ) { }
852
852
}
853
853
854
- [ Fact ]
855
- public async Task Invoke_CacheableRequest_AddsResponseCachingFeature ( )
854
+ [ Theory ]
855
+ // If allowResponseCaching is false, other settings will not matter but are included for completeness
856
+ [ InlineData ( false , false , false ) ]
857
+ [ InlineData ( false , false , true ) ]
858
+ [ InlineData ( false , true , false ) ]
859
+ [ InlineData ( false , true , true ) ]
860
+ [ InlineData ( true , false , false ) ]
861
+ [ InlineData ( true , false , true ) ]
862
+ [ InlineData ( true , true , false ) ]
863
+ [ InlineData ( true , true , true ) ]
864
+ public async Task Invoke_AddsResponseCachingFeature_Always ( bool allowResponseCaching , bool allowCacheLookup , bool allowCacheStorage )
856
865
{
857
866
var responseCachingFeatureAdded = false ;
858
867
var middleware = TestUtils . CreateTestMiddleware ( next : httpContext =>
859
868
{
860
869
responseCachingFeatureAdded = httpContext . Features . Get < IResponseCachingFeature > ( ) != null ;
861
870
return TaskCache . CompletedTask ;
862
871
} ,
863
- policyProvider : new ResponseCachingPolicyProvider ( ) ) ;
864
-
865
- var context = new DefaultHttpContext ( ) ;
866
- context . Request . Method = HttpMethods . Get ;
867
- context . Features . Set < IHttpResponseFeature > ( new FakeResponseFeature ( ) ) ;
868
- await middleware . Invoke ( context ) ;
869
-
870
- Assert . True ( responseCachingFeatureAdded ) ;
871
- }
872
-
873
- [ Fact ]
874
- public async Task Invoke_NonCacheableRequest_AddsResponseCachingFeature ( )
875
- {
876
- var responseCachingFeatureAdded = false ;
877
- var middleware = TestUtils . CreateTestMiddleware ( next : httpContext =>
872
+ policyProvider : new TestResponseCachingPolicyProvider
878
873
{
879
- responseCachingFeatureAdded = httpContext . Features . Get < IResponseCachingFeature > ( ) != null ;
880
- return TaskCache . CompletedTask ;
881
- } ,
882
- policyProvider : new ResponseCachingPolicyProvider ( ) ) ;
874
+ AllowResponseCachingValue = allowResponseCaching ,
875
+ AllowCacheLookupValue = allowCacheLookup ,
876
+ AllowCacheStorageValue = allowCacheStorage
877
+ } ) ;
883
878
884
879
var context = new DefaultHttpContext ( ) ;
885
- context . Request . Method = HttpMethods . Post ;
880
+ context . Features . Set < IHttpResponseFeature > ( new FakeResponseFeature ( ) ) ;
886
881
await middleware . Invoke ( context ) ;
887
882
888
883
Assert . True ( responseCachingFeatureAdded ) ;
0 commit comments