Exemplo n.º 1
0
 private static void PrintErrors(InvalidValue[] values)
 {
     foreach (InvalidValue value in values)
     {
         Console.WriteLine("\t-Invalid Property: {0}. Error Message: {1}", value.PropertyName, value.Message);
     }
 }
Exemplo n.º 2
0
 public ValidationResult(InvalidValue invalidValue)
 {
     ClassContext = invalidValue.EntityType;
     PropertyName = invalidValue.PropertyName;
     Message = invalidValue.Message;
     InvalidValue = invalidValue;
 }
        public ValidationResult(InvalidValue invalidValue) {
            Check.Require(invalidValue != null, "invalidValue may not be null");

            ClassContext = invalidValue.EntityType;
            PropertyName = invalidValue.PropertyName;
            Message = invalidValue.Message;
            InvalidValue = invalidValue;
        }
Exemplo n.º 4
0
        private ICollection<IValidationResult> ParseValidationResultsFrom(InvalidValue[] invalidValues) {
            ICollection<IValidationResult> validationResults = new Collection<IValidationResult>();

            foreach (InvalidValue invalidValue in invalidValues) {
                validationResults.Add(new ValidationResult(invalidValue));
            }

            return validationResults;
        }
Exemplo n.º 5
0
        private void FillErrorsOnListBox(InvalidValue[] values)
        {
            listBox1.Items.Clear();

            foreach (InvalidValue value in values)
            {
                string message = value.PropertyName + ": " + value.Message;

                listBox1.Items.Add(message);
            }
        }
        public void ShouldNotCreateValidationExceptionIfNoErrors()
        {
            // arrange
            InvalidValue[] errors = new InvalidValue[] {};

            // act
            ValidationException ex = errors.ToValidationException();

            // assert
            Assert.AreEqual(null, ex);
        }
        public virtual void AddInvalidValue(InvalidValue invalidValue)
        {
            if (InvalidValues == null)
                InvalidValues = new InvalidValue[1];

            var tmpArray = new InvalidValue[InvalidValues.Length + 1];
            tmpArray[InvalidValues.Length] = invalidValue;

            if (InvalidValues.Length > 0)
                InvalidValues.CopyTo(tmpArray, 0);
            InvalidValues = tmpArray;
        }
        public void ShouldCreateValidationException()
        {
            // arrange
            InvalidValue[] errors = new InvalidValue[] { new InvalidValue("Error", typeof(string), "Property", "this", "that", null) };

            // act
            ValidationException ex = errors.ToValidationException();

            // assert
            Assert.IsTrue(ex.Errors.AllKeys.Contains("Property"));
            string[] messages = ex.Errors.GetValues("Property");
            Assert.AreEqual(1, messages.Length);
            Assert.AreEqual("Error", messages[0]);
        }
Exemplo n.º 9
0
 public InvalidStateException(InvalidValue[] invalidValues, String className)
     : base("validation failed for: " + className)
 {
     _invalidValues = invalidValues;
 }
Exemplo n.º 10
0
 public InvalidStateException(InvalidValue[] invalidValues)
     : this(invalidValues, invalidValues[0].GetType().Name)
 {
 }
 public KPExceptionValidator(ActiveRecordBase entity, InvalidValue[] errors)
 {
     Entity = entity;
     Erros = errors;
 }
 public virtual void AddInvalidValues(InvalidValue[] invalidValues)
 {
     foreach (var invalidValue in invalidValues)
         AddInvalidValue(invalidValue);
 }
 public ValidationRequiredEntity()
 {
     InvalidValues = new InvalidValue[0];
 }
Exemplo n.º 14
0
 protected void AddValidationResults(InvalidValue[] invalidValues)
 {
     if (invalidValues == null) return;
     foreach (var invalidValue in invalidValues)
         ModelState.AddModelError(invalidValue.PropertyName, invalidValue.Message);
 }
Exemplo n.º 15
0
 protected void AddValidationResult(string summaryErrorMessage, InvalidValue[] invalidValues)
 {
     ViewData["Error"] = new ErrorModel { Message = summaryErrorMessage };
     AddValidationResults(invalidValues);
 }
        internal protected bool Validate(InvalidValue[] invalidValues)
        {
            this.ErrorsView.Visible = false;
            InvalidValue[] errors = invalidValues;
            bool foundComponent = false;
            if (errors != null)
            {
                int firstTabIndex = 9999;
                int tabIndex = 0;

                WebControl[] componentDataWebControls = this.GetWebControlsType(typeof(IKPComponentData));
                if (componentDataWebControls != null)
                {
                    foreach (WebControl componentData in componentDataWebControls)
                    {
                        if (String.IsNullOrEmpty(((IKPComponentData)componentData).FieldName))
                        {
                            continue;
                        }

                        ((IKPComponentData)componentData).RemoveInvalidateMsg();

                        foreach (InvalidValue error in errors)
                        {
                            if (((IKPComponentData)componentData).FieldName.Equals(error.PropertyName))
                            {
                                foundComponent = true;
                                ((IKPComponentData)componentData).SetInvalidateMsg(error.Message);

                                if (firstTabIndex > 0)
                                {
                                    tabIndex = this.GetTabIndexFromFieldName(error.PropertyName);
                                    if (tabIndex >= 0 && firstTabIndex > tabIndex)
                                    {
                                        firstTabIndex = tabIndex;
                                    }
                                }
                            }
                        }
                    }
                }

                if (errors.Length > 0)
                {
                    string scriptString = "generateMaskValidators();";

                    if (this.KPTabs.Count > 0)
                    {
                        scriptString += KPTabControl.GetTabIndexScript(firstTabIndex);
                    }

                    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "scriptWhenErrorOccur", scriptString, true);

                    if (!foundComponent)
                    {
                        this.AddErrorView("Atenção! Existem componentes não visíveis em tela.");
                        foreach (var errorView in errors)
                        {
                            PropertyInfo prop = errorView.EntityType.GetProperty(errorView.PropertyName);
                            this.AddErrorView(String.Format("{0} - {1}", prop.GetTranslate(), errorView.Message));
                        }
                    }

                    return false;
                }
            }

            return true;
        }