Beispiel #1
0
        public void Should_build_expectation_groups_and_verify_expectations()
        {
            // Arrange
            var configuration     = FluentSecurityFactory.CreateSecurityConfiguration();
            var expectationGroups = new List <ExpectationGroup>();

            var builder  = new Mock <IExpectationGroupBuilder>();
            var verifyer = new Mock <IExpectationVerifyer>();

            builder.Setup(x => x.Build(It.IsAny <IEnumerable <ExpectationExpression> >())).Returns(expectationGroups).AtMostOnce();
            verifyer.Setup(x => x.VerifyExpectationsOf(expectationGroups)).Returns(new List <ExpectationResult>()).AtMostOnce();

            var policyExpectations = new PolicyExpectations();

            policyExpectations.SetExpectationGroupBuilder(builder.Object);
            policyExpectations.ConstructExpectationVerifyerUsing((c, h) => verifyer.Object);
            policyExpectations.For <SampleController>();
            policyExpectations.For <AdminController>(x => x.Login());

            // Act
            policyExpectations.VerifyAll(configuration);

            // Assert
            builder.VerifyAll();
            verifyer.VerifyAll();
        }
Beispiel #2
0
        public void Should_have_expectation_verifyer_provider()
        {
            var configuration = FluentSecurityFactory.CreateEmptySecurityConfiguration();
            var handler       = _policyExpectations.ExpectationViolationHandler;

            Assert.That(_policyExpectations.ExpectationVerifyerProvider(configuration, handler).GetType(), Is.EqualTo(typeof(ExpectationVerifyer)));
        }
        public void Should_not_throw()
        {
            ISecurityConfiguration securityConfiguration = FluentSecurityFactory.CreateSecurityConfiguration();

            Assert.DoesNotThrow(() =>
                                securityConfiguration.Verify <AdminController>(expectations => { })
                                );
        }
        public void Should_throw_when_expectations_are_null()
        {
            ISecurityConfiguration securityConfiguration = FluentSecurityFactory.CreateSecurityConfigurationWithTwoExpectations();

            Assert.Throws <ArgumentNullException>(() =>
                                                  securityConfiguration.Verify <AdminController>(null)
                                                  );
        }
Beispiel #5
0
        public void Should_throw_when_expectation_groups_is_null()
        {
            // Arrange
            var configuration = FluentSecurityFactory.CreateSecurityConfiguration();

            var expectationViolationHandler = new Mock <IExpectationViolationHandler>();

            expectationViolationHandler.Setup(x => x.Handle(It.IsAny <string>())).Returns(ExpectationResult.CreateSuccessResult);

            var expectationVerifyer = new ExpectationVerifyer(configuration, expectationViolationHandler.Object);
            IEnumerable <ExpectationGroup> expectationGroups = null;

            // Act & assert
            Assert.Throws <ArgumentNullException>(() => expectationVerifyer.VerifyExpectationsOf(expectationGroups));
        }
        public void Should_verify_expectations()
        {
            ISecurityConfiguration securityConfiguration = FluentSecurityFactory.CreateSecurityConfiguration();

            var results = securityConfiguration.Verify <AdminController>(expectations =>
            {
                expectations.Expect().Has <DenyAnonymousAccessPolicy>();
                expectations.Expect(x => x.Login()).DoesNotHave <DenyAnonymousAccessPolicy>().Has <DenyAuthenticatedAccessPolicy>();
                expectations.Expect(x => x.NewUser())
                .DoesNotHave <DenyAnonymousAccessPolicy>()
                .DoesNotHave <RequireRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserViewer))
                .Has <RequireRolePolicy>(p => p.RolesRequired.Contains(UserRole.UserEditor));
            });

            Assert.That(results.All(x => x.ExpectationsMet), results.ErrorMessages());
        }
Beispiel #7
0
        public void Should_fail_11_times_and_return_14_results()
        {
            // Arrange
            var configuration = FluentSecurityFactory.CreateEmptySecurityConfiguration();

            var expectationViolationHandler = new Mock <IExpectationViolationHandler>();

            expectationViolationHandler.Setup(x => x.Handle(It.IsAny <string>())).Returns(ExpectationResult.CreateSuccessResult);

            var expectationVerifyer = new ExpectationVerifyer(configuration, expectationViolationHandler.Object);
            var expectationGroups   = FluentSecurityFactory.CreateExpectationsGroups();

            // Act
            var expectationResults = expectationVerifyer.VerifyExpectationsOf(expectationGroups);

            // Assert
            expectationViolationHandler.Verify(x => x.Handle(It.IsAny <string>()), Times.Exactly(11));
            Assert.That(expectationResults.Count(), Is.EqualTo(15));
        }
Beispiel #8
0
        public void Should_fail_once_with_predicate_description_in_result_message()
        {
            // Arrange
            var configuration = FluentSecurityFactory.CreateSecurityConfiguration();

            var expectationViolationHandler = new DefaultExpectationViolationHandler();
            var expectationVerifyer         = new ExpectationVerifyer(configuration, expectationViolationHandler);
            var policyExpectations          = new PolicyExpectations();

            policyExpectations.For <AdminController>(x => x.Login()).Has <DelegatePolicy>(p => p.Name == "LoginPolicy");

            // Act
            var expectationResults = expectationVerifyer.VerifyExpectationsOf(policyExpectations.ExpectationGroups);

            // Assert
            Assert.That(expectationResults.Count(), Is.EqualTo(1));
            Assert.That(expectationResults.First().ExpectationsMet, Is.False);
            Assert.That(expectationResults.First().Message, Is.EqualTo("Expected policy of type \"FluentSecurity.Policy.DelegatePolicy\" for controller \"FluentSecurity.TestHelper.Specification.TestData.AdminController\", action \"Login\".\r\n\t\tPredicate: p => (p.Name == \"LoginPolicy\")"));
        }