public void TestCachingByETag() { log.Debug("TestCachingByETag"); TimeSpan maxAge = TimeSpan.FromDays(30); cmd.CacheByETag( @"somedir\*", maxAge, () => new Tuple <string, DateTime?>("xyz", new DateTime(2016, 01, 19, 10, 22, 0))); routeMatch.AddParameter("path", @"somedir\somepath.png"); const string ExpectedFileName = @"d:\somedir\contents\somedir\somepath.png"; fileSystem.Stub(x => x.DoesFileExist(ExpectedFileName)).Return(true); IWebCommandResult result = cmd.Execute(context, routeMatch); FileResult fileResult = (FileResult)result; CachingByETagPolicy cachingPolicy = (CachingByETagPolicy)fileResult.CachingPolicy; Assert.AreEqual(maxAge, cachingPolicy.MaxAge); context.RequestHeaders.Add(HttpConsts.HeaderIfNoneMatch, "xyz"); result.Apply(context); Assert.AreEqual((int)HttpStatusCode.NotModified, context.StatusCode); }
public void IfNoneMatchHeaderIsMissingReturnResource() { policy = new CachingByETagPolicy(maxAge, () => new Tuple <string, DateTime?>(ETag, lastModifiedTime)); policy.ProcessRequest(null, WebContext, ReturnResource); Assert.AreEqual((int)HttpStatusCode.OK, WebContext.StatusCode); Assert.IsTrue(ResourceReturned); }
public void ETagAndIfNoneMatchHeaderAreMatching() { WebContext.RequestHeaders.Add(HttpConsts.HeaderIfNoneMatch, ETag); policy = new CachingByETagPolicy(maxAge, () => new Tuple <string, DateTime?>(ETag, lastModifiedTime)); policy.ProcessRequest(null, WebContext, ReturnResource); Assert.AreEqual((int)HttpStatusCode.NotModified, WebContext.StatusCode); Assert.IsFalse(ResourceReturned); }