Beispiel #1
0
        public static void TestManualInvalidation(string method)
        {
            // setup
            var mocks = new MockRepository();

            string routePattern1 = "http://myserver/api/stuffs/*";
            string routePattern2 = "http://myserver/api/more/*";

            var entityTagStore = mocks.StrictMock <IEntityTagStore>();
            var linkedUrls     = new[] { "url1", "url2" };
            var cachingHandler = new CachingHandler(new HttpConfiguration(), entityTagStore)
            {
                LinkedRoutePatternProvider = (req) => linkedUrls,
            };

            entityTagStore.Expect(x => x.RemoveResource("/api/stuff/")).Return(1);
            entityTagStore.Expect(x => x.RemoveResource("/api/more/")).Return(1);


            mocks.ReplayAll();

            // run
            cachingHandler.InvalidateResource(new HttpRequestMessage(new HttpMethod(method), new Uri(TestUrl)));
            cachingHandler.InvalidateResource(new HttpRequestMessage(new HttpMethod(method), new Uri(TestUrl2)));

            // verify
            mocks.VerifyAll();
        }
        public static void TestManualInvalidation(string method)
        {
            // setup
            var mocks = new MockRepository();

            var entityTagStore = mocks.StrictMock <IEntityTagStore>();
            var cachingHandler = new CachingHandler("test", "1.0.0", new HttpConfiguration(), entityTagStore);

            entityTagStore.Expect(x => x.RemoveResource("/api/stuff/")).Return(1);
            entityTagStore.Expect(x => x.RemoveAllByRoutePattern("/api/stuff/")).Return(1);
            entityTagStore.Expect(x => x.RemoveResource("/api/more/")).Return(1);
            entityTagStore.Expect(x => x.RemoveAllByRoutePattern("/api/more/")).Return(1);


            mocks.ReplayAll();

            // run
            cachingHandler.InvalidateResource(new HttpRequestMessage(new HttpMethod(method), new Uri(TestUrl)));
            cachingHandler.InvalidateResource(new HttpRequestMessage(new HttpMethod(method), new Uri(TestUrl2)));

            // verify
            mocks.VerifyAll();
        }