public void Merge(IValidationSummary summary)
 {
     foreach (var result in summary.ValidationResults)
     {
         AddResult(result);
     }
 }
Exemple #2
0
            protected override void Validate(IValidationSummary summary, Person item)
            {
                if (item.Name == "Taylor" && item.Firstname == "Tim")
                {
                    summary.AddResult(new ValidationResult(Severity.Error, "Tim Taylor is not alowed"));
                }

                base.Validate(summary, item);
            }
Exemple #3
0
            protected override void Validate(IValidationSummary summary, TestClass item)
            {
                if (item.Index < 1)
                {
                    summary.AddResult(new ValidationResult(Severity.Error, "Index is smaller than 1"));
                }

                base.Validate(summary, item);
            }
            public void ViewModelBaseNoErrorsTest()
            {
                var personViewModel = new PersonViewModel {
                    PersonFirstName = "Igr Alexánder", PersonLastName = "Fernández Saúco"
                };

                personViewModel.Validate();

                IValidationSummary validationSummary = personViewModel.ValidationContext.GetValidationSummary("Person");

                Assert.IsFalse(validationSummary.HasErrors);
                Assert.IsFalse(validationSummary.HasWarnings);
            }
            public void ModelBaseWithFieldValidationTest()
            {
                var personViewModel = new PersonViewModelWithModel {
                    Person = new Person {
                        FirstName = "Igr Alexánder", LastName = string.Empty
                    }
                };

                // I have to add this call here
                personViewModel.Validate();

                IValidationSummary validationSummary = personViewModel.ValidationContext.GetValidationSummary("Person");

                Assert.IsTrue(validationSummary.HasErrors);
            }
Exemple #6
0
        /// <summary>
        /// Creates a new <see cref="Command{TExecuteParameter}"/> that automatically determines whether it can be executed. It does this
        /// by checking the right validation summary, which should be in a property..
        /// </summary>
        /// <typeparam name="TExecuteParameter">The type of the execute parameter.</typeparam>
        /// <param name="execute">The action to execute when the command is being invoked.</param>
        /// <param name="validationSummaryPropertyExpression">The validation summary property expression.</param>
        /// <param name="tag">The tag for the command.</param>
        /// <returns>The created command.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="execute"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="validationSummaryPropertyExpression"/> is <c>null</c>.</exception>
        public static Command <TExecuteParameter> CreateCommand <TExecuteParameter>(Action <TExecuteParameter> execute, Expression <Func <IValidationSummary> > validationSummaryPropertyExpression, object tag = null)
        {
            Argument.IsNotNull("execute", execute);
            Argument.IsNotNull("validationSummaryPropertyExpression", validationSummaryPropertyExpression);

            var property = validationSummaryPropertyExpression.Compile();

            var command = new Command <TExecuteParameter>(execute, parameter =>
            {
                IValidationSummary validationSummary = property.Invoke();
                return((validationSummary != null) && (!validationSummary.HasErrors));
            }, tag);

            return(command);
        }
            public void ViewModelBaseWithFieldErrorsAndBusinessRuleWarningsValidationTest()
            {
                var personViewModel = new PersonViewModel();

                personViewModel.Validate();

                IValidationSummary validationSummary = personViewModel.ValidationContext.GetValidationSummary("Person");

                Assert.IsTrue(validationSummary.HasErrors);
                Assert.IsTrue(validationSummary.HasFieldErrors);
                Assert.AreEqual(2, validationSummary.FieldErrors.Count);
                Assert.IsTrue(validationSummary.FieldErrors[0].Message.Contains("First name"));
                Assert.IsTrue(validationSummary.FieldErrors[1].Message.Contains("Last name"));

                Assert.IsTrue(validationSummary.HasWarnings);
                Assert.IsTrue(validationSummary.HasBusinessRuleWarnings);
                Assert.AreEqual(2, validationSummary.BusinessWarnings.Count);
                Assert.IsTrue(validationSummary.BusinessWarnings[0].Message.Contains("First name"));
                Assert.IsTrue(validationSummary.BusinessWarnings[1].Message.Contains("Last name"));
            }
Exemple #8
0
 protected virtual void Validate(IValidationSummary summary, T item)
 {
     // method that is called for custom validation implemented in inherited object
 }