public void OnProvidersExecuting_AddsResponseCacheFilters()
    {
        // Arrange
        var options  = Options.Create(new MvcOptions());
        var provider = new ResponseCacheFilterApplicationModelProvider(options, Mock.Of <ILoggerFactory>());
        var typeInfo = typeof(PageWithResponseCache).GetTypeInfo();
        var context  = GetApplicationProviderContext(typeInfo);

        // Act
        provider.OnProvidersExecuting(context);

        // Assert
        Assert.Collection(
            context.PageApplicationModel.Filters,
            f => { },
            f => Assert.IsType <PageHandlerPageFilter>(f),
            f => Assert.IsType <HandleOptionsRequestsPageFilter>(f),
            f =>
        {
            var filter = Assert.IsType <PageResponseCacheFilter>(f);
            Assert.Equal("Abc", filter.VaryByHeader);
            Assert.Equal(12, filter.Duration);
            Assert.True(filter.NoStore);
        });
    }
    public void OnProvidersExecuting_ReadsCacheProfileFromOptions()
    {
        // Arrange
        var options = Options.Create(new MvcOptions());

        options.Value.CacheProfiles.Add("TestCacheProfile", new CacheProfile
        {
            Duration        = 14,
            VaryByQueryKeys = new[] { "A" },
        });
        var provider = new ResponseCacheFilterApplicationModelProvider(options, Mock.Of <ILoggerFactory>());
        var typeInfo = typeof(PageWithResponseCacheProfile).GetTypeInfo();
        var context  = GetApplicationProviderContext(typeInfo);

        // Act
        provider.OnProvidersExecuting(context);

        // Assert
        Assert.Collection(
            context.PageApplicationModel.Filters,
            f => { },
            f => Assert.IsType <PageHandlerPageFilter>(f),
            f => Assert.IsType <HandleOptionsRequestsPageFilter>(f),
            f =>
        {
            var filter = Assert.IsType <PageResponseCacheFilter>(f);
            Assert.Equal(new[] { "A" }, filter.VaryByQueryKeys);
            Assert.Equal(14, filter.Duration);
        });
    }
    public void OnProvidersExecuting_DoesNothingIfHandlerHasNoResponseCacheAttributes()
    {
        // Arrange
        var options  = Options.Create(new MvcOptions());
        var provider = new ResponseCacheFilterApplicationModelProvider(options, Mock.Of <ILoggerFactory>());
        var typeInfo = typeof(PageWithoutResponseCache).GetTypeInfo();
        var context  = GetApplicationProviderContext(typeInfo);

        // Act
        provider.OnProvidersExecuting(context);

        // Assert
        Assert.Collection(
            context.PageApplicationModel.Filters,
            f => Assert.IsType <PageHandlerPageFilter>(f),
            f => Assert.IsType <HandleOptionsRequestsPageFilter>(f));
    }