本文整理汇总了C#中PolicyContainer.Cache方法的典型用法代码示例。如果您正苦于以下问题:C# PolicyContainer.Cache方法的具体用法?C# PolicyContainer.Cache怎么用?C# PolicyContainer.Cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PolicyContainer
的用法示例。
在下文中一共展示了PolicyContainer.Cache方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_clear_all_cache_strategies_for_policy
public void Should_clear_all_cache_strategies_for_policy()
{
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
policyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);
policyContainer.Cache<RequireAllRolesPolicy>(Cache.PerHttpRequest);
// Act
policyContainer.ClearCacheStrategyFor<RequireAnyRolePolicy>();
// Assert
Assert.That(policyContainer.CacheStrategies.Single().PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
}
示例2: Should_clear_all_cache_strategies
public void Should_clear_all_cache_strategies()
{
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
policyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);
// Act
policyContainer.ClearCacheStrategies();
// Assert
Assert.That(policyContainer.CacheStrategies.Any(), Is.False);
}
示例3: Should_update_existing_policyresult_cache_strategies
public void Should_update_existing_policyresult_cache_strategies()
{
// Arrange
const Cache expectedLifecycle = Cache.PerHttpSession;
const string expectedControllerName = "Controller6";
const string expectedActionName = "Action6";
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
policyContainer
.Cache<RequireAllRolesPolicy>(Cache.PerHttpRequest, By.Controller)
.Cache<RequireAllRolesPolicy>(Cache.PerHttpSession, By.Policy);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(policyResultCacheStrategy.ActionName, Is.EqualTo(expectedActionName));
Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(By.Policy));
}
示例4: Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_level_set_to_Policy
public void Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_level_set_to_Policy()
{
const By expectedLevel = By.Policy;
var policyContainer = new PolicyContainer("Controller", "Action", TestDataFactory.CreateValidPolicyAppender());
// Act
policyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest, expectedLevel);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(expectedLevel));
}
示例5: Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_lifecycle_set_to_PerHttpSession
public void Should_add_policyresult_cache_strategy_for_RequireAnyRolePolicy_with_lifecycle_set_to_PerHttpSession()
{
const Cache expectedLifecycle = Cache.PerHttpSession;
const string expectedControllerName = "Controller3";
const string expectedActionName = "Action3";
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
policyContainer.Cache<RequireAnyRolePolicy>(expectedLifecycle);
// Assert
var policyResultCacheStrategy = policyContainer.CacheStrategies.Single();
Assert.That(policyResultCacheStrategy.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(policyResultCacheStrategy.ActionName, Is.EqualTo(expectedActionName));
Assert.That(policyResultCacheStrategy.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(policyResultCacheStrategy.CacheLifecycle, Is.EqualTo(expectedLifecycle));
Assert.That(policyResultCacheStrategy.CacheLevel, Is.EqualTo(By.ControllerAction));
}
示例6: Should_add_policyresult_cache_strategies_for_each_policy_type
public void Should_add_policyresult_cache_strategies_for_each_policy_type()
{
// Arrange
const string expectedControllerName = "Controller5";
const string expectedActionName = "Action5";
var policyContainer = new PolicyContainer(expectedControllerName, expectedActionName, TestDataFactory.CreateValidPolicyAppender());
// Act
policyContainer
.Cache<RequireAllRolesPolicy>(Cache.PerHttpRequest)
.Cache<RequireAnyRolePolicy>(Cache.PerHttpSession);
// Assert
Assert.That(policyContainer.CacheStrategies.Count, Is.EqualTo(2));
var strategy1 = policyContainer.CacheStrategies.First();
Assert.That(strategy1.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(strategy1.ActionName, Is.EqualTo(expectedActionName));
Assert.That(strategy1.PolicyType, Is.EqualTo(typeof(RequireAllRolesPolicy)));
Assert.That(strategy1.CacheLifecycle, Is.EqualTo(Cache.PerHttpRequest));
Assert.That(strategy1.CacheLevel, Is.EqualTo(By.ControllerAction));
var strategy2 = policyContainer.CacheStrategies.Last();
Assert.That(strategy2.ControllerName, Is.EqualTo(expectedControllerName));
Assert.That(strategy2.ActionName, Is.EqualTo(expectedActionName));
Assert.That(strategy2.PolicyType, Is.EqualTo(typeof(RequireAnyRolePolicy)));
Assert.That(strategy2.CacheLifecycle, Is.EqualTo(Cache.PerHttpSession));
Assert.That(strategy2.CacheLevel, Is.EqualTo(By.ControllerAction));
}