public void Should_have_a_simple_DelegatePolicy()
        {
            // Arrange
            const string policyName = "Name1";
            const string failureMessage = "Some error message";
            Func<DelegateSecurityContext, bool> policyDelegate = context => false;
            Func<PolicyViolationException, ActionResult> violationHandlerDelegate = exception => new EmptyResult();
            var securityContext = new DelegateSecurityContext(new Mock<ISecurityPolicy>().Object, new Mock<ISecurityContext>().Object);

            // Act
            _conventionPolicyContainer.DelegatePolicy(policyName, policyDelegate, violationHandlerDelegate, failureMessage);

            // Assert
            var securityPolicy = _policyContainers[0].GetPolicies().Where(x => x.GetType().Equals(typeof(DelegatePolicy))).Single() as DelegatePolicy;
            Assert.That(securityPolicy, Is.Not.Null);
            Assert.That(securityPolicy.Name, Is.EqualTo(policyName));

            var policyResult = securityPolicy.Policy.Invoke(securityContext);
            Assert.That(policyResult.Message, Is.EqualTo(failureMessage));
            Assert.That(policyResult.ViolationOccured, Is.True);

            Assert.That(securityPolicy.ViolationHandler, Is.EqualTo(violationHandlerDelegate));
        }
 public PolicyResult Enforce(ISecurityContext context)
 {
     var wrappedContext = new DelegateSecurityContext(this, context);
     var policyResult = Policy.Invoke(wrappedContext);
     return new DelegatePolicyResult(policyResult, Name, ViolationHandler);
 }