public static ValidatorResultSetup Succeeding(ValidatorInvocation invocation)
 {
     return(new ValidatorResultSetup {
         Invocation = invocation,
         Result = ValidationResult.Valid
     });
 }
            public override bool Equals(object obj)
            {
                ValidatorInvocation other = obj as ValidatorInvocation;

                return
                    (other != null &&
                     Type == other.Type &&
                     Owner == other.Owner &&
                     TargetVM == other.TargetVM &&
                     TargetCollection == other.TargetCollection &&
                     TargetProperty == other.TargetProperty &&
                     ValidatorKey == other.ValidatorKey);
            }
            public static ValidatorResultSetup Failing(ValidatorInvocation invocation, string errorDetails)
            {
                var error = new ValidationError(
                    NullValidator.Instance,
                    invocation.GetValidationTarget(),
                    invocation.ToString(errorDetails)
                    );

                return(new ValidatorResultSetup {
                    Invocation = invocation,
                    Result = new ValidationResult(error)
                });
            }
        protected void SetFailedResult(ValidatorInvocation target, string errorDetails)
        {
            var stateBefore = GetState();

            SetupFailingValidator(target, errorDetails);
            if (target.TargetProperty != null)
            {
                Revalidator.RevalidatePropertyValidations(
                    target.TargetVM,
                    target.TargetProperty,
                    ValidationScope.Self
                    );
            }
            else
            {
                Revalidator.RevalidateViewModelValidations(target.TargetVM);
            }

            stateBefore.RestoreToState();
        }
        protected virtual void PerformValidation(
            Action <string> addValidationErrorAction,
            ValidatorType type,
            IViewModel owner,
            IViewModel targetVM,
            object validatorKey,
            IVMPropertyDescriptor targetProperty = null
            )
        {
            var invocation = new ValidatorInvocation(type, owner, targetVM, null, targetProperty, validatorKey);

            var errors = ValidatorSetups
                         .Where(x => x.Invocation.Equals(invocation))
                         .SelectMany(x => x.Result.Errors);

            errors.ForEach(x => addValidationErrorAction(x.Message));

            ActualInvocations.Add(
                new ValidatorInvocation(type, owner, targetVM, null, targetProperty, validatorKey)
                );
        }
        protected virtual void PerformCollectionValidation <TItemVM>(
            Action <TItemVM, string, object> addValidationErrorAction,
            ValidatorType type,
            IViewModel owner,
            IVMCollectionBase <TItemVM> targetCollection,
            object validatorKey,
            IVMPropertyDescriptor targetProperty = null
            ) where TItemVM : IViewModel
        {
            foreach (TItemVM item in targetCollection)
            {
                var invocation = new ValidatorInvocation(type, owner, item, null, targetProperty, validatorKey);

                var errors = ValidatorSetups
                             .Where(x => x.Invocation.Equals(invocation))
                             .SelectMany(x => x.Result.Errors);

                errors.ForEach(x => addValidationErrorAction(item, x.Message, x.Details));
            }

            ActualInvocations.Add(
                new ValidatorInvocation(type, owner, null, targetCollection, targetProperty, validatorKey)
                );
        }
 protected void ExpectInvocation(ValidatorInvocation invocation)
 {
     ExpectedInvocations.Add(invocation);
 }
 protected void SetupSucceedingValidator(ValidatorInvocation forInvocation)
 {
     ValidatorSetups.Add(ValidatorResultSetup.Succeeding(forInvocation));
 }
 protected void SetupFailingValidator(ValidatorInvocation forInvocation, string errorDetails)
 {
     ValidatorSetups.Add(ValidatorResultSetup.Failing(forInvocation, errorDetails));
 }