public void ShouldGiveCorrectContentType() { Filter = new OutputCacheActionFilter(60, 60); ClearCache(); Filter.OnActionExecuted(executedContext); Filter.OnActionExecuting(actionContext); var contentType = actionContext.Response.Content.Headers.ContentType; Assert.IsNotNull(actionContext.Response, "Response is null"); Assert.IsNotNull(contentType, "Content-type is null"); var reExecutingContext = GetActionContext(HttpMethod.Get, DefaultUri); Filter.OnActionExecuting(reExecutingContext); Assert.IsNotNull(reExecutingContext.Response, "Re-executing context response is null"); var cachedContentType = reExecutingContext.Response.Content.Headers.ContentType; Assert.IsNotNull(cachedContentType, "Cached content-type is null"); Assert.AreEqual(contentType, cachedContentType); }
public void OutputCacheShouldExpireAfterExpiryTime() { Filter = new OutputCacheActionFilter(1, 1); ClearCache(); Filter.OnActionExecuting(actionContext); Assert.IsNotNull(actionContext.Response, "Should be cached"); //now sleep to see cache expire System.Threading.Thread.Sleep(1005); var reExecutingContext = GetActionContext(HttpMethod.Get, DefaultUri); Filter.OnActionExecuting(reExecutingContext); Assert.IsNull(reExecutingContext.Response, "Should have expired"); }
public void OutputCacheShouldVaryByQueryString() { Filter = new OutputCacheActionFilter(1, 1); ClearCache(); var context = GetActionExecutedContext("http://anyurl/?yayayaya&nononno&paela=yes"); Filter.OnActionExecuted(context); Assert.IsNotNull(actionContext.Response, "Should be cached"); var reExecutingContext = GetActionContext(HttpMethod.Get, "http://anyurl/?yayayaya&nononno&paela=no"); Filter.OnActionExecuting(reExecutingContext); Assert.IsNull(reExecutingContext.Response, "Should not be cached"); ClearCache(); }