Exemple #1
0
        public void Should_clear_all_cache_strategies_for_policy()
        {
            var controllerName   = NameHelper.Controller <AdminController>();
            var policyContainers = new List <PolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast <IPolicyContainerConfiguration>().ToList());

            conventionPolicyContainer.Cache <RequireAnyRolePolicy>(Cache.PerHttpRequest);
            conventionPolicyContainer.Cache <RequireAllRolesPolicy>(Cache.PerHttpRequest);

            // Act
            conventionPolicyContainer.ClearCacheStrategyFor <RequireAnyRolePolicy>();

            // Assert
            var containers = policyContainers.ToList();

            Assert.That(containers[0].CacheStrategies.Single().PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
            Assert.That(containers[1].CacheStrategies.Single().PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
            Assert.That(containers[2].CacheStrategies.Single().PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
        }
Exemple #2
0
        public void Should_add_policyresult_cache_strategy_to_policycontainers()
        {
            // Arrange
            var controllerName   = NameHelper.Controller <AdminController>();
            var policyContainers = new List <PolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var         conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast <IPolicyContainerConfiguration>().ToList());
            const Cache expectedLifecycle         = Cache.PerHttpRequest;
            const By    expectedLevel             = By.ControllerAction;
            var         expectedType = typeof(DenyAnonymousAccessPolicy);

            // Act
            conventionPolicyContainer.Cache <DenyAnonymousAccessPolicy>(expectedLifecycle, expectedLevel);

            // Assert
            var containers = policyContainers.ToList();

            Assert.That(containers[0].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[0].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[0].CacheStrategies.Single().CacheLevel, Is.EqualTo(expectedLevel));
            Assert.That(containers[1].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[1].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[1].CacheStrategies.Single().CacheLevel, Is.EqualTo(expectedLevel));
            Assert.That(containers[2].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[2].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[2].CacheStrategies.Single().CacheLevel, Is.EqualTo(expectedLevel));
        }
Exemple #3
0
        public void Should_clear_all_cache_strategies()
        {
            var controllerName   = NameHelper.Controller <AdminController>();
            var policyContainers = new List <IPolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers);

            conventionPolicyContainer.Cache <RequireRolePolicy>(Cache.PerHttpRequest);

            // Act
            conventionPolicyContainer.ClearCacheStrategies();

            // Assert
            var containers = policyContainers.Cast <PolicyContainer>().ToList();

            Assert.That(containers[0].CacheStrategies.Any(), Is.False);
            Assert.That(containers[1].CacheStrategies.Any(), Is.False);
            Assert.That(containers[2].CacheStrategies.Any(), Is.False);
        }
        public void Should_clear_all_cache_strategies()
        {
            var controllerName = NameHelper.Controller<AdminController>();
            var policyContainers = new List<IPolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers);
            conventionPolicyContainer.Cache<RequireRolePolicy>(Cache.PerHttpRequest);

            // Act
            conventionPolicyContainer.ClearCacheStrategies();

            // Assert
            var containers = policyContainers.Cast<PolicyContainer>().ToList();
            Assert.That(containers[0].CacheStrategies.Any(), Is.False);
            Assert.That(containers[1].CacheStrategies.Any(), Is.False);
            Assert.That(containers[2].CacheStrategies.Any(), Is.False);
        }
        public void Should_add_policyresult_cache_strategy_to_policycontainers()
        {
            // Arrange
            var controllerName = NameHelper.Controller<AdminController>();
            var policyContainers = new List<IPolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers, By.Controller);
            const Cache expectedLifecycle = Cache.PerHttpRequest;
            var expectedType = typeof(DenyAnonymousAccessPolicy);

            // Act
            conventionPolicyContainer.Cache<DenyAnonymousAccessPolicy>(expectedLifecycle);

            // Assert
            var containers = policyContainers.Cast<PolicyContainer>().ToList();
            Assert.That(containers[0].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[0].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[0].CacheStrategies.Single().CacheLevel, Is.EqualTo(By.Controller));
            Assert.That(containers[1].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[1].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[1].CacheStrategies.Single().CacheLevel, Is.EqualTo(By.Controller));
            Assert.That(containers[2].CacheStrategies.Single().PolicyType, Is.EqualTo(expectedType));
            Assert.That(containers[2].CacheStrategies.Single().CacheLifecycle, Is.EqualTo(expectedLifecycle));
            Assert.That(containers[2].CacheStrategies.Single().CacheLevel, Is.EqualTo(By.Controller));
        }
        public void Should_clear_all_cache_strategies_for_policy()
        {
            var controllerName = NameHelper.Controller<AdminController>();
            var policyContainers = new List<PolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast<IPolicyContainerConfiguration>().ToList());
            conventionPolicyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);
            conventionPolicyContainer.Cache<RequireAllRolesPolicy>(Cache.PerHttpRequest);

            // Act
            conventionPolicyContainer.ClearCacheStrategyFor<RequireAnyRolePolicy>();

            // Assert
            var containers = policyContainers.ToList();
            Assert.That(containers[0].CacheStrategies.Single().PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
            Assert.That(containers[1].CacheStrategies.Single().PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
            Assert.That(containers[2].CacheStrategies.Single().PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
        }