public void ToOptimizedResult_throws_304_when_not_ModifiedSince()
        {
            var client = GetClient();

            DateTime?lastModified = null;

            client.ResponseFilter = res =>
                                    lastModified = DateTime.Parse(res.Headers[HttpHeaders.LastModified]);

            var request = new CachedRequest {
                Age = TimeSpan.FromHours(1)
            };
            var response = client.Get(request);

            Assert.That(response, Is.EqualTo(request));

            try
            {
                client.RequestFilter = req =>
                                       req.IfModifiedSince = lastModified.Value;

                response = client.Get(request);
                Assert.Fail("Should throw 304 NotModified");
            }
            catch (Exception ex)
            {
                if (!ex.IsNotModified())
                {
                    throw;
                }
            }
        }
Example #2
0
        public object Any(CachedRequest request)
        {
#if NETCORE
            var cacheKey = String.Join("&", Request.QueryString.Cast <string>().Select(key => key + "=" + Request.QueryString[key]));
#else
            var cacheKey = Request.QueryString.ToString();
#endif

            return(Request.ToOptimizedResultUsingCache(Cache, cacheKey, () => request));
        }
Example #3
0
        public void CachedServiceClient_does_return_cached_ToOptimizedResults()
        {
            var client = GetCachedServiceClient();

            var request = new CachedRequest {
                Age = TimeSpan.FromHours(1)
            };
            var response = client.Get(request);

            Assert.That(client.NotModifiedHits, Is.EqualTo(0));
            Assert.That(response, Is.EqualTo(request));

            response = client.Get(request);
            Assert.That(client.NotModifiedHits, Is.EqualTo(1));
            Assert.That(response, Is.EqualTo(request));
        }
        public void ToOptimizedResult_does_populate_LastModified()
        {
            var client = GetClient();

            client.ResponseFilter = res =>
                                    Assert.That(DateTime.Parse(res.Headers[HttpHeaders.LastModified]).ToUniversalTime(),
                                                Is.EqualTo(DateTime.UtcNow).Within(TimeSpan.FromMinutes(1)));

            var request = new CachedRequest {
                ETag = "etag"
            };
            var response = client.Get(request);

            Assert.That(response, Is.EqualTo(request));

            response = client.Get(request);
            Assert.That(response, Is.EqualTo(request));
        }
 public object Any(CachedRequest request)
 {
     return(Request.ToOptimizedResultUsingCache(Cache,
                                                Request.QueryString.ToString(),
                                                () => request));
 }
Example #6
0
        public object Any(CachedRequest request)
        {
            var cacheKey = Request.QueryString.ToString();

            return(Request.ToOptimizedResultUsingCache(Cache, cacheKey, () => request));
        }