public void ResponseCacheFilter_DoesNotThrowIfDurationIsNotSet_WhenNoStoreIsFalse()
        {
            // Arrange, Act
            var cache = new ResponseCacheFilter(
                new CacheProfile
                {
                    Duration = null
                });

            // Assert
            Assert.NotNull(cache);
        }
Example #2
0
        public void ResponseCacheFilter_DoesNotThrowIfDurationIsNotSet_WhenNoStoreIsFalse()
        {
            // Arrange, Act
            var cache = new ResponseCacheFilter(
                new CacheProfile
            {
                Duration = null
            });

            // Assert
            Assert.NotNull(cache);
        }
Example #3
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"]);
        }
Example #4
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"]);
        }
Example #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"]);
        }
Example #8
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);
        }
Example #9
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"]);
        }
Example #10
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"]);
        }
Example #11
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"]);
        }
        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"]);
        }
        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"]);
        }
        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"]);
        }
        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 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"]);
        }
        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"]);
        }