public void SetUp()
        {
            theStep = new ValidationStep(typeof(string), typeof(ConfiguredValidationSource), new IValidationRule[] { new Rule1(), new Rule2() });

            theDescription = Description.For(theStep);
            theRuleList    = theDescription.BulletLists.Single();
        }
Beispiel #2
0
        public void ExecutionExtension_ValidationSummary()
        {
            string msg1 = "message1",
                   msg2 = "message2",
                   msg3 = "message3";

            var er = new ExecutionResult("ss", null);

            er.Add(new[]
            {
                ValidationStep.BuildValidationResponseStep(true, msg1),
                ValidationStep.BuildValidationResponseStep(false, msg2),
                ValidationStep.BuildValidationResponseStep(false, msg3)
            });
            var vs1 = er.ValidationSummary();

            vs1.Count().ShouldBe(3);
            vs1.Contains(msg1).ShouldBeTrue();
            vs1.Contains(msg2).ShouldBeTrue();
            vs1.Contains(msg3).ShouldBeTrue();

            var vs2 = er.ValidationSummary(true);

            vs2.Count().ShouldBe(1);
            vs2.Contains(msg1).ShouldBeTrue();

            var vs3 = er.ValidationSummary(false);

            vs3.Count().ShouldBe(2);
            vs3.Contains(msg2).ShouldBeTrue();
            vs3.Contains(msg3).ShouldBeTrue();
        }
Beispiel #3
0
        public void ExecutionExtension_AddValidationStep()
        {
            var er1 = new ExecutionResult("ss", null);

            er1.Add(ValidationStep.BuildValidationResponseStep(false, "message"));
            er1.ValidationSteps.Any().ShouldBeTrue();
        }
Beispiel #4
0
        // Token: 0x06001C34 RID: 7220 RVA: 0x00084970 File Offset: 0x00082B70
        internal override bool Validate(object value, ValidationStep validationStep)
        {
            if (value == Binding.DoNothing)
            {
                return(true);
            }
            if (value == DependencyProperty.UnsetValue)
            {
                base.SetStatus(BindingStatusInternal.UpdateSourceError);
                return(false);
            }
            bool result = base.Validate(value, validationStep);

            if (validationStep != ValidationStep.RawProposedValue)
            {
                object[] array = value as object[];
                int      num   = this.MutableBindingExpressions.Count;
                if (array.Length < num)
                {
                    num = array.Length;
                }
                for (int i = 0; i < num; i++)
                {
                    value = array[i];
                    if (value != DependencyProperty.UnsetValue && value != Binding.DoNothing && !this.MutableBindingExpressions[i].Validate(value, validationStep))
                    {
                        array[i] = DependencyProperty.UnsetValue;
                    }
                }
            }
            return(result);
        }
Beispiel #5
0
 public ValidationRequest(
     ValidationStep step,
     IViewModel vm
     )
     : this(step, Path.Empty.Prepend(vm))
 {
     Check.NotNull(vm, nameof(vm));
 }
        protected ValidationArgs(ValidationStep step, IValidator validator)
        {
            Check.NotNull(validator, nameof(validator));

            Step      = step;
            Validator = validator;
            Result    = ValidationResult.Valid;
        }
Beispiel #7
0
 public ValidationRequest(
     ValidationStep step,
     Path targetPath
     )
 {
     Check.NotNull(targetPath, nameof(targetPath));
     Step       = step;
     TargetPath = targetPath;
 }
Beispiel #8
0
 public CommitStage()
 {
     Name        = "1-Integration-Build-hosted";
     Artifacts   = new[] { new SourceRepository() };
     Validations = new ValidationStep[]
     {
         new PrivateBuild(),
         new ContinuousIntegrationBuild()
     };
 }
 public StagingStage()
 {
     Name        = "3-Promote to Staging";
     Artifacts   = new[] { new ReleasePackages() };
     Validations = new ValidationStep[]
     {
         new InPlaceUpgrade(),
         new SmokeTestSuite()
     };
 }
        /// <summary>
        /// Run validation rules for the given step
        /// <summary>
        internal override bool Validate(object value, ValidationStep validationStep)
        {
            BindingExpressionBase bindExpr = ActiveBindingExpression;

            if (bindExpr != null)
            {
                return(bindExpr.Validate(value, validationStep));
            }
            return(true);
        }
