public void Reset() { ServiceLocator.Reset(); ExceptionFactory.Reset(); SecurityCache.ClearCache(Lifecycle.HybridHttpContext);; SecurityCache.ClearCache(Lifecycle.HybridHttpSession);; }
public void Should_use_cache_lifecycle_specified_when_adding_a_policy() { // Arrange const Cache defaultCacheLifecycle = Cache.PerHttpSession; const Cache specifiedCacheLifecycle = Cache.PerHttpRequest; var context = TestDataFactory.CreateSecurityContext(false); var securityPolicy = new IgnorePolicy(); var policyContainer = new PolicyContainer(TestDataFactory.ValidControllerName, TestDataFactory.ValidActionName, TestDataFactory.CreateValidPolicyAppender()); policyContainer.SecurityConfigurationProvider = () => TestDataFactory.CreateValidSecurityConfiguration(configuration => configuration.Advanced.SetDefaultResultsCacheLifecycle(defaultCacheLifecycle)); policyContainer.AddPolicy(securityPolicy).Cache <IgnorePolicy>(specifiedCacheLifecycle); // Act var results1 = policyContainer.EnforcePolicies(context); var results2 = policyContainer.EnforcePolicies(context); SecurityCache.ClearCache(Lifecycle.HybridHttpContext);; var results3 = policyContainer.EnforcePolicies(context); var results4 = policyContainer.EnforcePolicies(context); // Assert Assert.That(results1.Single(), Is.EqualTo(results2.Single())); Assert.That(results3.Single(), Is.EqualTo(results4.Single())); Assert.That(results1.Single(), Is.Not.EqualTo(results3.Single()), "Results should not be equal across requests."); }
public void Should_return_the_same_results() { // Arrange var context = TestDataFactory.CreateSecurityContext(false); var firstPolicy = new IgnorePolicy(); var policyContainer = new PolicyContainer(TestDataFactory.ValidControllerName, TestDataFactory.ValidActionName, TestDataFactory.CreateValidPolicyAppender()); policyContainer.SecurityConfigurationProvider = () => TestDataFactory.CreateValidSecurityConfiguration(configuration => configuration.Advanced.SetDefaultResultsCacheLifecycle(Cache.PerHttpSession)); policyContainer.AddPolicy(firstPolicy); // Act var results1 = policyContainer.EnforcePolicies(context); var results2 = policyContainer.EnforcePolicies(context); SecurityCache.ClearCache(Lifecycle.HybridHttpSession);; var results3 = policyContainer.EnforcePolicies(context); var results4 = policyContainer.EnforcePolicies(context); // Assert Assert.That(results1.Single(), Is.EqualTo(results2.Single())); Assert.That(results3.Single(), Is.EqualTo(results4.Single())); Assert.That(results1.Single(), Is.Not.EqualTo(results3.Single()), "Results should not be equal across sessions."); }
[OneTimeSetUp] //[SetUp] public void Reset() { ServiceLocator.Reset(); ExceptionFactory.Reset(); SecurityDoctor.Reset(); SecurityRuntime.HttpContextAccessor = new Mock <IHttpContextAccessor>().Object; SecurityCache.ClearCache(Lifecycle.HybridHttpContext); SecurityCache.ClearCache(Lifecycle.HybridHttpSession); }