public void Should_have_1_expectations() { // Arrange var expectation = new HasTypeExpectation <DenyInternetExplorerPolicy>(); // Act _expectationExpression.Add(expectation); // Assert Assert.That(_expectationExpression.Expectations.Count(), Is.EqualTo(1)); }
public void Should_have_1_expectations() { // Arrange var expectation = new HasTypeExpectation<DenyInternetExplorerPolicy>(); // Act _expectationExpression.Add(expectation); // Assert Assert.That(_expectationExpression.Expectations.Count(), Is.EqualTo(1)); }
public void Should_have_type_and_default_predicate() { var expectation = new HasTypeExpectation<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.HasTypeExpectation`1[FluentSecurity.TestHelper.Specification.TestData.DenyInternetExplorerPolicy]).Type)" )); }
public void Should_have_type_and_default_predicate() { var expectation = new HasTypeExpectation <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.HasTypeExpectation`1[FluentSecurity.TestHelper.Specification.TestData.DenyInternetExplorerPolicy]).Type)" )); }
public void Should_have_type_and_predicate() { Expression<Func<DenyInternetExplorerPolicy, bool>> predicate = p => true; var expectation = new HasTypeExpectation<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 HasTypeExpectation<DenyAnonymousAccessPolicy>(); var policy = new LazySecurityPolicy<IgnorePolicy>(); // Act var isMatch = expectation.IsMatch(policy); // Assert Assert.That(isMatch, Is.False); }
public void Should_be_match_for_lazy_policy() { // Arrange var expectation = new HasTypeExpectation<IgnorePolicy>(); var policy = new LazySecurityPolicy<IgnorePolicy>(); // Act var isMatch = expectation.IsMatch(policy); // Assert Assert.That(isMatch, Is.True); }
public void Should_be_match_for_lazy_policy() { // Arrange var expectation = new HasTypeExpectation <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 HasTypeExpectation <DenyAnonymousAccessPolicy>(); var policy = new 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_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_predicate() { Expression <Func <DenyInternetExplorerPolicy, bool> > predicate = p => true; var expectation = new HasTypeExpectation <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_have_2_expecation_when_expecations_have_different_types_for_HasTypeExpectation() { // Arrange var expectation1 = new HasTypeExpectation <DenyInternetExplorerPolicy>(); var expectation2 = new HasTypeExpectation <DenyLynxPolicy>(); // Act _expectationGroup.ApplyExpectation(expectation1); _expectationGroup.ApplyExpectation(expectation2); // Assert Assert.That(_expectationGroup.Expectations.Count(), Is.EqualTo(2)); }
public void Should_have_1_expecation_when_expecations_have_same_type_for_does_not_have_and_has() { // Arrange var expectation1 = new DoesNotHaveTypeExpectation <DenyInternetExplorerPolicy>(); var expectation2 = new HasTypeExpectation <DenyInternetExplorerPolicy>(); // Act _expectationGroup.ApplyExpectation(expectation1); _expectationGroup.ApplyExpectation(expectation2); // Assert Assert.That(_expectationGroup.Expectations.Count(), Is.EqualTo(1)); }
private void HandleHasTypeExpectation(HasTypeExpectation expectation) { var doesNotHaveTypeExpectations = _expectations.OfType <DoesNotHaveTypeExpectation>().Where(x => x.Type == expectation.Type); for (var i = 0; i < doesNotHaveTypeExpectations.Count(); i++) { var doesNotHaveTypeExpectation = doesNotHaveTypeExpectations.ElementAt(i); _expectations.Remove(doesNotHaveTypeExpectation); } var hasTypeExpectations = _expectations.OfType <HasTypeExpectation>(); if (hasTypeExpectations.Any(x => x.Type == expectation.Type)) { return; } _expectations.Add(expectation); }
private ExpectationResult VerifyHasType(IPolicyContainer policyContainer, HasTypeExpectation expectation, string controllerName, string actionName) { if (expectation == null) { return(null); } if (policyContainer == null) { const string messageFormat = "Expected a configuration for controller \"{0}\", action \"{1}\". Policycontainer could not be found!"; var message = string.Format(messageFormat, controllerName, actionName); return(_expectationViolationHandler.Handle(message)); } if (policyContainer.HasPolicyMatching(expectation) == false) { const string messageFormat = "Expected policy of type \"{2}\" 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()); }
public void Should_have_type() { var expectation = new HasTypeExpectation<DenyInternetExplorerPolicy>(); Assert.That(expectation.Type, Is.EqualTo(typeof(DenyInternetExplorerPolicy))); }
public static bool HasPolicyMatching(this IPolicyContainer policyContainer, HasTypeExpectation predicateExpectation) { var policies = policyContainer.GetPolicies(); return(policies.Any(predicateExpectation.IsMatch)); }
private ExpectationResult VerifyHasType(IPolicyContainer policyContainer, HasTypeExpectation expectation, string controllerName, string actionName) { if (expectation == null) return null; if (policyContainer == null) { const string messageFormat = "Expected a configuration for controller \"{0}\", action \"{1}\". Policycontainer could not be found!"; var message = string.Format(messageFormat, controllerName, actionName); return _expectationViolationHandler.Handle(message); } if (policyContainer.HasPolicyOfType(expectation.Type) == false) { const string messageFormat = "Expected policy of type \"{2}\" 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_1_expecation_when_expecations_have_same_type_for_has_and_does_not_have() { // Arrange var expectation1 = new HasTypeExpectation<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_2_expecation_when_expecations_have_different_types_for_HasTypeExpectation() { // Arrange var expectation1 = new HasTypeExpectation<DenyInternetExplorerPolicy>(); var expectation2 = new HasTypeExpectation<DenyLynxPolicy>(); // Act _expectationGroup.ApplyExpectation(expectation1); _expectationGroup.ApplyExpectation(expectation2); // Assert Assert.That(_expectationGroup.Expectations.Count(), Is.EqualTo(2)); }
private void HandleHasTypeExpectation(HasTypeExpectation expectation) { var doesNotHaveTypeExpectations = _expectations.Where(x => x is DoesNotHaveTypeExpectation).Cast<DoesNotHaveTypeExpectation>().Where(x => x.Type == expectation.Type); for (var i = 0; i < doesNotHaveTypeExpectations.Count(); i++) { var doesNotHaveTypeExpectation = doesNotHaveTypeExpectations.ElementAt(i); _expectations.Remove(doesNotHaveTypeExpectation); } var hasTypeExpectations = _expectations.Where(x => x is HasTypeExpectation).Cast<HasTypeExpectation>(); if (hasTypeExpectations.Any(x => x.Type == expectation.Type)) return; _expectations.Add(expectation); }