private ExpectationResult VerifyDoesNotHaveType(IPolicyContainer policyContainer, DoesNotHaveTypeExpectation expectation) { if (expectation == null) return null; if (policyContainer != null && policyContainer.HasPolicyOfType(expectation.Type)) { const string messageFormat = "An unexpected policy of type \"{2}\" was found for controller \"{0}\", action \"{1}\"."; var message = string.Format(messageFormat, policyContainer.ControllerName, policyContainer.ActionName, expectation.Type); return _expectationViolationHandler.Handle(message); } return ExpectationResult.CreateSuccessResult(); }
public void Should_have_type_and_default_predicate() { var expectation = new DoesNotHaveTypeExpectation<DenyInternetExplorerPolicy>(); Assert.That(expectation.Type, Is.EqualTo(typeof(DenyInternetExplorerPolicy))); Assert.That(expectation.IsPredicateExpectation, Is.False); Assert.That(expectation.PredicateExpression, Is.Not.Null); Assert.That(expectation.Predicate, Is.Not.Null); Assert.That(expectation.GetPredicateDescription(), Is.EqualTo( "securityPolicy => (securityPolicy.GetPolicyType() == value(FluentSecurity.TestHelper.Expectations.DoesNotHaveTypeExpectation`1[FluentSecurity.TestHelper.Specification.TestData.DenyInternetExplorerPolicy]).Type)" )); }
public void Should_be_match_for_lazy_policy() { // Arrange var expectation = new DoesNotHaveTypeExpectation <IgnorePolicy>(); var policy = new LazySecurityPolicy <IgnorePolicy>(); // Act var isMatch = expectation.IsMatch(policy); // Assert Assert.That(isMatch, Is.True); }
public void Should_not_be_match_for_normal_policy() { // Arrange var expectation = new DoesNotHaveTypeExpectation <DenyAnonymousAccessPolicy>(); var policy = new IgnorePolicy(); // Act var isMatch = expectation.IsMatch(policy); // Assert Assert.That(isMatch, Is.False); }
public void Should_have_type_and_predicate() { Expression<Func<DenyInternetExplorerPolicy, bool>> predicate = p => true; var expectation = new DoesNotHaveTypeExpectation<DenyInternetExplorerPolicy>(predicate); Assert.That(expectation.Type, Is.EqualTo(typeof(DenyInternetExplorerPolicy))); Assert.That(expectation.IsPredicateExpectation, Is.True); Assert.That(expectation.PredicateExpression, Is.EqualTo(predicate)); Assert.That(expectation.Predicate, Is.Not.Null); Assert.That(expectation.GetPredicateDescription(), Is.EqualTo( "p => True" )); }
public void Should_not_be_match_for_lazy_policy() { // Arrange var expectation = new DoesNotHaveTypeExpectation<DenyAnonymousAccessPolicy>(); var policy = new LazySecurityPolicy<IgnorePolicy>(); // Act var isMatch = expectation.IsMatch(policy); // Assert Assert.That(isMatch, Is.False); }
public void Should_have_2_expectations() { // Arrange var expectation1 = new HasTypeExpectation<DenyInternetExplorerPolicy>(); var expectation2 = new DoesNotHaveTypeExpectation<DenyInternetExplorerPolicy>(); // Act _expectationExpression.Add(expectation1).Add(expectation2); // Assert Assert.That(_expectationExpression.Expectations.Count(), Is.EqualTo(2)); }
public void Should_have_type_and_default_predicate() { var expectation = new DoesNotHaveTypeExpectation <DenyInternetExplorerPolicy>(); Assert.That(expectation.Type, Is.EqualTo(typeof(DenyInternetExplorerPolicy))); Assert.That(expectation.IsPredicateExpectation, Is.False); Assert.That(expectation.PredicateExpression, Is.Not.Null); Assert.That(expectation.Predicate, Is.Not.Null); Assert.That(expectation.GetPredicateDescription(), Is.EqualTo( "securityPolicy => (securityPolicy.GetType() == value(FluentSecurity.TestHelper.Expectations.DoesNotHaveTypeExpectation`1[FluentSecurity.TestHelper.Specification.TestData.DenyInternetExplorerPolicy]).Type)" )); }
public void Should_have_2_expectations() { // Arrange var expectation1 = new HasTypeExpectation <DenyInternetExplorerPolicy>(); var expectation2 = new DoesNotHaveTypeExpectation <DenyInternetExplorerPolicy>(); // Act _expectationExpression.Add(expectation1).Add(expectation2); // Assert Assert.That(_expectationExpression.Expectations.Count(), Is.EqualTo(2)); }
public void Should_have_1_expecation_when_expecations_have_same_type_for_DoesNotHaveTypeExpectation() { // Arrange var expectation1 = new DoesNotHaveTypeExpectation <DenyInternetExplorerPolicy>(); var expectation2 = new DoesNotHaveTypeExpectation <DenyInternetExplorerPolicy>(); // Act _expectationGroup.ApplyExpectation(expectation1); _expectationGroup.ApplyExpectation(expectation2); // Assert Assert.That(_expectationGroup.Expectations.Count(), Is.EqualTo(1)); }
public void Should_have_type_and_predicate() { Expression <Func <DenyInternetExplorerPolicy, bool> > predicate = p => true; var expectation = new DoesNotHaveTypeExpectation <DenyInternetExplorerPolicy>(predicate); Assert.That(expectation.Type, Is.EqualTo(typeof(DenyInternetExplorerPolicy))); Assert.That(expectation.IsPredicateExpectation, Is.True); Assert.That(expectation.PredicateExpression, Is.EqualTo(predicate)); Assert.That(expectation.Predicate, Is.Not.Null); Assert.That(expectation.GetPredicateDescription(), Is.EqualTo( "p => True" )); }
private void HandleDoesNotHaveTypeExpectation(DoesNotHaveTypeExpectation expectation) { var hasTypeExpectations = _expectations.OfType <HasTypeExpectation>().Where(x => x.Type == expectation.Type); for (var i = 0; i < hasTypeExpectations.Count(); i++) { var hasTypeExpectation = hasTypeExpectations.ElementAt(i); _expectations.Remove(hasTypeExpectation); } var doesNotHaveTypeExpectations = _expectations.OfType <DoesNotHaveTypeExpectation>(); if (doesNotHaveTypeExpectations.Any(x => x.Type == expectation.Type)) { return; } _expectations.Add(expectation); }
public static bool HasPolicyMatching(this IPolicyContainer policyContainer, DoesNotHaveTypeExpectation predicateExpectation) { var policies = policyContainer.GetPolicies(); return(policies.Any(predicateExpectation.IsMatch)); }
private void HandleDoesNotHaveTypeExpectation(DoesNotHaveTypeExpectation expectation) { var hasTypeExpectations = _expectations.Where(x => x is HasTypeExpectation).Cast<HasTypeExpectation>().Where(x => x.Type == expectation.Type); for (var i = 0; i < hasTypeExpectations.Count(); i++) { var hasTypeExpectation = hasTypeExpectations.ElementAt(i); _expectations.Remove(hasTypeExpectation); } var doesNotHaveTypeExpectations = _expectations.Where(x => x is DoesNotHaveTypeExpectation).Cast<DoesNotHaveTypeExpectation>(); if (doesNotHaveTypeExpectations.Any(x => x.Type == expectation.Type)) return; _expectations.Add(expectation); }
public void Should_have_1_expecation_when_expecations_have_same_type_for_DoesNotHaveTypeExpectation() { // Arrange var expectation1 = new DoesNotHaveTypeExpectation<DenyInternetExplorerPolicy>(); var expectation2 = new DoesNotHaveTypeExpectation<DenyInternetExplorerPolicy>(); // Act _expectationGroup.ApplyExpectation(expectation1); _expectationGroup.ApplyExpectation(expectation2); // Assert Assert.That(_expectationGroup.Expectations.Count(), Is.EqualTo(1)); }
public void Should_be_match_for_normal_policy() { // Arrange var expectation = new DoesNotHaveTypeExpectation<IgnorePolicy>(); var policy = new IgnorePolicy(); // Act var isMatch = expectation.IsMatch(policy); // Assert Assert.That(isMatch, Is.True); }
public void Should_have_type() { var expectation = new DoesNotHaveTypeExpectation<DenyInternetExplorerPolicy>(); Assert.That(expectation.Type, Is.EqualTo(typeof(DenyInternetExplorerPolicy))); }
private ExpectationResult VerifyDoesNotHaveType(IPolicyContainer policyContainer, DoesNotHaveTypeExpectation expectation) { if (expectation == null) { return(null); } if (policyContainer != null && policyContainer.HasPolicyMatching(expectation)) { const string messageFormat = "An unexpected policy of type \"{2}\" was found for controller \"{0}\", action \"{1}\".{3}"; var message = string.Format(messageFormat, policyContainer.ControllerName, policyContainer.ActionName, expectation.Type, GetPredicateDescription(expectation)); return(_expectationViolationHandler.Handle(message)); } return(ExpectationResult.CreateSuccessResult()); }