Exemplo n.º 1
0
        public void TypicalFreshCase_Expires()
        {
            var fresh          = DateTimeOffset.Now.Add(TimeSpan.FromMinutes(10));
            var cachedResponse = ResponseHelper.GetOkMessage();

            cachedResponse.Content = new StringContent("Ravi");
            cachedResponse.Content.Headers.Expires = fresh;

            var req       = new HttpRequestMessage(HttpMethod.Get, "http://some.sing");
            var freshness = CachingHandler.IsFreshOrStaleAcceptable(cachedResponse, req);

            Assert.NotNull(freshness);
            Assert.True(freshness);
        }
Exemplo n.º 2
0
        public void TypicalFreshCase_MaxAge()
        {
            var cachedResponse = ResponseHelper.GetOkMessage();

            cachedResponse.Content = new StringContent("Ravi");
            cachedResponse.Headers.CacheControl = new CacheControlHeaderValue()
            {
                MaxAge = TimeSpan.FromSeconds(1)
            };

            var req       = new HttpRequestMessage(HttpMethod.Get, "http://some.sing");
            var freshness = CachingHandler.IsFreshOrStaleAcceptable(cachedResponse, req);

            Assert.NotNull(freshness);
            Assert.True(freshness);
        }
Exemplo n.º 3
0
        [Fact] public void TypicalStaleCase_MaxAge_and_Age()
        {
            var cachedResponse = ResponseHelper.GetOkMessage();

            cachedResponse.Content = new StringContent("Ravi");
            cachedResponse.Headers.CacheControl = new CacheControlHeaderValue()
            {
                MaxAge = TimeSpan.FromSeconds(60)
            };
            cachedResponse.Headers.Age  = TimeSpan.FromSeconds(50);
            cachedResponse.Headers.Date = DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(50));


            var req       = new HttpRequestMessage(HttpMethod.Get, "http://some.sing");
            var freshness = CachingHandler.IsFreshOrStaleAcceptable(cachedResponse, req);

            Assert.NotNull(freshness);
            Assert.False(freshness);
        }