Beispiel #11
0
 public ValidationRequest(
     ValidationStep step,
     IViewModel vm,
     IVMPropertyDescriptor property
     )
     : this(step, Path.Empty.Prepend(property).Prepend(vm))
 {
     Check.NotNull(vm, nameof(vm));
     Check.NotNull(property, nameof(property));
 }
        /// <summary>
        /// Run validation rules for the given step, and inform the binding group
        /// <summary>
        internal override bool CheckValidationRules(BindingGroup bindingGroup, ValidationStep validationStep)
        {
            BindingExpressionBase bindExpr = ActiveBindingExpression;

            if (bindExpr != null)
            {
                return(bindExpr.CheckValidationRules(bindingGroup, validationStep));
            }
            return(true);
        }
        /// <summary>Performs validation checks on a value.</summary>
        /// <param name="value">The value from the binding target to check.</param>
        /// <param name="cultureInfo">The culture to use in this rule.</param>
        /// <param name="owner">The binding expression that uses the validation rule.</param>
        /// <returns>A <see cref="T:System.Windows.Controls.ValidationResult" /> object.</returns>
        // Token: 0x0600599F RID: 22943 RVA: 0x0018B870 File Offset: 0x00189A70
        public virtual ValidationResult Validate(object value, CultureInfo cultureInfo, BindingExpressionBase owner)
        {
            ValidationStep validationStep = this._validationStep;

            if (validationStep - ValidationStep.UpdatedValue <= 1)
            {
                value = owner;
            }
            return(this.Validate(value, cultureInfo));
        }
        public void finds_the_rules()
        {
            var r1 = new StubRule();
            var r2 = new StubRule();
            var r3 = new ClassFieldValidationRules();

            var src  = new ConfiguredValidationSource(new IValidationRule[] { r1, r2, r3 });
            var step = ValidationStep.FromSource(typeof(object), src);

            step.FindRules <StubRule>().ShouldHaveTheSameElementsAs(r1, r2);
        }
 public ProductionStage()
 {
     Name        = "3-Promote to Production";
     Artifacts   = new[] { new ReleasePackages() };
     Validations = new ValidationStep[]
     {
         new SuccessfulBackup(),
         new InPlaceUpgrade(),
         new SmokeTestSuite()
     };
 }
 public AcceptanceStage()
 {
     Name        = "2-Deploy to Test";
     Artifacts   = new[] { new ReleasePackages() };
     Validations = new ValidationStep[]
     {
         new SmokeTestSuite(),
         new AcceptanceTestSuite(),
         new SystemIntegrationTestSuite(),
         new CapacityTestSuite()
     };
 }
Beispiel #17
0
        public void ExecutionExtension_AddValidationStepCollection()
        {
            var er1 = new ExecutionResult("ss", null);

            er1.Add(new[]
            {
                ValidationStep.BuildValidationResponseStep(false, "message"),
                ValidationStep.BuildValidationResponseStep(false, "message"),
                ValidationStep.BuildValidationResponseStep(false, "message")
            });
            er1.ValidationSteps.Count.ShouldBe(3);
        }
Beispiel #18
0
 public void InvalidCollectionResults(
     ValidationStep step,
     IViewModel item,
     IVMPropertyDescriptor property
     )
 {
     _cachedCollectionResults.RemoveAll(res =>
                                        res.Target.Step == step &&
                                        res.Target.Property == property &&
                                        item.Kernel.OwnerCollections.Contains(res.Target.Collection)
                                        );
 }
