public void OutputCacheSetsVaryByValues()
        {
            // Arrange
            var timestamp = new DateTime(2011, 1, 1, 0, 0, 0);
            var context   = new Mock <HttpContextBase>();

            context.SetupGet(c => c.Timestamp).Returns(timestamp);
            var response = new Mock <HttpResponseBase>().Object;

            var varyByParams          = new HttpCacheVaryByParams();
            var varyByHeader          = new HttpCacheVaryByHeaders();
            var varyByContentEncoding = new HttpCacheVaryByContentEncodings();

            var cache = new Mock <HttpCachePolicyBase>();

            cache.SetupGet(c => c.VaryByParams).Returns(varyByParams);
            cache.SetupGet(c => c.VaryByHeaders).Returns(varyByHeader);
            cache.SetupGet(c => c.VaryByContentEncodings).Returns(varyByContentEncoding);

            // Act
            ResponseExtensions.OutputCache(context.Object, cache.Object, 20, false, new[] { "foo" }, new[] { "bar", "bar2" },
                                           new[] { "baz", "baz2" }, HttpCacheability.Public);

            // Assert
            Assert.Equal(varyByParams["foo"], true);
            Assert.Equal(varyByHeader["bar"], true);
            Assert.Equal(varyByHeader["bar2"], true);
            Assert.Equal(varyByContentEncoding["baz"], true);
            Assert.Equal(varyByContentEncoding["baz2"], true);
        }
Beispiel #2
0
        public void Indexer()
        {
            HttpResponse response = new HttpResponse(Console.Out);
            HttpCacheVaryByContentEncodings encs = response.Cache.VaryByContentEncodings;

            encs ["gzip"]  = true;
            encs ["bzip2"] = false;

            Assert.IsTrue(encs ["gzip"], "gzip == true");
            Assert.IsFalse(encs ["bzip2"], "bzip2 == false");

            bool exceptionCaught = false;

            try {
                encs [null] = true;
            } catch (ArgumentNullException) {
                exceptionCaught = true;
            }
            Assert.IsTrue(exceptionCaught, "ArgumentNullException on this [null] setter");

            exceptionCaught = false;
            try {
                bool t = encs [null];
            } catch (ArgumentNullException) {
                exceptionCaught = true;
            }
            Assert.IsTrue(exceptionCaught, "ArgumentNullException on this [null] getter");
        }