Example #1
0
		public static void TestCacheInvalidationForPost(string method)
		{
		    const string relatedUrl = "http://api/SomeLocationUrl/";
			// setup
			var locationUrl = new Uri(relatedUrl);
			var mocks = new MockRepository();
			var request = new HttpRequestMessage(new HttpMethod(method), TestUrl);
			string routePattern = "http://myserver/api/stuffs/*";
			var entityTagStore = mocks.StrictMock<IEntityTagStore>();

			var cachingHandler = new CachingHandler(new HttpConfiguration(), entityTagStore)
			{
				
			};
			var entityTagKey = new CacheKey(TestUrl, new string[0], routePattern);
			var response = new HttpResponseMessage();
			response.Headers.Location = locationUrl;
			var invalidateCacheForPost = cachingHandler.PostInvalidationRule(entityTagKey, request, response);
			if(method == "POST")
			{
                entityTagStore.Expect(x => x.RemoveAllByRoutePattern("/SomeLocationUrl/")).Return(1);				
			}
			mocks.ReplayAll();

			// run
			invalidateCacheForPost();

			// verify
			mocks.VerifyAll();

			
		}
Example #2
0
        public static void TestCacheInvalidationForPost(string method)
        {
            // setup
            var locationUrl = new Uri("http://api/SomeLocationUrl");
            var mocks = new MockRepository();
            var request = new HttpRequestMessage(new HttpMethod(method), TestUrl);
            string routePattern = "http://myserver/api/stuffs/*";
            var entityTagStore = mocks.StrictMock<IEntityTagStore>();
            var linkedUrls = new[] { "url1", "url2" };
            var cachingHandler = new CachingHandler(entityTagStore)
            {
                LinkedRoutePatternProvider = (url, mthd, headers) => linkedUrls
            };
            var entityTagKey = new CacheKey(TestUrl, new string[0], routePattern);
            var response = new HttpResponseMessage();
            response.Headers.Location = locationUrl;
            var invalidateCacheForPost = cachingHandler.PostInvalidationRule(entityTagKey, request, response);
            if(method == "POST")
            {
                entityTagStore.Expect(x => x.RemoveAllByRoutePattern(locationUrl.ToString())).Return(1);
            }
            mocks.ReplayAll();

            // run
            invalidateCacheForPost();

            // verify
            mocks.VerifyAll();
        }