Beispiel #19
0
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            StringBuilder buidler = new StringBuilder();

            Debug.WriteLine(buidler.Append("TraceValidationRule for '")
                            .Append(PropertyName)
                            .Append("' called. ValidationStep='")
                            .Append(ValidationStep.ToString())
                            .Append("'").ToString());

            return(ValidationResult.ValidResult);  // Don't stop the validation process by reporting an error.
        }
 public static IInstanceValidationTarget ForInstance(
     ValidationStep step,
     IViewModel vm,
     IVMPropertyDescriptor property = null
     )
 {
     Check.NotNull(vm, nameof(vm));
     return(new ValidationTarget(step)
     {
         VM = vm, Property = property
     });
 }
 public static ICollectionValidationTarget ForCollection(
     ValidationStep step,
     IVMCollection collection,
     IVMPropertyDescriptor property = null
     )
 {
     Check.NotNull(collection, nameof(collection));
     return(new ValidationTarget(step)
     {
         Collection = collection, Property = property
     });
 }
        public void SetUp()
        {
            theModel = new SimpleModel();

            r1 = MockRepository.GenerateStub<IValidationRule>();
            r2 = MockRepository.GenerateStub<IValidationRule>();
            theSource = typeof(ConfiguredValidationSource);

            theContext = ValidationContext.For(theModel);

            theStep = new ValidationStep(theModel.GetType(), theSource, new[] { r1, r2 });
        }
        public void SetUp()
        {
            theModel = new SimpleModel();

            r1        = MockRepository.GenerateStub <IValidationRule>();
            r2        = MockRepository.GenerateStub <IValidationRule>();
            theSource = typeof(ConfiguredValidationSource);

            theContext = ValidationContext.For(theModel);

            theStep = new ValidationStep(theModel.GetType(), theSource, new[] { r1, r2 });
        }
        public void PushValidatorBuildActions(
            IValidator validator,
            ValidationStep step
            )
        {
            PushGeneralBuildAction(
                BuildActionOrder.Validator,
                () => ActionArgs.Push(validator)
                );

            PushConditionBuildAction(
                BuildActionOrder.PredefinedConditions,
                new ValidationStepCondition(step)
                );
        }
Beispiel #25
0
        public PropertyValidationArgs(
            IValidator validator,
            ValidationStep step,
            TOwnerVM owner,
            TTargetVM target,
            IVMPropertyDescriptor <TValue> targetProperty
            )
            : base(step, validator, owner)
        {
            Check.NotNull(target, nameof(target));
            Check.NotNull(targetProperty, nameof(targetProperty));

            Target         = target;
            TargetProperty = targetProperty;
        }
Beispiel #26
0
        public ValidationResult GetResult(
            ValidationStep step,
            IViewModel target,
            IVMPropertyDescriptor targetProperty = null
            )
        {
            var t = ValidationTarget.ForInstance(step, target, targetProperty);

            var request = t.CreateValidationRequest();
            var result  = t.VM.ExecuteValidationRequest(request);

            var collectionResult = GetCollectionItemResults(t);

            return(ValidationResult.Join(result, collectionResult));
        }
        public static IValidationErrorTarget ForError(
            ValidationStep step,
            IViewModel vm,
            IVMCollection collection       = null,
            IVMPropertyDescriptor property = null
            )
        {
            Check.NotNull(vm, nameof(vm));

            return(new ValidationTarget(step)
            {
                VM = vm,
                Collection = collection,
                Property = property
            });
        }
