public void SetUp()
 {
     _validationRuleBuilder        = new ValidationRuleBuilder();
     _discoveredType               = typeof(TestViewModel);
     _propertyInfoOfStringProperty = typeof(TestViewModel).GetProperty("Valid_Email");
     _propertyInfoOfIntProperty    = typeof(TestViewModel).GetProperty("Valid_Int");
 }
 public void SetUp()
 {
     _validationRuleBuilder = new ValidationRuleBuilder();
     _discoveredType = typeof(TestViewModel);
     _propertyInfoOfStringProperty = typeof(TestViewModel).GetProperty("Valid_Email");
     _propertyInfoOfIntProperty = typeof(TestViewModel).GetProperty("Valid_Int");
 }
Exemple #3
0
 public static Rule <TValue> Between <TValue>(
     this ValidationRuleBuilder <TValue> builder,
     TValue lowerBound,
     TValue upperBound)
     where TValue : IComparable <TValue>
 => new Rule <TValue>
 {
     LowerBound = lowerBound,
     UpperBound = upperBound
 };
        public ValidationResults Validate(ValidationResults validation)
        {
            var builder = new ValidationRuleBuilder <SampleClass>(validation);

            builder.Given(this)
            .When(self => self.Property3 == true)
            .Then("One Property Validation message.", nameof(Property3));

            builder.Given(this)
            .When(self => self.Property1 == true)
            .And(self => self.Property2 == true)
            .Then("Two Property Validation message.", nameof(Property1));

            return(validation);
        }
Exemple #5
0
            public Error Validate(Algorithm4Configuration value, Rule rule, ValidationContext context)
            {
                if (value.Phases == null)
                {
                    return(null);
                }

                var phasesNumber = value.PhasesNumber;
                var phaseKeys    = value.Phases.Keys;

                var phaseKeyRule = new ValidationRuleBuilder <IEnumerable <int> >()
                                   .Collection(b => b.Between(1, phasesNumber));

                var keysValidationResult = context.Engine.Validate <CollectionValidation.Rule <int>, IEnumerable <int>, CollectionValidation.Error>(phaseKeys.AsEnumerable(), phaseKeyRule);

                return(keysValidationResult.HasError()
                    ? new Error {
                    InvalidKeyIndices = keysValidationResult.Error.Violations.Keys
                }
                    : null);
            }