Exemplo n.º 1
0
        public void Should_throw_when_factory_method_is_null()
        {
            // Arrange
            var expression = new ViolationHandlerExpression(new ViolationConfigurationExpression(new Conventions()), x => true);

            // Act & assert
            Assert.Throws <ArgumentNullException>(() => expression.IsHandledBy <DefaultPolicyViolationHandler>(null));
        }
Exemplo n.º 2
0
        public void Should_add_convention_for_predicate_to_instance()
        {
            // Arrange
            var conventions = new Conventions();
            var expression  = new ViolationHandlerExpression <IgnorePolicy>(new ViolationConfigurationExpression(conventions));

            // Act
            expression.IsHandledBy(() => new DefaultPolicyViolationHandler());

            // Assert
            Assert.That(conventions.Single(), Is.InstanceOf <PolicyTypeToPolicyViolationHandlerInstanceConvention <IgnorePolicy, DefaultPolicyViolationHandler> >());
        }
Exemplo n.º 3
0
        public void Should_add_convention_for_predicate_to_instance()
        {
            // Arrange
            Func <PolicyResult, bool> expectedPredicate = x => true;
            var conventions = new Conventions();
            var expression  = new ViolationHandlerExpression(new ViolationConfigurationExpression(conventions), expectedPredicate);

            // Act
            expression.IsHandledBy(() => new DefaultPolicyViolationHandler());

            // Assert
            Assert.That(conventions.Single().As <PredicateToPolicyViolationHandlerInstanceConvention <DefaultPolicyViolationHandler> >().Predicate, Is.EqualTo(expectedPredicate));
        }
        public void Should_add_convention_for_predicate_to_type()
        {
            // Arrange
            Func<PolicyResult, bool> expectedPredicate = x => true;
            var conventions = new Conventions();
            var expression = new ViolationHandlerExpression(new ViolationConfigurationExpression(conventions), expectedPredicate);

            // Act
            expression.IsHandledBy<DefaultPolicyViolationHandler>();

            // Assert
            Assert.That(conventions.Single().As<PredicateToPolicyViolationHandlerTypeConvention<DefaultPolicyViolationHandler>>().Predicate, Is.EqualTo(expectedPredicate));
        }
        public void Should_throw_when_factory_method_is_null()
        {
            // Arrange
            var expression = new ViolationHandlerExpression<IgnorePolicy>(new ViolationConfigurationExpression(new Conventions()));

            // Act & assert
            Assert.Throws<ArgumentNullException>(() => expression.IsHandledBy<DefaultPolicyViolationHandler>(null));
        }
        public void Should_add_convention_for_predicate_to_type()
        {
            // Arrange
            var conventions = new Conventions();
            var expression = new ViolationHandlerExpression<IgnorePolicy>(new ViolationConfigurationExpression(conventions));

            // Act
            expression.IsHandledBy<DefaultPolicyViolationHandler>();

            // Assert
            Assert.That(conventions.Single(), Is.InstanceOf<PolicyTypeToPolicyViolationHandlerTypeConvention<IgnorePolicy, DefaultPolicyViolationHandler>>());
        }