public static void TestGetReturnsNullIfVerbNotGet()
        {
            // setup
            var request          = new HttpRequestMessage(HttpMethod.Put, TestUrl);
            var entityTagHandler = new CachingHandler(new HttpConfiguration());
            var getRule          = entityTagHandler.GetIfMatchNoneMatch();

            // run
            var task = getRule(request);

            // verify
            Assert.IsNull(task);
        }
        public static void TestGetReturnsBadRequestIfBothIfMatchAndIfNoneMatchExist()
        {
            // setup
            var request = new HttpRequestMessage(HttpMethod.Get, TestUrl);

            request.Headers.Add(HttpHeaderNames.IfMatch, "\"123\"");
            request.Headers.Add(HttpHeaderNames.IfNoneMatch, "\"123\"");
            var entityTagHandler = new CachingHandler(new HttpConfiguration());
            var getRule          = entityTagHandler.GetIfMatchNoneMatch();

            // run
            var task = getRule(request);
            var httpResponseMessage = task.Result;

            // verify
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponseMessage.StatusCode);
        }
        public static void GetMatchNonMatchTest(
            string headerName,
            string[] values,
            bool existsInStore,
            bool expectReturnNull,
            HttpStatusCode expectedStatus = HttpStatusCode.Unused)
        {
            // setup
            var mocks            = new MockRepository();
            var entityTagStore   = mocks.StrictMock <IEntityTagStore>();
            var entityTagHandler = new CachingHandler(new HttpConfiguration(), entityTagStore);
            var request          = new HttpRequestMessage(HttpMethod.Get, TestUrl);

            request.Headers.Add(headerName, values);
            TimedEntityTagHeaderValue entityTagHeaderValue = new TimedEntityTagHeaderValue("\"12345678\"");

            if (values.Length > 0)          // if
            {
                entityTagStore.Expect(x => x.TryGetValue(Arg <CacheKey> .Matches(etg => etg.ResourceUri == entityTagHandler.UriTrimmer(new Uri(TestUrl))),
                                                         out Arg <TimedEntityTagHeaderValue> .Out(entityTagHeaderValue).Dummy)).Return(existsInStore);
            }

            mocks.ReplayAll();


            // run
            var matchNoneMatch = entityTagHandler.GetIfMatchNoneMatch();
            // verify
            Task <HttpResponseMessage> resultTask = matchNoneMatch(request);

            Assert.That(expectReturnNull ^ resultTask != null, "result was not as expected");
            if (resultTask != null && expectedStatus != HttpStatusCode.Unused)
            {
                Assert.AreEqual(expectedStatus, resultTask.Result.StatusCode, "Status code");
            }
            mocks.VerifyAll();
        }