Beispiel #28
0
        private void AssertStandardValidators(
            IVMDescriptor descriptor,
            ValidationStep step,
            PathDefinition targetPath,
            IValidator validator,
            Func <ValidatorConditionArgs <EmployeeVM, IViewModel <ProjectVMDescriptor> >, bool> condition1 = null,
            Func <ValidatorConditionArgs <EmployeeVM, IViewModel <ProjectVMDescriptor> >, bool> condition2 = null
            )
        {
            IValidator expectedValidator = validator;

            if (condition2 != null)
            {
                expectedValidator = new ConditionalValidator(
                    new DelegateValidatorCondition <EmployeeVM, IViewModel <ProjectVMDescriptor> >(condition2, 0),
                    expectedValidator
                    );
            }

            if (condition1 != null)
            {
                expectedValidator = new ConditionalValidator(
                    new DelegateValidatorCondition <EmployeeVM, IViewModel <ProjectVMDescriptor> >(condition1, 0),
                    expectedValidator
                    );
            }

            expectedValidator = new ConditionalValidator(
                new ValidationStepCondition(step),
                new ConditionalValidator(
                    new ValidationTargetCondition(targetPath),
                    expectedValidator
                    )
                );

            ValidatorExecutorBehavior expectedBehavior = new ValidatorExecutorBehavior();

            expectedBehavior.AddValidator(expectedValidator);

            Assert.AreEqual(
                expectedBehavior.ToString(),
                descriptor
                .Behaviors
                .GetNextBehavior <ValidatorExecutorBehavior>()
                .ToString()
                );
        }
        public void finds_the_rules_from_all_steps()
        {
            var r1 = new StubRule();
            var r2 = new StubRule();
            var r3 = new ClassFieldValidationRules();
            var r4 = new ClassFieldValidationRules();

            var src1 = new ConfiguredValidationSource(new IValidationRule[] { r1, r3 });
            var src2 = new ConfiguredValidationSource(new IValidationRule[] { r2, r4 });

            var step1 = ValidationStep.FromSource(typeof(object), src1);
            var step2 = ValidationStep.FromSource(typeof(object), src2);

            var plan = new ValidationPlan(typeof(object), new[] { step1, step2 });

            plan.FindRules <StubRule>().ShouldHaveTheSameElementsAs(r1, r2);
        }
        private static CollectionValidationArgs <IViewModel, EmployeeVM, string> CreateArgsWithProperty(
            EmployeeListVM owner,
            ValidationStep step  = ValidationStep.Value,
            IValidator validator = null
            )
        {
            validator = validator ?? Mock <IValidator>();

            var path = Path.Empty
                       .Append(owner)
                       .Append(owner.GetValue(x => x.Employees))
                       .Append(EmployeeVM.ClassDescriptor.Name);

            return(CollectionValidationArgs <IViewModel, EmployeeVM, string> .Create(
                       validator,
                       new ValidationRequest(step, path)
                       ));
        }
