Exemplo n.º 1
0
 /// <summary>
 /// Specify on of the rule's conditions to be the ommision of a section that has a field with a given operation
 /// </summary>
 /// <param name="field"></param>
 /// <param name="values"></param>
 /// <returns></returns>
 public Validation SectionDoesNotExist(ValidationField field, List <string> values)
 {
     InitializeConditions();
     _rule.SelfValidation = true;
     _rule.ConditionOperations.Add(SectionDoesNotExistFieldOperationComparison(field, values));
     return(this);
 }
Exemplo n.º 2
0
        public ValidationOperation DoesNotContainsOperation(ValidationField validationField, List <string> containsValues)
        {
            var operation = ContainsOperation(validationField, containsValues);

            operation.Operand = ValidationOperand.NotIn;

            return(operation);
        }
Exemplo n.º 3
0
        public ValidationOperation NotRequiredOperation(ValidationField validationField)
        {
            var rule = RequiredOperation(validationField);

            rule.Operand = ValidationOperand.Not;

            return(rule);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Specify one off the rule's conditions to be a Contains Operation Type
        /// </summary>
        public Validation Contains(ValidationField field, List <string> containsValues)
        {
            InitializeConditions();

            _rule.SelfValidation = false;
            _rule.ConditionOperations.Add(ContainsOperation(field, containsValues));

            return(this);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Specify one off the rule's conditions to be a Required Operation Type
        /// </summary>
        public Validation Required(ValidationField field)
        {
            InitializeConditions();

            _rule.SelfValidation = false;
            _rule.ConditionOperations.Add(RequiredOperation(field));

            return(this);
        }
Exemplo n.º 6
0
        public ValidationOperation RequiredOperation(ValidationField validationField)
        {
            var operation = new ValidationOperation
            {
                FieldPath     = validationField.FieldPath,
                SectionName   = validationField.SectionName,
                OperationType = ValidationOperationType.Required,
                ControlType   = validationField.ControlType,
            };

            return(operation);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Specify one off the rule's conditions to be a Does Not Contains Operation Type
        /// </summary>
        public Validation DoesNotContain(ValidationField field, List <string> containsValues)
        {
            InitializeConditions();

            _rule.SelfValidation = false;
            var operation = ContainsOperation(field, containsValues);

            operation.Operand = ValidationOperand.NotIn;

            _rule.ConditionOperations.Add(operation);

            return(this);
        }
Exemplo n.º 8
0
        public List <ValidationRule> BuildComparisonConditionValidationRule(ValidationMessage message,
                                                                            ValidationField field1, ValidationField field2, string operand, List <ValidationOperation> conditions)
        {
            var rules = BuildComparisonValidationRule(message, field1, field2, operand);

            foreach (var rule in rules)
            {
                rule.ValidationReBroadcast = true;
                rule.ConditionOperations   = conditions;
            }

            return(rules);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Specify one off the rule's conditions to be a Not Required Operation Type
        /// </summary>
        public Validation NotRequired(ValidationField field)
        {
            InitializeConditions();

            _rule.SelfValidation = false;
            var operation = RequiredOperation(field);

            operation.Operand = ValidationOperand.Not;

            _rule.ConditionOperations.Add(operation);

            return(this);
        }
Exemplo n.º 10
0
        public ValidationOperation ContainsOperation(ValidationField validationField, List <string> containsValues)
        {
            var operation = new ValidationOperation
            {
                FieldPath      = validationField.FieldPath,
                SectionName    = validationField.SectionName,
                OperationType  = ValidationOperationType.Contains,
                ContainsValues = containsValues,
                Operand        = ValidationOperand.In,
                ControlType    = validationField.ControlType,
            };

            return(operation);
        }
Exemplo n.º 11
0
        public ValidationOperation UniqueOperation(ValidationField validationField)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = validationField.FieldPath,
                FieldType        = (int)validationField.FieldType,
                SectionName      = validationField.SectionName,
                ControlType      = validationField.ControlType,
                OperationType    = ValidationOperationType.Unique,
                PropertyOverride = validationField.PropertyOverride
            };

            return(operation);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Constructs a Required Operation for a field
        /// </summary>
        private ValidationOperation RequiredOperation(ValidationField validationField)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = validationField.FieldPath,
                FieldType        = (int)validationField.FieldType, // todo: change property type to FieldType
                SectionName      = validationField.SectionName,
                OperationType    = ValidationOperationType.Required,
                ControlType      = validationField.ControlType,
                PropertyOverride = validationField.PropertyOverride
            };

            return(operation);
        }
Exemplo n.º 13
0
        public ValidationOperation CompareToCurrentDateOperation(ValidationField validationField)
        {
            var operation = new ValidationOperation
            {
                FieldPath     = validationField.FieldPath,
                SectionName   = validationField.SectionName,
                OperationType = ValidationOperationType.CompareToCurrentDate,
                ControlType   = validationField.ControlType,
                Operand       = ValidationOperand.LessThanEqual,
                FieldMask     = validationField.Mask,
                CompareToMask = validationField.CompareToMask
            };

            return(operation);
        }
Exemplo n.º 14
0
        public Validation(Guid id, ValidationMessage validationMessage, ValidationField validationField)
        {
            _rule = new ValidationRule
            {
                Id                = id,
                ValidationId      = validationMessage.Message,
                Message           = validationMessage.Message,
                FieldPath         = validationField.FieldPath,
                SectionName       = validationField.SectionName,
                TargetPath        = validationMessage.TargetPath,
                AlwaysShowMessage = validationMessage.AlwaysShowMessage,
            };

            _operationField = validationField;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Constructs a Value Count Operaration for a field
        /// </summary>
        public ValidationOperation ValueCountOperation(ValidationField validationField, string limit)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = validationField.FieldPath,
                FieldType        = (int)validationField.FieldType,
                SectionName      = validationField.SectionName,
                OperationType    = ValidationOperationType.ValueCount,
                CompareValue     = limit,
                ControlType      = validationField.ControlType,
                PropertyOverride = validationField.PropertyOverride
            };

            return(operation);
        }
