public void Execute_DoesNotSetLocationOrDuration_IfNoStoreIsSet(CacheProfile cacheProfile, string output) { // Arrange var executor = new ResponseCacheFilterExecutor(cacheProfile); var context = GetActionExecutingContext(); // Act executor.Execute(context); // Assert Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]); }
public void Execute_CanSetCacheControlHeaders(CacheProfile cacheProfile, string output) { // Arrange var executor = new ResponseCacheFilterExecutor(cacheProfile); var context = GetActionExecutingContext(); // Act executor.Execute(context); // Assert Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]); }
public void ResponseCacheCanSetVaryByHeader(CacheProfile cacheProfile, string varyOutput, string cacheControlOutput) { // Arrange var executor = new ResponseCacheFilterExecutor(cacheProfile); var context = GetActionExecutingContext(); // Act executor.Execute(context); // Assert Assert.Equal(varyOutput, context.HttpContext.Response.Headers["Vary"]); Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers["Cache-control"]); }
public void ResponseCacheCanSetVaryByQueryKeys(CacheProfile cacheProfile, string[] varyOutput, string cacheControlOutput) { // Arrange var executor = new ResponseCacheFilterExecutor(cacheProfile); var context = GetActionExecutingContext(); context.HttpContext.Features.Set <IResponseCachingFeature>(new ResponseCachingFeature()); // Acts executor.Execute(context); // Assert Assert.Equal(varyOutput, context.HttpContext.Features.Get <IResponseCachingFeature>().VaryByQueryKeys); Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers[HeaderNames.CacheControl]); }
public void Execute_ThrowsIfDurationIsNotSet_WhenNoStoreIsFalse() { // Arrange var executor = new ResponseCacheFilterExecutor( new CacheProfile() { Duration = null }); var context = GetActionExecutingContext(); // Act & Assert var ex = Assert.Throws <InvalidOperationException>(() => executor.Execute(context)); Assert.Equal("If the 'NoStore' property is not set to true, 'Duration' property must be specified.", ex.Message); }
public void Execute_DoesNotThrow_WhenNoStoreIsTrue() { // Arrange var executor = new ResponseCacheFilterExecutor( new CacheProfile { NoStore = true, Duration = null }); var context = GetActionExecutingContext(); // Act executor.Execute(context); // Assert Assert.Equal("no-store", context.HttpContext.Response.Headers["Cache-control"]); }
public void FilterDurationProperty_OverridesCachePolicySetting() { // Arrange var executor = new ResponseCacheFilterExecutor( new CacheProfile { Duration = 10 }); executor.Duration = 20; var context = GetActionExecutingContext(); // Act executor.Execute(context); // Assert Assert.Equal("public,max-age=20", context.HttpContext.Response.Headers["Cache-control"]); }
public void FilterVaryByProperty_OverridesCachePolicySetting() { // Arrange var executor = new ResponseCacheFilterExecutor( new CacheProfile { NoStore = true, VaryByHeader = "Accept" }); executor.VaryByHeader = "Test"; var context = GetActionExecutingContext(); // Act executor.Execute(context); // Assert Assert.Equal("Test", context.HttpContext.Response.Headers["Vary"]); }
public void FilterLocationProperty_OverridesCachePolicySetting() { // Arrange var executor = new ResponseCacheFilterExecutor( new CacheProfile { Duration = 10, Location = ResponseCacheLocation.None }); executor.Location = ResponseCacheLocation.Client; var context = GetActionExecutingContext(); // Act executor.Execute(context); // Assert Assert.Equal("private,max-age=10", context.HttpContext.Response.Headers["Cache-control"]); }
public void NonEmptyVaryByQueryKeys_WithoutConfiguringMiddleware_Throws() { // Arrange var executor = new ResponseCacheFilterExecutor( new CacheProfile { Duration = 0, Location = ResponseCacheLocation.None, NoStore = true, VaryByHeader = null, VaryByQueryKeys = new[] { "Test" } }); var context = GetActionExecutingContext(); // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => executor.Execute(context)); Assert.Equal("'VaryByQueryKeys' requires the response cache middleware.", exception.Message); }
public void SetsPragmaOnNoCache() { // Arrange var executor = new ResponseCacheFilterExecutor( new CacheProfile { Duration = 0, Location = ResponseCacheLocation.None, NoStore = true, VaryByHeader = null }); var context = GetActionExecutingContext(); // Act executor.Execute(context); // Assert Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers["Cache-control"]); Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]); }