/// <summary> /// Validates the property. /// </summary> /// <param name="validation">The validation.</param> /// <param name="itemResult">The item result.</param> /// <returns><c>true</c> if the validation is successful, <c>false</c> otherwise.</returns> private bool ValidateProperty(ItemValidation validation, ValidationItemResult itemResult) { IPropertyData propertyData; if (!this.ElementLocator.TryGetProperty(validation.FieldName, out propertyData)) { if (validation.Comparer is DoesNotExistComparer) { itemResult.NoteValidationResult(validation, successful: true, actualValue: null); return(true); } itemResult.NoteMissingProperty(validation); return(false); } string actualValue = null; bool? successful = null; this.DoValidate <IPropertyData>(propertyData, e => { successful = e.ValidateItem(validation, out actualValue); return(successful.Value); }); itemResult.NoteValidationResult(validation, successful.Value, actualValue); return(successful.Value); }
/// <summary> /// Checks the item. /// </summary> /// <param name="element">The element.</param> /// <param name="validations">The validations.</param> /// <param name="validationResult">The validation tracker.</param> /// <returns><c>true</c> if the item is valid; otherwise <c>false</c>.</returns> private bool CheckItem(TElement element, IEnumerable <ItemValidation> validations, ValidationResult validationResult) { var page = this.ElementHandler.GetPageFromElement(element); var validationItemResult = new ValidationItemResult(); validationResult.CheckedItems.Add(validationItemResult); var result = true; foreach (var itemValidation in validations) { IPropertyData property; if (!page.TryGetProperty(itemValidation.FieldName, out property)) { validationItemResult.NoteMissingProperty(itemValidation); result = false; continue; } string actualValue; var successful = true; if (!property.ValidateItem(itemValidation, out actualValue)) { successful = false; result = false; } validationItemResult.NoteValidationResult(itemValidation, successful, actualValue); } return(result); }
/// <summary> /// Validates the property. /// </summary> /// <param name="validation">The validation.</param> /// <param name="itemResult">The item result.</param> /// <returns><c>true</c> if the validation is successful, <c>false</c> otherwise.</returns> private bool ValidateProperty(ItemValidation validation, ValidationItemResult itemResult) { IPropertyData propertyData; if (!this.ElementLocator.TryGetProperty(validation.FieldName, out propertyData)) { itemResult.NoteMissingProperty(validation); return(false); } string actualValue; var successful = propertyData.ValidateItem(validation, out actualValue); itemResult.NoteValidationResult(validation, successful, actualValue); return(successful); }
public void TestGetComparisonTableByRuleWithMissingField() { var validation = ItemValidationHelper.Create("MyField", "Something"); var validationResult = new ValidationResult(new[] { validation }); var itemResult = new ValidationItemResult(); itemResult.NoteMissingProperty(validation); validationResult.CheckedItems.Add(itemResult); var result = validationResult.GetComparisonTableByRule(); var expectedTable = new StringBuilder() .AppendLine("| Field | Rule | Value |") .Append("| MyField [Not Found] | equals | Something |"); Assert.AreEqual(expectedTable.ToString(), result); }