Exemplo n.º 16
0
        public ValidationOperation ComparisonOperation(ValidationField validationField, string operand)
        {
            var operation = new ValidationOperation
            {
                FieldPath     = validationField.FieldPath,
                SectionName   = validationField.SectionName,
                OperationType = ValidationOperationType.Comparison,
                ControlType   = validationField.ControlType,
                Operand       = operand,
                FieldMask     = validationField.Mask,
                CompareToMask = validationField.CompareToMask
            };

            return(operation);
        }
Exemplo n.º 17
0
        public ValidationOperation MaxRecordCountOperation(ValidationField validationField, string count)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = validationField.FieldPath,
                SectionName      = validationField.SectionName,
                ControlType      = validationField.ControlType,
                CompareValue     = count,
                FieldType        = (int)validationField.FieldType,
                OperationType    = ValidationOperationType.MaxRecordCount,
                PropertyOverride = validationField.PropertyOverride
            };

            return(operation);
        }
Exemplo n.º 18
0
        public ValidationRule BuildContainsValidationRule(ValidationMessage message, ValidationField field, List <string> containsValues)
        {
            var containsRule = new ValidationRule(RuleSource)
            {
                Id             = Guid.NewGuid(),
                ValidationId   = message.Message,
                Message        = message.Message,
                FieldPath      = field.FieldPath,
                SectionName    = field.SectionName,
                SelfValidation = true,
                TargetPath     = message.TargetPath,
                Operation      = ContainsOperation(field, containsValues),
            };

            return(containsRule);
        }
Exemplo n.º 19
0
        public ValidationRule BroadcastOnlyRule(ValidationMessage message, ValidationField field)
        {
            var validationRule = new ValidationRule(RuleSource)
            {
                Id                    = Guid.NewGuid(),
                ValidationId          = message.Message,
                Message               = message.Message,
                FieldPath             = field.FieldPath,
                SectionName           = field.SectionName,
                TargetPath            = message.TargetPath,
                SelfValidation        = false,
                ValidationReBroadcast = true,
            };

            return(validationRule);
        }
Exemplo n.º 20
0
        public ValidationRule BuildRequiredValidationRule(ValidationMessage message, ValidationField field)
        {
            var requiredRule = new ValidationRule(RuleSource)
            {
                Id             = Guid.NewGuid(),
                ValidationId   = message.Message,
                Message        = message.Message,
                FieldPath      = field.FieldPath,
                SectionName    = field.SectionName,
                SelfValidation = true,
                TargetPath     = message.TargetPath,
                Operation      = RequiredOperation(field),
            };

            return(requiredRule);
        }
Exemplo n.º 21
0
        public ValidationRule BuildRegularExpressionRule(ValidationMessage message, ValidationField field, string operand)
        {
            var compareToCurrentDateRule = new ValidationRule(RuleSource)
            {
                Id             = Guid.NewGuid(),
                ValidationId   = message.Message,
                Message        = message.Message,
                FieldPath      = field.FieldPath,
                SectionName    = field.SectionName,
                SelfValidation = true,
                TargetPath     = message.TargetPath,
                Operation      = RegularExpressionOperation(field, operand),
            };

            return(compareToCurrentDateRule);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Constructs a Comparison Operation for a field
        /// </summary>
        private ValidationOperation ComparisonOperation(ValidationField field, string operand)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = field.FieldPath,
                FieldType        = (int)field.FieldType,
                SectionName      = field.SectionName,
                OperationType    = ValidationOperationType.Comparison,
                ContainsValues   = null,
                Operand          = operand,
                ControlType      = field.ControlType,
                PropertyOverride = field.PropertyOverride
            };

            return(operation);
        }
