public void AddError_CreatesAndAddsCorrectError()
        {
            var target    = new EmployeeVM();
            var validator = Mock <IValidator>();

            var message = "Test error message";
            var details = new Object();

            var args = CreateArgs(target, target, validator);

            args.AddError(message, details);

            var expectedError = new ValidationError(
                validator,
                ValidationTarget.ForError(
                    ValidationStep.ViewModel,
                    target,
                    null,
                    null
                    ),
                message,
                details
                );

            ValidationAssert.HasErrors(args.Result, ValidationAssert.FullErrorComparer, expectedError);
        }
        public void AddError_ArgsWithProperty_CreatesAndAddsCorrectError()
        {
            var item      = new EmployeeVM();
            var owner     = new EmployeeListVM(item);
            var validator = Mock <IValidator>();
            var step      = ValidationStep.Value;

            var message = "Test error message";
            var details = new Object();

            var args = CreateArgsWithProperty(owner, step, validator);

            args.AddError(item, message, details);

            var expectedError = new ValidationError(
                validator,
                ValidationTarget.ForError(
                    step,
                    item,
                    owner.GetValue(x => x.Employees),
                    EmployeeVM.ClassDescriptor.Name
                    ),
                message,
                details
                );

            ValidationAssert.HasErrors(args.Result, ValidationAssert.FullErrorComparer, expectedError);
        }
 public IValidationErrorTarget GetValidationTarget()
 {
     return(ValidationTarget.ForError(
                Step,
                TargetVM,
                TargetCollection,
                TargetProperty
                ));
 }
            public ValidationError For(IViewModel targetVM)
            {
                var target = ValidationTarget.ForError(
                    ValidationStep.ViewModel,
                    targetVM,
                    null,
                    null
                    );

                return(new ValidationError(NullValidator.Instance, target, _errorMessage));
            }
            public ValidationError For <T>(
                IViewModel <T> targetVM,
                Func <T, IVMPropertyDescriptor> targetPropertySelector
                ) where T : IVMDescriptor
            {
                var targetProperty = targetPropertySelector((T)targetVM.Descriptor);

                var target = ValidationTarget.ForError(
                    ValidationStep.ViewModel,
                    targetVM,
                    null,
                    targetProperty
                    );

                return(new ValidationError(NullValidator.Instance, target, _errorMessage));
            }
        protected static ValidationError CreateValidationError(
            string message      = "Validation error",
            IViewModel targetVM = null,
            IVMPropertyDescriptor targetProperty = null
            )
        {
            targetVM = targetVM ?? NullViewModel.Instance;
            var step = targetProperty != null ?
                       ValidationStep.Value :
                       ValidationStep.ViewModel;

            return(new ValidationError(
                       NullValidator.Instance,
                       ValidationTarget.ForError(step, targetVM, null, targetProperty),
                       message
                       ));
        }