Esempio n. 1
0
        public void OnActionExecuting_CanSetCacheControlHeaders(ResponseCacheFilter cache, string output)
        {
            // Arrange
            var context = GetActionExecutingContext(new List <IFilterMetadata> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]);
        }
Esempio n. 2
0
        public void OnActionExecuting_DoesNotSetLocationOrDuration_IfNoStoreIsSet(
            ResponseCacheFilter cache, string output)
        {
            // Arrange
            var context = GetActionExecutingContext(new List <IFilterMetadata> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]);
        }
        public void OnActionExecuting_ThrowsIfDurationIsNotSet_WhenNoStoreIsFalse()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile()
                {
                    Duration = null
                });

            var context = GetActionExecutingContext(new List<IFilterMetadata> { cache });

            // Act & Assert
            var ex = Assert.Throws<InvalidOperationException>(() => cache.OnActionExecuting(context));
            Assert.Equal("If the 'NoStore' property is not set to true, 'Duration' property must be specified.",
                ex.Message);
        }
        public void ResponseCacheFilter_DoesNotThrow_WhenNoStoreIsTrue()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
                {
                    NoStore = true,
                    Duration = null
                });
            var context = GetActionExecutingContext(new List<IFilterMetadata> { cache });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("no-store", context.HttpContext.Response.Headers["Cache-control"]);
        }
Esempio n. 5
0
        public void OnActionExecuting_ThrowsIfDurationIsNotSet_WhenNoStoreIsFalse()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile()
            {
                Duration = null
            });

            var context = GetActionExecutingContext(new List <IFilterMetadata> {
                cache
            });

            // Act & Assert
            var ex = Assert.Throws <InvalidOperationException>(() => cache.OnActionExecuting(context));

            Assert.Equal("If the 'NoStore' property is not set to true, 'Duration' property must be specified.",
                         ex.Message);
        }
Esempio n. 6
0
        public void SetsPragmaOnNoCache()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
            {
                Duration = 0, Location = ResponseCacheLocation.None, NoStore = true, VaryByHeader = null
            });
            var context = GetActionExecutingContext(new List <IFilterMetadata> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers["Cache-control"]);
            Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]);
        }
Esempio n. 7
0
        public void ResponseCacheFilter_DoesNotThrow_WhenNoStoreIsTrue()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
            {
                NoStore  = true,
                Duration = null
            });
            var context = GetActionExecutingContext(new List <IFilterMetadata> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("no-store", context.HttpContext.Response.Headers["Cache-control"]);
        }
Esempio n. 8
0
        public void FilterDurationProperty_OverridesCachePolicySetting()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
            {
                Duration = 10
            });

            cache.Duration = 20;
            var context = GetActionExecutingContext(new List <IFilterMetadata> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("public,max-age=20", context.HttpContext.Response.Headers["Cache-control"]);
        }
Esempio n. 9
0
        public void FilterVaryByProperty_OverridesCachePolicySetting()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
            {
                NoStore      = true,
                VaryByHeader = "Accept"
            });

            cache.VaryByHeader = "Test";
            var context = GetActionExecutingContext(new List <IFilterMetadata> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("Test", context.HttpContext.Response.Headers["Vary"]);
        }
Esempio n. 10
0
        public void FilterVaryByProperty_OverridesCachePolicySetting()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
                {
                    NoStore = true,
                    VaryByHeader = "Accept"
                });
            cache.VaryByHeader = "Test";
            var context = GetActionExecutingContext(new List<IFilterMetadata> { cache });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("Test", context.HttpContext.Response.Headers["Vary"]);
        }
Esempio n. 11
0
        public void FilterNoStoreProperty_OverridesCachePolicySetting()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
                {
                    NoStore = true
                });
            cache.NoStore = false;
            cache.Duration = 10;
            var context = GetActionExecutingContext(new List<IFilterMetadata> { cache });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("public,max-age=10", context.HttpContext.Response.Headers["Cache-control"]);
        }
Esempio n. 12
0
        public void FilterLocationProperty_OverridesCachePolicySetting()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
                {
                    Duration = 10,
                    Location = ResponseCacheLocation.None
                });
            cache.Location = ResponseCacheLocation.Client;
            var context = GetActionExecutingContext(new List<IFilterMetadata> { cache });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("private,max-age=10", context.HttpContext.Response.Headers["Cache-control"]);
        }
Esempio n. 13
0
        public void SetsPragmaOnNoCache()
        {
            // Arrange
            var cache = new ResponseCacheFilter(
                new CacheProfile
                {
                    Duration = 0, Location = ResponseCacheLocation.None, NoStore = true, VaryByHeader = null
                });
            var context = GetActionExecutingContext(new List<IFilterMetadata> { cache });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers["Cache-control"]);
            Assert.Equal("no-cache", context.HttpContext.Response.Headers["Pragma"]);
        }
Esempio n. 14
0
        public void ResponseCacheCanSetVary(ResponseCacheFilter cache, string varyOutput, string cacheControlOutput)
        {
            // Arrange
            var context = GetActionExecutingContext(new List<IFilterMetadata> { cache });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal(varyOutput, context.HttpContext.Response.Headers["Vary"]);
            Assert.Equal(cacheControlOutput, context.HttpContext.Response.Headers["Cache-control"]);
        }
Esempio n. 15
0
        public void OnActionExecuting_DoesNotSetLocationOrDuration_IfNoStoreIsSet(
            ResponseCacheFilter cache, string output)
        {
            // Arrange
            var context = GetActionExecutingContext(new List<IFilterMetadata> { cache });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal(output, context.HttpContext.Response.Headers["Cache-control"]);
        }