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();
        }
        public static void PutIfUnmodifiedTest(
            bool resourceHasChanged,
            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.Put, TestUrl);
            DateTimeOffset lastChanged            = DateTimeOffset.Now.Subtract(TimeSpan.FromDays(7));
            DateTimeOffset lastModifiedInQuestion = resourceHasChanged
                                                                                                                ? lastChanged.Subtract(TimeSpan.FromDays(1))
                                                                                                                : lastChanged.Add(TimeSpan.FromDays(1));

            request.Headers.Add(HttpHeaderNames.IfUnmodifiedSince, lastModifiedInQuestion.ToString("r"));
            TimedEntityTagHeaderValue entityTagHeaderValue = new TimedEntityTagHeaderValue("\"12345678\"")
            {
                LastModified = lastChanged
            };

            entityTagStore.Expect(x => x.TryGetValue(Arg <CacheKey> .Matches(etg => etg.ResourceUri == entityTagHandler.UriTrimmer(new Uri(TestUrl))),
                                                     out Arg <TimedEntityTagHeaderValue> .Out(entityTagHeaderValue).Dummy)).Return(true);

            mocks.ReplayAll();


            // run
            var modifiedUnmodifiedSince = entityTagHandler.PutIfUnmodifiedSince();
            var task = modifiedUnmodifiedSince(request);
            HttpResponseMessage response = task == null ? null : task.Result;

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