public void Required_Validation_picks_up_message()
        {
            ValidationRules<RuleTestClass> rules = new ValidationRules<RuleTestClass>();
            rules.IfProperty(x => x.Matches).Equals(true).Property(x => x.Name).ShouldBeRequired().WithMessage("a message");

            RuleTestClass target = new RuleTestClass { Matches = true, Name = null };
            rules.Validate(target).IsValid("Name").ShouldBeFalse();
            rules.Validate(target).AllMessages[0].Message.ShouldEqual("a message");
        }
        public void SimpleValidation_for_ShouldBeGreaterThanZero()
        {
            ValidationRules<RuleTestClass> rules = new ValidationRules<RuleTestClass>();
            rules.IfProperty(x => x.Matches).Equals(true).Property(x => x.Age).ShouldBeGreaterThanZero();

            RuleTestClass target = new RuleTestClass { Matches = false, Age = 0 };
            rules.Validate(target).IsValid("Age").ShouldBeTrue();

            target.Matches = true;
            rules.Validate(target).IsValid("Age").ShouldBeFalse();

            target.Age = 34;
            rules.Validate(target).IsValid("Age").ShouldBeTrue();
        }
        public void SimpleValidation_for_Required()
        {
            ValidationRules<RuleTestClass> rules = new ValidationRules<RuleTestClass>();
            rules.IfProperty(x => x.Matches).Equals(true).Property(x => x.Name).ShouldBeRequired().WithMessage("a message");

            RuleTestClass target = new RuleTestClass { Matches = false, Name = null };
            rules.Validate(target).IsValid("Name").ShouldBeTrue();

            target.Matches = true;
            rules.Validate(target).IsValid("Name").ShouldBeFalse();

            target.Name = "Jeremy";
            rules.Validate(target).IsValid("Name").ShouldBeTrue();
        }
