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("test", "1.0.0", new HttpConfiguration(), entityTagStore); var entityTagKey = new CacheKey(TestUrl, new string[0], routePattern, "test", "1.0.0"); 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); entityTagStore.Expect(x => x.RemoveResource("/SomeLocationUrl/")).Return(1); } mocks.ReplayAll(); // run invalidateCacheForPost(); // verify mocks.VerifyAll(); }
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(new HttpConfiguration(), entityTagStore) { LinkedRoutePatternProvider = (req) => 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(); }