public void Should_have_1_expecation_when_expecations_have_same_instance_for_does_not_have_and_has() { // Arrange var expectation1 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor")); var expectation2 = new HasInstanceExpectation(new RequireRolePolicy("Editor")); // 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_instances_for_DoesNotHaveInstanceExpectation() { // Arrange var expectation1 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor")); var expectation2 = new DoesNotHaveInstanceExpectation(new RequireRolePolicy("Editor", "Writer")); // Act _expectationGroup.ApplyExpectation(expectation1); _expectationGroup.ApplyExpectation(expectation2); // Assert Assert.That(_expectationGroup.Expectations.Count(), Is.EqualTo(2)); }
private void HandleDoesNotHaveInstanceExpectation(DoesNotHaveInstanceExpectation expectation) { var hasInstanceExpectations = _expectations.OfType <HasInstanceExpectation>().Where(x => x.Instance.Equals(expectation.Instance)); for (var i = 0; i < hasInstanceExpectations.Count(); i++) { var hasInstanceExpectation = hasInstanceExpectations.ElementAt(i); _expectations.Remove(hasInstanceExpectation); } var doesNotHaveTypeExpectations = _expectations.OfType <DoesNotHaveInstanceExpectation>(); if (doesNotHaveTypeExpectations.Any(x => x.Instance.Equals(expectation.Instance))) { return; } _expectations.Add(expectation); }
private ExpectationResult VerifyDoesNotHaveInstance(IPolicyContainer policyContainer, DoesNotHaveInstanceExpectation expectation) { if (expectation == null) { return(null); } if (policyContainer != null && policyContainer.HasPolicy(expectation.Instance)) { const string messageFormat = "An unexpected instance of the policy type \"{2}\" was found for controller \"{0}\", action \"{1}\"."; var expectedPolicyType = expectation.Instance.GetType().Name; var message = string.Format(messageFormat, policyContainer.ControllerName, policyContainer.ActionName, expectedPolicyType); return(_expectationViolationHandler.Handle(message)); } return(ExpectationResult.CreateSuccessResult()); }