Example #4
0
 protected override void AddBusinessRules()
 {
     ValidationRules.AddRule(Dothan.Validation.CommonRules.StringRequired, "Name");
 }
 internal override void AddValidationRules()
 {
     ValidationRules.AddRules(new Validation.ValidateRuleNotNull("Idgroup_solution", "Idgroup_solution"));
     ValidationRules.AddRules(new Validation.ValidateRuleStringMaxLength("Cod_solution", "Cod_solution", 20));
 }
 /// <summary>
 /// Force this object to validate itself using the assigned business rules.
 /// </summary>
 /// <remarks>Validates all properties.</remarks>
 public void Validate()
 {
     ValidationRules.ValidateRules();
 }
 /// <summary>
 /// Adds a rule to the list of validated rules.
 /// </summary>
 /// <param name="handler">The method that implements the rule.</param>
 /// <param name="propertyName">
 /// The name of the property on the target object where the rule implementation can retrieve
 /// the value to be validated.
 /// </param>
 public void AddValidationRuleHandler(Validation.ValidationRuleHandler handler, String propertyName)
 {
     ValidationRules.AddRule(handler, propertyName);
 }
        public override ClaseAuditoria Save()
        {
            // Por la posible doble interfaz Root/Child
            if (IsChild)
            {
                throw new iQException(moleQule.Library.Resources.Messages.CHILD_SAVE_NOT_ALLOWED);
            }

            if (IsDeleted && !CanDeleteObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (IsNew && !CanAddObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (!CanEditObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            try
            {
                ValidationRules.CheckRules();

                base.Save();

                //_plan_clases.Update(this);
                _tipoauditorias.Update(this);

                if (!SharedTransaction)
                {
                    Transaction().Commit();
                }
                return(this);
            }
            catch (Exception ex)
            {
                if (!SharedTransaction)
                {
                    if (!SharedTransaction && Transaction() != null)
                    {
                        Transaction().Rollback();
                    }
                }
                iQExceptionHandler.TreatException(ex);
                return(this);
            }
            finally
            {
                if (!SharedTransaction)
                {
                    if (CloseSessions && (this.IsNew || Transaction().WasCommitted))
                    {
                        CloseSession();
                    }
                    else
                    {
                        BeginTransaction();
                    }
                }
            }
        }
 internal override void AddValidationRules()
 {
     ValidationRules.AddRules(new Validation.ValidateRuleNotNull("Idconfiguration", "Idconfiguration"));
     ValidationRules.AddRules(new Validation.ValidateRuleStringMaxLength("Nom_configuration", "Nom_configuration", 30));
     ValidationRules.AddRules(new Validation.ValidateRuleStringMaxLength("Value_configuration", "Value_configuration", 300));
 }
Example #10
0
        /// <summary>
        /// Guarda en la base de datos todos los cambios del objeto.
        /// También guarda los cambios de los hijos si los tiene
        /// </summary>
        /// <returns>Objeto actualizado y con los flags reseteados</returns>
        public override RemesaNomina Save()
        {
            // Por la posible doble interfaz Root/Child
            if (IsChild)
            {
                throw new iQException(Library.Resources.Messages.CHILD_SAVE_NOT_ALLOWED);
            }

            if (IsDeleted && !CanDeleteObject())
            {
                throw new System.Security.SecurityException(Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (IsNew && !CanAddObject())
            {
                throw new System.Security.SecurityException(Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (!CanEditObject())
            {
                throw new System.Security.SecurityException(Library.Resources.Messages.USER_NOT_ALLOWED);
            }

            try
            {
                ValidationRules.CheckRules();
            }
            catch (iQValidationException ex)
            {
                iQExceptionHandler.TreatException(ex);
                return(this);
            }

            try
            {
                base.Save();

                if (!SharedTransaction)
                {
                    Transaction().Commit();
                }
                return(this);
            }
            catch (Exception ex)
            {
                if (Transaction() != null)
                {
                    Transaction().Rollback();
                }
                iQExceptionHandler.TreatException(ex);
                return(this);
            }
            finally
            {
                if (!SharedTransaction)
                {
                    if (CloseSessions)
                    {
                        CloseSession();
                    }
                    else
                    {
                        BeginTransaction();
                    }
                }
            }
        }
Example #11
0
 protected override void AddBusinessRules()
 {
     ValidationRules.AddRule(Dothan.Validation.CommonRules.IntegerMinValue, new Dothan.Validation.CommonRules.IntegerMinValueRuleArgs("CourseId", 1));
 }
 internal override void AddValidationRules()
 {
     ValidationRules.AddRules(new Validation.ValidateRuleNotNull("Idreactive", "Idreactive"));
     ValidationRules.AddRules(new Validation.ValidateRuleStringMaxLength("Reactive_name", "Reactive_name", 40));
     ValidationRules.AddRules(new Validation.ValidateRuleStringMaxLength("Chemical_formula", "Chemical_formula", 15));
 }
Example #13
0
        /// <summary>
        /// Guarda en la base de datos todos los cambios del objeto.
        /// También guarda los cambios de los hijos si los tiene
        /// </summary>
        /// <returns>Objeto actualizado y con los flags reseteados</returns>
        public override PayrollBatch Save()
        {
            // Por la posible doble interfaz Root/Child
            if (IsChild)
            {
                throw new iQException(moleQule.Resources.Messages.CHILD_SAVE_NOT_ALLOWED);
            }

            if (IsDeleted && !CanDeleteObject())
            {
                throw new System.Security.SecurityException(moleQule.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (IsNew && !CanAddObject())
            {
                throw new System.Security.SecurityException(moleQule.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (!CanEditObject())
            {
                throw new System.Security.SecurityException(moleQule.Resources.Messages.USER_NOT_ALLOWED);
            }

            try
            {
                ValidationRules.CheckRules();
            }
            catch (iQValidationException ex)
            {
                iQExceptionHandler.TreatException(ex);
                return(this);
            }

            try
            {
                CalculateTotal();

                base.Save();

                _nominas.Update(this);
                _gastos.Update(this);

                Transaction().Commit();
                return(this);
            }
            catch (Exception ex)
            {
                if (Transaction() != null)
                {
                    Transaction().Rollback();
                }
                iQExceptionHandler.TreatException(ex);
                return(this);
            }
            finally
            {
                Cache.Instance.Remove(typeof(TipoGastoList));
                Cache.Instance.Remove(typeof(EmployeeList));

                if (CloseSessions)
                {
                    CloseSession();
                }
                else
                {
                    BeginTransaction();
                }
            }
        }
Example #14
0
 /// <inheritdoc />
 public override ValidationResult Validate(ValidationRules rules = ValidationRules.All) =>
 new ValidationResult(Repositories.SelectMany(r => r.Validate(rules).Errors).ToList());
Example #15
0
 public override void InitValidation()
 {
     SetValidationRule(NameTextEdit, ValidationRules.IsNotBlankRule(ItemForName.Text));
     SetValidationRule(OwnerIdLookUpEdit, ValidationRules.IsNotBlankRule(ItemForOwnerId.Text));
     SetValidationRule(OwnerIdLookUpEdit, ValidationRules.IsGuidNotBlankRule(ItemForOwnerId.Text));
 }
Example #16
0
 protected override void AddBusinessRules()
 {
     ValidationRules.AddRule(
         Csla.Validation.CommonRules.StringRequired, "Nombre");
 }
Example #17
0
 protected override void DataPortal_Create(object criteria)
 {
     ValidationRules.CheckRules();
 }
Example #18
0
 /// <summary>
 /// Añade las reglas de validación necesarias para el objeto
 /// </summary>
 protected override void AddBusinessRules()
 {
     ValidationRules.AddRule(CheckValidation, "Oid");
 }
Example #19
0
 internal abstract void Validate(ValidationRules rules, Node nextNode);
Example #20
0
        public override Empresa Save()
        {
            // Por la posible doble interfaz Root/Child
            if (IsChild)
            {
                throw new iQException(moleQule.Library.Resources.Messages.CHILD_SAVE_NOT_ALLOWED);
            }

            if (IsDeleted && !CanDeleteObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (IsNew && !CanAddObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (!CanEditObject())
            {
                throw new System.Security.SecurityException(
                          moleQule.Library.Resources.Messages.USER_NOT_ALLOWED);
            }

            // Guardamos si es nuevo pq tras el Save la propiedad IsNew es false
            // y necesitamos saber si es un Insert para crear el eschema de usuarios
            // tras guardar la empresa
            Boolean isNew = IsNew;

            try
            {
                ValidationRules.CheckRules();

                base.Save();

                _contactos.Update(this);

                Transaction().Commit();

                // Si es una inserción de una nueva empresa tenemos que crear
                // el mapa de permisos de los usuarios
                if (isNew)
                {
                    PrincipalBase.NewSchema(this.Oid);
                }

                return(this);
            }
            catch (Exception ex)
            {
                if (Transaction() != null)
                {
                    Transaction().Rollback();
                }
                iQExceptionHandler.TreatException(ex);
                return(this);
            }
            finally
            {
                BeginTransaction();
            }
        }
Example #21
0
 internal override void Validate(ValidationRules rules, Node nextNode)
 {
     Debug.Assert(this == Empty, $"Assertion failed: this == {nameof(Empty)}");
     Debug.Assert(nextNode == null, $"Assertion failed: {nameof(nextNode)} == null");
 }
Example #22
0
 public ExceptionBinding()
 {
     ValidationRules.Add(new ExceptionValidationRule());
     UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
 }
Example #23
0
        //región a rellenar si hay campos requeridos o claves ajenas

        protected override void AddBusinessRules()
        {
            ValidationRules.AddRule(CommonRules.StringRequired, "Valor");

            //Agregar otras reglas de validación
        }
 protected override void AddBusinessRules()
 {
     ValidationRules.AddRule(CommonRules.StringRequired, CustomerNameProperty);
 }
 public override void InitValidation()
 {
     SetValidationRule(ModuleNameTextEdit, ValidationRules.IsNotBlankRule(ItemForModuleName.Text));
 }
 /// <summary>
 /// Adds a rule to the list of validated rules.
 /// </summary>
 /// <remarks>
 /// </remarks>
 /// <param name="handler">The method that implements the rule.</param>
 /// <param name="args">
 /// A <see cref="Validation.ValidationRuleArgs"/> object specifying the property name and other arguments
 /// passed to the rule method
 /// </param>
 public void AddValidationRuleHandler(Validation.ValidationRuleHandler handler, Validation.ValidationRuleArgs args)
 {
     ValidationRules.AddRule(handler, args);
 }
Example #27
0
 protected override void AddBusinessRules()
 {
     ValidationRules.AddRule(Csla.Validation.CommonRules.IntegerMinValue, new Csla.Validation.CommonRules.IntegerMinValueRuleArgs(IdProperty, 1));
 }
 /// <summary>
 /// Force the object to validate itself using the assigned business rules.
 /// </summary>
 /// <param name="propertyName">Name of the property to validate.</param>
 public void Validate(string propertyName)
 {
     ValidationRules.ValidateRules(propertyName);
 }
Example #29
0
 public bool IsValidStrict() => IsValid() && Fields.All(x => ValidationRules[x.Key](x.Value));
Example #30
0
 internal override void AddValidationRules()
 {
     ValidationRules.AddRules(new Validation.ValidateRuleNotNull("EMP_ID", "EMP_ID"));
     ValidationRules.AddRules(new Validation.ValidateRuleNotNull("MONTH", "MONTH"));
     ValidationRules.AddRules(new Validation.ValidateRuleNotNull("YEAR", "YEAR"));
 }
Example #31
0
        /// <summary>
        /// Guarda en la base de datos todos los cambios del objeto.
        /// También guarda los cambios de los hijos si los tiene
        /// </summary>
        /// <returns>Objeto actualizado y con los flags reseteados</returns>
        public override Registro Save()
        {
            // Por la posible doble interfaz Root/Child
            if (IsChild)
            {
                throw new iQException(Library.Resources.Messages.CHILD_SAVE_NOT_ALLOWED);
            }

            if (IsDeleted && !CanDeleteObject())
            {
                throw new System.Security.SecurityException(Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (IsNew && !CanAddObject())
            {
                throw new System.Security.SecurityException(Library.Resources.Messages.USER_NOT_ALLOWED);
            }
            else if (!CanEditObject())
            {
                throw new System.Security.SecurityException(Library.Resources.Messages.USER_NOT_ALLOWED);
            }

            try
            {
                ValidationRules.CheckRules();
            }
            catch (iQValidationException ex)
            {
                iQExceptionHandler.TreatException(ex);
                return(this);
            }

            try
            {
                base.Save();

                BuildLists();
#if TRACE
                Library.Timer.Instance.Record("Registro.BuildLists()");
#endif
                _lineas.Update(this, _entities_list);
#if TRACE
                Library.Timer.Instance.Record("LineaRegistros.Update()");
#endif
                SaveLists();
#if TRACE
                Library.Timer.Instance.Record("Registro::SaveLists()");
#endif
                Transaction().Commit();
#if TRACE
                Library.Timer.Instance.Record("Registro::Commit()");
#endif
                return(this);
            }
            catch (Exception ex)
            {
                if (Transaction() != null)
                {
                    Transaction().Rollback();
                }
                iQExceptionHandler.TreatException(ex);
                return(this);
            }
            finally
            {
                if (CloseSessions)
                {
                    CloseSession();
                }
                else
                {
                    BeginTransaction();
                }
            }
        }
Example #32
0
 public TextArea(string name, string label, string attrClass,
                 bool required, string placeholder, bool disabled, ValidationRules rules, string value) :
     base(name, label, attrClass, required, placeholder, disabled, rules, value)
 {
 }
Example #33
0
 private void CheckValidation(string fullName, string shortName, string kindOfAnimal, string description, string animalAge, string animalWeight)
 {
     if (ValidationRules.FullNameValidation(fullName))
     {
         FullNameValidationIcon           = FontAwesomeIcon.CheckCircle;
         FullNameValidationIconVisibility = Visibility.Visible;
     }
     else
     {
         FullNameValidationIcon           = FontAwesomeIcon.MinusCircle;
         FullNameValidationIconVisibility = Visibility.Visible;
     }
     if (ValidationRules.ShortNameValidation(shortName))
     {
         ShortNameValidationIcon           = FontAwesomeIcon.CheckCircle;
         ShortNameValidationIconVisibility = Visibility.Visible;
     }
     else
     {
         ShortNameValidationIcon           = FontAwesomeIcon.MinusCircle;
         ShortNameValidationIconVisibility = Visibility.Visible;
     }
     if (ValidationRules.KindOfAnimalValidation(kindOfAnimal))
     {
         KindOfAnimalValidationIcon           = FontAwesomeIcon.CheckCircle;
         KindOfAnimalValidationIconVisibility = Visibility.Visible;
     }
     else
     {
         KindOfAnimalValidationIcon           = FontAwesomeIcon.MinusCircle;
         KindOfAnimalValidationIconVisibility = Visibility.Visible;
     }
     if (ValidationRules.DescriptionValidation(description))
     {
         DescriptionValidationIcon           = FontAwesomeIcon.CheckCircle;
         DescriptionValidationIconVisibility = Visibility.Visible;
     }
     else
     {
         DescriptionValidationIcon           = FontAwesomeIcon.MinusCircle;
         DescriptionValidationIconVisibility = Visibility.Visible;
     }
     if (ValidationRules.AnimalAgeValidation(animalAge))
     {
         AnimalAgeValidationIcon           = FontAwesomeIcon.CheckCircle;
         AnimalAgeValidationIconVisibility = Visibility.Visible;
     }
     else
     {
         AnimalAgeValidationIcon           = FontAwesomeIcon.MinusCircle;
         AnimalAgeValidationIconVisibility = Visibility.Visible;
     }
     if (ValidationRules.AnimalWeightValidation(animalWeight))
     {
         AnimalWeightValidationIcon           = FontAwesomeIcon.CheckCircle;
         AnimalWeightValidationIconVisibility = Visibility.Visible;
     }
     else
     {
         AnimalWeightValidationIcon           = FontAwesomeIcon.MinusCircle;
         AnimalWeightValidationIconVisibility = Visibility.Visible;
     }
 }