Exemplo n.º 23
0
        private ValidationOperation RelatedOffenseContainsOperation(ValidationField offenseField, List <string> containsValues)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = offenseField.FieldPath,
                FieldType        = (int)offenseField.FieldType,
                SectionName      = offenseField.SectionName,
                OperationType    = ValidationOperationType.RelatedOffenseContains,
                ContainsValues   = containsValues,
                Operand          = ValidationOperand.In,
                ControlType      = offenseField.ControlType,
                PropertyOverride = offenseField.PropertyOverride
            };

            return(operation);
        }
Exemplo n.º 24
0
        private ValidationOperation RegularExpressionOperation(ValidationField field, string expression)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = field.FieldPath,
                FieldType        = (int)field.FieldType,
                SectionName      = field.SectionName,
                OperationType    = ValidationOperationType.RegularExpression,
                ControlType      = field.ControlType,
                Operand          = expression,
                FieldMask        = field.Mask,
                CompareToMask    = field.CompareToMask,
                PropertyOverride = field.PropertyOverride
            };

            return(operation);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Constructs a Compare to Current Date Operation for a field
        /// </summary>
        private ValidationOperation CompareToCurrentDateOperation(ValidationField field)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = field.FieldPath,
                FieldType        = (int)field.FieldType,
                SectionName      = field.SectionName,
                OperationType    = ValidationOperationType.CompareToCurrentDate,
                ControlType      = field.ControlType,
                Operand          = ValidationOperand.LessThanEqual,
                FieldMask        = field.Mask,
                CompareToMask    = field.CompareToMask,
                PropertyOverride = field.PropertyOverride
            };

            return(operation);
        }
Exemplo n.º 26
0
        public void CreateAssociatedRule()
        {
            //arrange
            var validationField = new AdminValidation.ValidationField();

            validationField.SectionName = "Section";
            var rule = new ValidationRule();

            rule.SelfValidation = true;

            //action
            var validationRule = AdminValidation.Validation.CreateAssociatedRule(validationField, rule);

            //assertion
            validationRule.Should().NotBeNull();
            validationRule.Should().BeOfType(typeof(ValidationRule));
            validationRule.SectionName.Should().Be(validationField.SectionName);
            validationRule.SelfValidation.Should().BeTrue();
        }
Exemplo n.º 27
0
        public Validation CompareVictimFieldToOffender(ValidationField field, string operation)
        {
            _rule.SelfValidation = true;

            _rule.Operation = new ValidationOperation
            {
                FieldPath        = field.FieldPath,
                FieldType        = (int)field.FieldType,
                SectionName      = field.SectionName,
                OperationType    = ValidationOperationType.CompareVictimFieldToOffender,
                ControlType      = field.ControlType,
                PropertyOverride = field.PropertyOverride,
                Operand          = operation,
                FieldMask        = field.Mask,
                CompareToMask    = field.CompareToMask
            };

            return(this);
        }
Exemplo n.º 28
0
        private ValidationOperation RangeOperation(ValidationField field, string lowerBound, string upperBound)
        {
            var operation = new ValidationOperation
            {
                FieldPath        = field.FieldPath,
                FieldType        = (int)field.FieldType,
                SectionName      = field.SectionName,
                OperationType    = ValidationOperationType.Range,
                ControlType      = field.ControlType,
                PropertyOverride = field.PropertyOverride,
                Operand          = null,
                FieldMask        = field.Mask,
                CompareToMask    = field.CompareToMask,
                LowerBound       = lowerBound,
                UpperBound       = upperBound
            };

            return(operation);
        }
Exemplo n.º 29
0
        public Validation RelatedOffenseContains(ValidationField offenseField, List <string> containsValues)
        {
            var relatedOffenseContains = RelatedOffenseContainsOperation(offenseField, containsValues);

            if (_withConditions)
            {
                if (_rule.ConditionOperations == null)
                {
                    _rule.ConditionOperations = new List <ValidationOperation>();
                }

                _rule.ConditionOperations.Add(relatedOffenseContains);
            }
            else
            {
                _rule.Operation = relatedOffenseContains;
            }
            return(this);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Create a new Validation Rule for an associated field based off of an existing rule
        /// </summary>
        public static ValidationRule CreateAssociatedRule(ValidationField associatedField, ValidationRule sourceRule)
        {
            var rule = new ValidationRule
            {
                Id                    = Guid.NewGuid(),
                ValidationId          = sourceRule.ValidationId,
                Message               = sourceRule.Message,
                FieldPath             = associatedField.FieldPath,
                SectionName           = associatedField.SectionName,
                TargetPath            = sourceRule.TargetPath,
                AlwaysShowMessage     = sourceRule.AlwaysShowMessage,
                SelfValidation        = sourceRule.SelfValidation,
                RuleSource            = sourceRule.RuleSource,
                Operation             = sourceRule.Operation,
                ConditionOperations   = sourceRule.ConditionOperations,
                ValidationReBroadcast = sourceRule.ValidationReBroadcast,
                RuleImplementation    = sourceRule.RuleImplementation,
                ConditionOperator     = sourceRule.ConditionOperator,
            };

            return(rule);
        }