Beispiel #31
0
        public void ExecutionResult_Errors()
        {
            var er1 = new ExecutionResult("ss", null);

            er1.ExecutionResultSteps.Add(ExecutionResultStep.Build(ExecutionStatus.Passed, "message"));
            er1.HasErrors.ShouldBeFalse();
            er1.HasExecutionErrors.ShouldBeFalse();
            er1.HasValidationErrors.ShouldBeFalse();

            er1.ExecutionResultSteps.Add(ExecutionResultStep.Build(ExecutionStatus.Failed, "message"));
            er1.HasErrors.ShouldBeTrue();
            er1.HasExecutionErrors.ShouldBeTrue();
            er1.HasValidationErrors.ShouldBeFalse();

            var er2 = new ExecutionResult("ss", null);

            er2.ValidationSteps.Add(ValidationStep.BuildValidationResponseStep(false, "message"));
            er2.HasErrors.ShouldBeTrue();
            er2.HasExecutionErrors.ShouldBeFalse();
            er2.HasValidationErrors.ShouldBeTrue();
        }
        /// <summary>
        /// Run validation rules for the given step
        /// <summary>
        internal override bool Validate(object value, ValidationStep validationStep)
        {
            // run rules attached to this binding
            bool result = base.Validate(value, validationStep);

            if (validationStep == ValidationStep.UpdatedValue)
            {
                if (result && ParentBinding.ValidatesOnDataErrors)
                {
                    // remember the old validation error, if it came from the implicit DataError rule
                    ValidationError oldValidationError = GetValidationErrors(validationStep);
                    if (oldValidationError != null &&
                        oldValidationError.RuleInError != DataErrorValidationRule.Instance)
                    {
                        oldValidationError = null;
                    }

                    // run the DataError rule, even though it doesn't appear in the
                    // ValidationRules collection
                    ValidationError error = RunValidationRule(DataErrorValidationRule.Instance, this, GetCulture());

                    if (error != null)
                    {
                        UpdateValidationError(error);
                        result = false;
                    }
                    else if (oldValidationError != null)
                    {
                        // the implicit rule is now valid - clear the old error
                        UpdateValidationError(null);
                    }
                }
            }
            else if (validationStep == ValidationStep.CommittedValue)
            {
                if (result)
                {
                    NeedsValidation = false;
                }
            }

            return result;
        }
        /// <summary>
        /// Run validation rules for the given step, and inform the binding group
        /// <summary>
        internal override bool CheckValidationRules(BindingGroup bindingGroup, ValidationStep validationStep)
        {
            if (!NeedsValidation)
                return true;

            object value;
            switch (validationStep)
            {
                case ValidationStep.RawProposedValue:
                    value = GetRawProposedValue();
                    break;
                case ValidationStep.ConvertedProposedValue:
                    value = bindingGroup.GetValue(this);
                    break;
                case ValidationStep.UpdatedValue:
                case ValidationStep.CommittedValue:
                    value = this;
                    break;
                default:
                    throw new InvalidOperationException(SR.Get(SRID.ValidationRule_UnknownStep, validationStep, bindingGroup));
            }

            return Validate(value, validationStep);
        }
        // get all errors raised at the given step, in preparation for running
        // the rules at that step
        internal ValidationError GetValidationErrors(ValidationStep validationStep)
        {
            ValidationError validationError = BaseValidationError;
            if (validationError == null || validationError.RuleInError.ValidationStep != validationStep)
                return null;

            return validationError;
        }
Beispiel #35
0
 /// <summary>
 /// Initialize a new instance of ValidationRule with the given validation
 /// step and target-update behavior.
 /// </summary> 
 protected ValidationRule(ValidationStep validationStep, bool validatesOnTargetUpdated)
 { 
     _validationStep = validationStep; 
     _validatesOnTargetUpdated = validatesOnTargetUpdated;
 } 
        public void SetUp()
        {
            theStep = new ValidationStep(typeof(string), typeof(ConfiguredValidationSource), new IValidationRule[] { new Rule1(), new Rule2()  });

            theDescription = Description.For(theStep);
            theRuleList = theDescription.BulletLists.Single();
        }
 /// <summary> 
 /// Run validation rules for the given step, and inform the binding group
 /// <summary>
 internal abstract bool CheckValidationRules(BindingGroup bindingGroup, ValidationStep validationStep);
        // get all errors raised at the given step, in preparation for running
        // the rules at that step 
        internal ValidationError GetValidationErrors(ValidationStep validationStep) 
        {
            if (_validationError == null || _validationError.RuleInError.ValidationStep != validationStep) 
                return null;

            return _validationError;
        } 
 protected ValidationRule(ValidationStep validationStep, bool validatesOnTargetUpdated)
 {
 }
        /// <summary>
        /// Run validation rules for the given step
        /// <summary>
        internal virtual bool Validate(object value, ValidationStep validationStep) 
        {
            if (value == Binding.DoNothing) 
                return true; 

            if (value == DependencyProperty.UnsetValue) 
            {
                SetStatus(BindingStatus.UpdateSourceError);
                return false;
            } 

            // get old errors from this step - we're about to reevaluate those rules. 
            ValidationError oldValidationError = GetValidationErrors(validationStep); 

            // ignore an error from the implicit DataError rule - this is checked 
            // separately (in BindingExpression.Validate).  [Dev10 575988]
            if (oldValidationError != null &&
                oldValidationError.RuleInError == DataErrorValidationRule.Instance)
            { 
                oldValidationError = null;
            } 
 
            Collection<ValidationRule> validationRules = ParentBindingBase.ValidationRulesInternal;
 
            if (validationRules != null)
            {
                CultureInfo culture = GetCulture();
                switch (validationStep) 
                {
                    case ValidationStep.UpdatedValue: 
                    case ValidationStep.CommittedValue: 
                        // rules at these steps get passed the rule owner
                        value = this; 
                        break;
                }

                foreach (ValidationRule validationRule in validationRules) 
                {
                    if (validationRule.ValidationStep == validationStep) 
                    { 
                        ValidationResult validationResult = validationRule.Validate(value, culture);
 
                        if (!validationResult.IsValid)
                        {
                            if (TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.Update))
                            { 
                                TraceData.Trace(TraceEventType.Warning,
                                                    TraceData.ValidationRuleFailed( 
                                                        TraceData.Identify(this), 
                                                        TraceData.Identify(validationRule)));
                            } 

                            UpdateValidationError( new ValidationError(validationRule, this, validationResult.ErrorContent, null));
                            return false; // kenlai:
                        } 
                    }
                } 
            } 

            // this step is now valid - clear the old error (if any) 
            if (oldValidationError != null && oldValidationError == GetValidationErrors(validationStep))
            {
                UpdateValidationError(null);
            } 

            return true; 
        } 
 /// <summary>
 /// Run validation rules for the given step
 /// <summary>
 internal override bool Validate(object value, ValidationStep validationStep)
 {
     BindingExpressionBase bindExpr = ActiveBindingExpression;
     if (bindExpr != null)
     {
         return bindExpr.Validate(value, validationStep);
     }
     return true;
 }
