Permalink
Browse files

- Added missing specs for PolicyContainerConfigurationWrapper.

  • Loading branch information...
1 parent a6b86d6 commit 108810a3212ffb49f1b6faaebc9955d9044f613a Kristoffer Ahl committed Dec 4, 2012
@@ -0,0 +1,80 @@
+using System;
+using FluentSecurity.Caching;
+using FluentSecurity.Configuration;
+using FluentSecurity.Policy;
+using Moq;
+using NUnit.Framework;
+
+namespace FluentSecurity.Specification.Configuration
+{
+ [TestFixture]
+ [Category("PolicyContainerConfigurationWrapperSpec")]
+ public class When_performing_actions_on_PolicyContainerConfigurationWrapper
+ {
+ private Mock<IPolicyContainerConfiguration> _inner;
+ private PolicyContainerConfigurationWrapper<IgnorePolicy> _wrapper;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _inner = new Mock<IPolicyContainerConfiguration>();
+ _wrapper = new PolicyContainerConfigurationWrapper<IgnorePolicy>(_inner.Object);
+ }
+
+ [Test]
+ public void Should_add_policy_to_inner_configuration()
+ {
+ // Arrange
+ var expectedPolicy = new IgnorePolicy();
+
+ // Act
+ _wrapper.AddPolicy(expectedPolicy);
+ _wrapper.AddPolicy<IgnorePolicy>();
+
+ // Assert
+ _inner.Verify(x => x.AddPolicy(expectedPolicy), Times.Exactly(1));
+ _inner.Verify(x => x.AddPolicy<IgnorePolicy>(), Times.Exactly(1));
+ }
+
+ [Test]
+ public void Should_remove_policy_from_inner_configuration()
+ {
+ // Arrange
+ Func<IgnorePolicy, bool> expectedPredicate = p => true;
+
+ // Act
+ _wrapper.RemovePolicy(expectedPredicate);
+
+ // Assert
+ _inner.Verify(x => x.RemovePolicy(expectedPredicate), Times.Exactly(1));
+ }
+
+ [Test]
+ public void Should_set_cache_lifecycle_on_inner_configuration()
+ {
+ // Arrange
+ const Cache expectedLifecycle = Cache.PerHttpRequest;
+ const By expectedLevel = By.Controller;
+
+ // Act
+ _wrapper.Cache<IgnorePolicy>(expectedLifecycle);
+ _wrapper.Cache<IgnorePolicy>(expectedLifecycle, expectedLevel);
+
+ // Assert
+ _inner.Verify(x => x.Cache<IgnorePolicy>(expectedLifecycle), Times.Exactly(1));
+ _inner.Verify(x => x.Cache<IgnorePolicy>(expectedLifecycle, expectedLevel), Times.Exactly(1));
+ }
+
+ [Test]
+ public void Should_clear_cache_strategies_on_inner_configuration()
+ {
+ // Act
+ _wrapper.ClearCacheStrategies();
+ _wrapper.ClearCacheStrategyFor<IgnorePolicy>();
+
+ // Assert
+ _inner.Verify(x => x.ClearCacheStrategies(), Times.Exactly(1));
+ _inner.Verify(x => x.ClearCacheStrategyFor<IgnorePolicy>(), Times.Exactly(1));
+ }
+ }
+}
@@ -97,6 +97,7 @@
<Compile Include="AssemblyScannerBaseSpecification.cs" />
<Compile Include="ConfigurationExpressionSpec.cs" />
<Compile Include="Configuration\AdvancedConfigurationSpec.cs" />
+ <Compile Include="Configuration\PolicyContainerConfigurationWrapperSpec.cs" />
<Compile Include="Configuration\SecurityProfileSpec.cs" />
<Compile Include="Configuration\ViolationHandlerConfigurationSpec.cs" />
<Compile Include="Configuration\ViolationConfigurationSpec.cs" />

0 comments on commit 108810a

Please sign in to comment.