public void CheckValidationRule_ThrowsValidationException()
        {
            //Arrange
            var    falsePredicate = PredicateBuilder.False <object>();
            string errMsg         = "Predicate returned false";
            object o = new object();

            //Act
            valEngine.AddValidation <object>(falsePredicate, errMsg);

            //Assert
            Assert.Throws(typeof(ValidationException), () => valEngine.ValidateOrThrow(o));
        }
Ejemplo n.º 2
0
        private T InvokeUpdateOrInsert <T>(Func <IRepository <T>, Func <T, T> > func, T ent)
            where T : class
        {
            try
            {
                if (ValidationRulesEngine != null)
                {
                    ValidationRulesEngine.ValidateOrThrow(ent);
                }
                var rep = RecordCaseUnitOfWork.GetRepository <T>();
                return(func(rep)(ent));
            }
            catch (DbEntityValidationException ex)
            {
                StringBuilder sb = new StringBuilder();


                ex.EntityValidationErrors.ForEachInEnumerable(failure =>
                {
                    sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                    foreach (var error in failure.ValidationErrors)
                    {
                        sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                        sb.AppendLine();
                    }
                });

                // Add the original exception as the innerException
                throw new DbEntityValidationException("Entity Validation Failed - errors follow:\n" + sb, ex);
            }
        }