public void Test_Not_Cacheable_No_Content() { var cachingHandler = new CachingHandler(); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.CacheControl = new CacheControlHeaderValue(){Public = true}; Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.NotCacheable); }
public void Test_NoCache_IsCacheable_And_NotStale_But_MustRevalidate() { var cachingHandler = new CachingHandler(); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.CacheControl = new CacheControlHeaderValue() { Public = true, NoCache = true}; response.Content = new ByteArrayContent(new byte[256]); response.Content.Headers.Expires = DateTimeOffset.Now.AddHours(1); // resource is not stale Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.MustRevalidate); }
public void Test_Stale_By_Expires() { var cachingHandler = new CachingHandler(); cachingHandler.MustRevalidateByDefault = false; var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.CacheControl = new CacheControlHeaderValue() { Public = true }; response.Content = new ByteArrayContent(new byte[256]); response.Content.Headers.Expires = DateTimeOffset.UtcNow.AddDays(-1); Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.Stale); }
public void Test_OK() { var cachingHandler = new CachingHandler(); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.CacheControl = new CacheControlHeaderValue() { Public = true, MaxAge = TimeSpan.FromSeconds(200), MustRevalidate = false }; response.Headers.Date = DateTimeOffset.UtcNow; response.Content = new ByteArrayContent(new byte[256]); Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.OK); }
public void Test_Not_Cacheable_StatusCode(HttpStatusCode code) { var cachingHandler = new CachingHandler(); var response = new HttpResponseMessage(code); Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.NotCacheable); }
public void Test_Stale_By_SharedAge() { var cachingHandler = new CachingHandler(); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.CacheControl = new CacheControlHeaderValue() { Public = true, SharedMaxAge = TimeSpan.FromSeconds(200) }; response.Headers.Date = DateTimeOffset.UtcNow.AddDays(-1); response.Content = new ByteArrayContent(new byte[256]); Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.Stale); }