Beispiel #1
0
        public void Create_MemberInfoIsNoPropertyInfo_ExceptionIsThrown()
        {
            var dummyExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.Dummy());

            Assert.Throws <InvalidOperationException> (
                () => RemovingComponentPropertyRule.Create(dummyExpression, typeof(CustomerValidationCollector1)),
                "An 'RemovingComponentPropertyRule' can only created for property members.");
        }
Beispiel #2
0
        public void SetUp()
        {
            _property = PropertyInfoAdapter.Create(typeof(Customer).GetProperty("UserName"));

            _userNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.UserName);
            _lastNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.LastName);

            _removingComponentPropertyRule = RemovingComponentPropertyRule.Create(_userNameExpression, typeof(RemovingComponentPropertyRuleTest));
        }
Beispiel #3
0
        /// <inheritdoc />
        public IRemovingComponentRuleBuilderOptions <TValidatedType, TProperty> RemoveRule <TProperty> (
            Expression <Func <TValidatedType, TProperty> > propertySelector)
        {
            ArgumentUtility.CheckNotNull("propertySelector", propertySelector);

            var componentPropertyRule = RemovingComponentPropertyRule.Create(propertySelector, GetType());

            _removedPropertyRules.Add(componentPropertyRule);

            return(new RemovingComponentRuleBuilder <TValidatedType, TProperty> (componentPropertyRule));
        }
        public void SetUp()
        {
            _notEmptyValidator      = new NotEmptyValidator(null);
            _notNullValidator       = new NotNullValidator();
            _notEqualValidator      = new NotEqualValidator("test");
            _maximumLengthValidator = new MaximumLengthValidator(30);
            _minimumLengthValidator = new MinimumLengthValidator(5);

            _componenValidationCollectorStub1 = MockRepository.GenerateStub <IComponentValidationCollector>();
            _componenValidationCollectorStub2 = MockRepository.GenerateStub <IComponentValidationCollector>();
            _componenValidationCollectorStub3 = MockRepository.GenerateStub <IComponentValidationCollector>();

            _firstNameExpression = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.FirstName);
            _lastNameExpression  = ExpressionHelper.GetTypedMemberExpression <Customer, string> (c => c.LastName);

            _addingPropertyRule1 = AddingComponentPropertyRule.Create(_firstNameExpression, _componenValidationCollectorStub1.GetType());
            _addingPropertyRule1.RegisterValidator(_notEmptyValidator);
            _addingPropertyRule1.RegisterValidator(_notNullValidator);
            _addingPropertyRule1.RegisterValidator(_notEqualValidator);

            _addingPropertyRule2 = AddingComponentPropertyRule.Create(_lastNameExpression, _componenValidationCollectorStub2.GetType());
            _addingPropertyRule2.RegisterValidator(_maximumLengthValidator);

            _addingPropertyRule3 = AddingComponentPropertyRule.Create(_lastNameExpression, _componenValidationCollectorStub2.GetType());
            _addingPropertyRule3.RegisterValidator(_minimumLengthValidator);

            _addingPropertyRule4 = AddingComponentPropertyRule.Create(_lastNameExpression, _componenValidationCollectorStub2.GetType());
            _addingPropertyRule4.RegisterValidator(_notNullValidator);

            _removingPropertyRule1 = RemovingComponentPropertyRule.Create(_firstNameExpression, typeof(CustomerValidationCollector1));
            _removingPropertyRule1.RegisterValidator(typeof(NotEmptyValidator));

            _removingPropertyRule2 = RemovingComponentPropertyRule.Create(_firstNameExpression, typeof(CustomerValidationCollector1));
            _removingPropertyRule2.RegisterValidator(typeof(NotNullValidator), _componenValidationCollectorStub1.GetType());

            _removingPropertyRule3 = RemovingComponentPropertyRule.Create(_firstNameExpression, typeof(CustomerValidationCollector1));
            _removingPropertyRule3.RegisterValidator(typeof(NotNullValidator), typeof(string)); //Unknow collector type!

            _removingPropertyRule4 = RemovingComponentPropertyRule.Create(_lastNameExpression, typeof(CustomerValidationCollector1));
            _removingPropertyRule4.RegisterValidator(typeof(MaximumLengthValidator));

            _propertyValidatorExtractorFactoryMock = MockRepository.GenerateStrictMock <IPropertyValidatorExtractorFactory>();
            _propertyValidatorExtractorMock        = MockRepository.GenerateStrictMock <IPropertyValidatorExtractor>();

            _merger = new OrderPrecedenceValidationCollectorMerger(_propertyValidatorExtractorFactoryMock);
        }