Beispiel #42
0
 public KorValidation(ValidationStep validationStep, bool validatesOnTargetUpdated) : base(validationStep, validatesOnTargetUpdated) {
 }
 /// <summary>
 /// Run validation rules for the given step, and inform the binding group
 /// <summary>
 internal override bool CheckValidationRules(BindingGroup bindingGroup, ValidationStep validationStep)
 {
     BindingExpressionBase bindExpr = ActiveBindingExpression;
     if (bindExpr != null)
     {
         return bindExpr.CheckValidationRules(bindingGroup, validationStep);
     }
     return true;
 }
Beispiel #44
0
    /// <summary>
    /// Run validation rules for the given step
    /// <summary>
    internal override bool Validate(object value, ValidationStep validationStep)
    {
        if (value == Binding.DoNothing)
            return true;

        if (value == DependencyProperty.UnsetValue)
        {
            SetStatus(BindingStatusInternal.UpdateSourceError);
            return false;
        }

        // run rules attached to this multibinding
        bool result = base.Validate(value, validationStep);

        // run rules attached to the child bindings
        switch (validationStep)
        {
            case ValidationStep.RawProposedValue:
                // the child bindings don't get raw values until the Convert step
                break;

            default:
                object[] values = value as object[];
                int count = MutableBindingExpressions.Count;
                if (values.Length < count)
                    count = values.Length;

                for (int i=0; i<count; ++i)
                {
                    value = values[i];
                    if (value == DependencyProperty.UnsetValue)
                    {
                        // an unset value means the binding failed validation at an earlier step,
                        // typically at Raw step, evaluated during the MultiBinding's ConvertValue

                        //result = false;
                        // COMPAT: This should mean the MultiBinding as a whole fails validation, but
                        // in 3.5 this didn't happen.  Instead the process continued, writing back
                        // values to child bindings that succeeded, and simply not writing back
                        // to child bindings that didn't.
                    }
                    else if (value != Binding.DoNothing)
                    {
                        if (!MutableBindingExpressions[i].Validate(value, validationStep))
                        {
                            values[i] = DependencyProperty.UnsetValue;  // prevent writing an invalid value

                            //result = false;
                            // COMPAT: as above, preserve v3.5 behavior by not failing when a
                            // child binding fails to validate
                        }
                    }
                }
                break;
        }

        return result;
    }