public void TestRefreshPolicyFor404()
        {
            var configuration = new HttpConfiguration(new HttpRouteCollection("/"));

            configuration.Routes.MapHttpRoute("main", "api/{controller}/{id}");
            configuration.Services.Replace(typeof(IHttpControllerSelector), new NotFoundControllerSelector());
            var request   = new HttpRequestMessage(HttpMethod.Get, new Uri("http://aliostad/api/CacheRefreshPolicyAction/1"));
            var routeData = configuration.Routes.GetRouteData(request);

            request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, (object)routeData);
            var attributeBasedCachePolicy = new AttributeBasedCacheRefreshPolicy();

            // act
            var refresh = attributeBasedCachePolicy.DoGetCacheRefreshPolicy(request, configuration);

            // assert
            Assert.AreEqual(false, refresh.HasValue);
        }
        public void TestDefaultControllerOrActionLevelPolicy()
        {
            // arrange
            var configuration = new HttpConfiguration(new HttpRouteCollection("/"));

            configuration.Routes.MapHttpRoute("main", "api/{controller}/{id}");
            var request   = new HttpRequestMessage(HttpMethod.Get, new Uri("http://aliostad/api/NoCacheRefreshPolicy/1"));
            var routeData = configuration.Routes.GetRouteData(request);

            request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, (object)routeData);
            var attributeBasedCachePolicy = new AttributeBasedCacheRefreshPolicy();

            // act
            var refresh = attributeBasedCachePolicy.DoGetCacheRefreshPolicy(request, configuration);

            // assert
            Assert.AreEqual(false, refresh.HasValue);
        }
        public void TestControllerAndActionLevelPolicy()
        {
            var configuration = new HttpConfiguration(new HttpRouteCollection("/"));

            configuration.Routes.MapHttpRoute("main", "api/{controller}/{id}");
            var request   = new HttpRequestMessage(HttpMethod.Get, new Uri("http://aliostad/api/CacheRefreshPolicyAction/1"));
            var routeData = configuration.Routes.GetRouteData(request);

            request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, (object)routeData);
            var attributeBasedCachePolicy = new AttributeBasedCacheRefreshPolicy();

            // act
            var refresh = attributeBasedCachePolicy.DoGetCacheRefreshPolicy(request, configuration);

            // assert
            Assert.AreEqual(true, refresh.HasValue);
            Assert.AreEqual(TimeSpan.FromSeconds(120), refresh.Value);
        }