public void Should_have_route_values_from_Data_RouteValues_property() { // Arrange ISecurityContext innerSecurityContext = new MockSecurityContext(); innerSecurityContext.Data.RouteValues = new RouteValueDictionary(); // Act var context = new MvcSecurityContext(innerSecurityContext); // Assert Assert.That(context.RouteValues, Is.EqualTo(innerSecurityContext.Data.RouteValues)); }
public void SetUp() { _securityContext = new MockSecurityContext(); FakeIoC.GetAllInstancesProvider = () => new List<object> { _securityContext }; SecurityConfigurator.Configure(configuration => { configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsTrue); configuration.ResolveServicesUsing(FakeIoC.GetAllInstances); }); }
public void SetUp() { SecurityConfigurator.Reset(); FakeIoC.Reset(); _context = new MockSecurityContext(); }
public void Should_load_lazy_policy_with_cache_key_exactly_twice_during_execution_with_caching_on() { // Arrange var callsToContainer = 0; var policy = new LazyLoadedPolicyWithCacheKey(); FakeIoC.GetAllInstancesProvider = () => { callsToContainer++; return new List<object> { policy }; }; SecurityConfigurator.Configure(configuration => { configuration.GetAuthenticationStatusFrom(TestDataFactory.ValidIsAuthenticatedFunction); configuration.ResolveServicesUsing(FakeIoC.GetAllInstances); configuration.Advanced.SetDefaultResultsCacheLifecycle(Cache.PerHttpRequest); }); var context = new MockSecurityContext(runtime: SecurityConfiguration.Current.Runtime); var policyContainer = new PolicyContainer(TestDataFactory.ValidControllerName, TestDataFactory.ValidActionName, TestDataFactory.CreateValidPolicyAppender()); policyContainer.AddPolicy<LazyLoadedPolicyWithCacheKey>(); // Act policyContainer.EnforcePolicies(context); policyContainer.EnforcePolicies(context); // Assert Assert.That(callsToContainer, Is.EqualTo(2)); Assert.That(policy.CacheKeyCallCount, Is.EqualTo(2), "Did not get the custom cache key the expected amount of times"); Assert.That(policy.EnforceCallCount, Is.EqualTo(1), "Did not call enforce the expected amount of times"); }