public void Should_be_successful_when_delegate_returns_success() { // Arrange Func <DelegateSecurityContext, PolicyResult> successDelegate = c => PolicyResult.CreateSuccessResult(c.Policy); var policy = new DelegatePolicy(ValidPolicyName, successDelegate, ValidViolationHandlerDelegate); var context = TestDataFactory.CreateSecurityContext(true); // Act var result = policy.Enforce(context); // Assert Assert.That(result, Is.TypeOf <DelegatePolicyResult>()); Assert.That(result.ViolationOccured, Is.False); }
public void Should_not_be_successful_when_delegate_returns_failure() { // Arrange Func <DelegateSecurityContext, PolicyResult> failureDelegate = c => PolicyResult.CreateFailureResult(c.Policy, "Access denied"); var policy = new DelegatePolicy(ValidPolicyName, failureDelegate, ValidViolationHandlerDelegate); var context = TestDataFactory.CreateSecurityContext(true); // Act var result = policy.Enforce(context); // Assert Assert.That(result, Is.TypeOf <DelegatePolicyResult>()); Assert.That(result.ViolationOccured, Is.True); Assert.That(result.Message, Is.EqualTo("Access denied")); }
public void Should_pass_wrapped_security_context_to_delegate() { // Arrange DelegateSecurityContext delegateContext = null; Func <DelegateSecurityContext, PolicyResult> successDelegate = c => { delegateContext = c; return(PolicyResult.CreateSuccessResult(c.Policy)); }; var policy = new DelegatePolicy(ValidPolicyName, successDelegate, ValidViolationHandlerDelegate); var context = TestDataFactory.CreateSecurityContext(true); // Act policy.Enforce(context); // Assert Assert.That(typeof(ISecurityContext).IsAssignableFrom(delegateContext.GetType()), Is.True); Assert.That(delegateContext.CurrenUserAuthenticated(), Is.EqualTo(context.CurrenUserAuthenticated())); Assert.That(delegateContext.CurrenUserRoles(), Is.EqualTo(context.CurrenUserRoles())); }