public void OnActionExecuting_CanSetCacheControlHeaders(ResponseCacheAttribute cache, string output)
        {
            // Arrange
            var context = GetActionExecutingContext(new List <IFilter> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal(output, context.HttpContext.Response.Headers.Get("Cache-control"));
        }
        public void OnActionExecuting_DoesNotSetLocationOrDuration_IfNoStoreIsSet(
            ResponseCacheAttribute cache, string output)
        {
            // Arrange
            var context = GetActionExecutingContext(new List <IFilter> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal(output, context.HttpContext.Response.Headers.Get("Cache-control"));
        }
        public void OnActionExecuting_ThrowsIfDurationIsNotSet_WhenNoStoreIsFalse()
        {
            // Arrange
            var cache = new ResponseCacheAttribute()
            {
                NoStore = false
            };
            var context = GetActionExecutingContext(new List <IFilter> {
                cache
            });

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

            Assert.Equal("If the 'NoStore' property is not set to true, 'Duration' property must be specified.",
                         exception.Message);
        }
        public void OnActionExecuting_DoesNotThrow_WhenNoStoreIsTrue()
        {
            // Arrange
            var cache = new ResponseCacheAttribute()
            {
                NoStore = true
            };
            var context = GetActionExecutingContext(new List <IFilter> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("no-store", context.HttpContext.Response.Headers.Get("Cache-control"));
        }
        public void SetsPragmaOnNoCache()
        {
            // Arrange
            var cache = new ResponseCacheAttribute()
            {
                NoStore  = true,
                Location = ResponseCacheLocation.None,
                Duration = 0
            };
            var context = GetActionExecutingContext(new List <IFilter> {
                cache
            });

            // Act
            cache.OnActionExecuting(context);

            // Assert
            Assert.Equal("no-store,no-cache", context.HttpContext.Response.Headers.Get("Cache-control"));
            Assert.Equal("no-cache", context.HttpContext.Response.Headers.Get("Pragma"));
        }