public void TestValidatorResultForMessages() { var vr = new ValidationResult(true); vr.AddErrorMessage("TEST", "Property"); vr.AddErrorMessage("TESTQ", "Property"); Assert.That(vr.ErrorMessages, Is.EquivalentTo(new String[] { "TEST", "TESTQ" } )); }
public override ValidationResult IsCorrectItem(DishCategory item) { ValidationResult valResult = new ValidationResult(true); if (string.IsNullOrWhiteSpace(item.Name)) { valResult.AddErrorMessage("Name is incorrect"); } if (item.Image == null || item.Image.Length == 0) { valResult.AddErrorMessage("Image is incorrect"); } return(valResult); }
public ValidationResult IsCorrectItem(PortionFood item) { ValidationResult valResult = new ValidationResult(true); if (item.Food == null && FoodService.Get(item.IdFood) == null) { valResult.AddErrorMessage("IdFood is incorrect"); } if (item.Dish == null && DishService.Get(item.IdDish) == null) { valResult.AddErrorMessage("IdDish is incorrect"); } return(valResult); }
public override ValidationResult IsCorrectItem(DishEating item) { ValidationResult valResult = new ValidationResult(true); if (item.Dish == null && DishService.Get(item.IdDish) == null) { valResult.AddErrorMessage("IdDish is incorrect"); } if (item.Eating == null && DishService.Get(item.IdEatinng) == null) { valResult.AddErrorMessage("IdEatinng is incorrect"); } return(valResult); }
public override ValidationResult IsCorrectItem(Dish item) { ValidationResult valResult = new ValidationResult(true); if (string.IsNullOrWhiteSpace(item.Name) || item.Name.Length > 50) { valResult.AddErrorMessage("Name is incorrect"); } if (item.DishCategory == null && CategoryService.Get(item.IdDishCategory) == null) { valResult.AddErrorMessage("IdDishCategory is incorrect"); } return(valResult); }
public override ValidationResult IsCorrectItem(User item) { ValidationResult valResult = new ValidationResult(true); if (string.IsNullOrWhiteSpace(item.FirstName) == true || item.FirstName.Length > 50) { valResult.AddErrorMessage("FirstName is incorrect"); } if (string.IsNullOrWhiteSpace(item.LastName) == true || item.LastName.Length > 50) { valResult.AddErrorMessage("LastName is incorrect"); } if (string.IsNullOrWhiteSpace(item.IdUserCredential) == true) { valResult.AddErrorMessage("IdUserCredential is incorrect"); } return(valResult); }
Validate(object objectToValidate, ValidationFlags validationFlags) { //First of all retrieve the object, if it is null validate. ValidationResult results = new ValidationResult(); object obj = Extract <Object>(objectToValidate); if (obj != null) { if (obj is IEnumerable) { //the object is IEnumerable, we need to validate inner objects Int32 index = 0; foreach (var innerObj in obj as IEnumerable) { var errors = ValidateSingleObject(innerObj, validationFlags); foreach (var validationError in errors) { results.Success = false; results.AddErrorMessage( validationError.Message, string.Format("{0}[{1}].{2}", mValueExtractor.SourceName, index, validationError.SourceName)); } index++; } } else { //Check if this object support a validation, if we do not have a rule the object should //be considered valid. var errors = ValidateSingleObject(obj, validationFlags); foreach (var validationError in errors) { results.AddErrorMessage( validationError.Message, mValueExtractor.SourceName + "." + validationError.SourceName); } } return(results); } return(results); }
public override ValidationResult IsCorrectItem(Eating item) { ValidationResult valResult = new ValidationResult(true); if (item.User == null && UserService.Get(item.IdUser) == null) { valResult.AddErrorMessage("IdUser is incorrect"); } return(valResult); }
public override ValidationResult IsCorrectItem(FoodConsistencyType item) { ValidationResult valResult = new ValidationResult(true); if (string.IsNullOrWhiteSpace(item.Name) == true || item.Name.Length > 50) { valResult.AddErrorMessage("Name is incorrect"); } return(valResult); }
public override ValidationResult IsCorrectItem(Food item) { ValidationResult valResult = new ValidationResult(true); if (string.IsNullOrWhiteSpace(item.Name) || item.Name.Length > 50) { valResult.AddErrorMessage("Name is incorrect"); } if (item.Image == null || item.Image.Length == 0) { valResult.AddErrorMessage("Image is incorrect"); } if (item.FoodCategory == null && FoodCategoryService.Get(item.IdFoodCategory) == null) { valResult.AddErrorMessage("IdFoodCategory is incorrect"); } if (item.FoodConsistencyType == null && FoodConsistencyTypeService.Get(item.IdFoodConsistencyType) == null) { valResult.AddErrorMessage("IdFoodConsistencyType is incorrect"); } return(valResult); }
/// <summary> /// this is the real function that performs validation. /// </summary> /// <param name="actualResult"></param> /// <param name="objToValidate"></param> /// <param name="validationFlag"></param> /// <param name="cultureInfo"></param> /// <returns></returns> public override Boolean Validate( ValidationResult actualResult, object objToValidate, ValidationFlags validationFlag, CultureInfo cultureInfo) { SingleValidationResult res = mValidator.Validate(objToValidate); if (!res) { actualResult.Success = false; actualResult.AddErrorMessage(GetErrorMessage(res, cultureInfo), res.SourceName); } return(res); }
public async Task ValidationResult_GetErrorMessages_Success() { await RunWithTelemetryAsync( totalOfExecutions : 1, runInParallel : false, handler : async execution => { #region Arrange var result = false; var validationResult = new ValidationResult(); validationResult.AddErrorMessage("MCB", "MCB", "MCB"); #endregion #region Act result = validationResult.ErrorMessageCollection.Any(); #endregion #region Assert return(await Task.FromResult(result).ConfigureAwait(false)); #endregion } ).ConfigureAwait(false); }
/// <summary> /// this is the real function that performs validation. /// </summary> /// <param name="actualResult"></param> /// <param name="objToValidate"></param> /// <param name="validationFlag"></param> /// <param name="cultureInfo"></param> /// <returns></returns> public override Boolean Validate( ValidationResult actualResult, object objToValidate, ValidationFlags validationFlag, CultureInfo cultureInfo) { SingleValidationResult res = mValidator.Validate(objToValidate); if (!res) { actualResult.Success = false; actualResult.AddErrorMessage(GetErrorMessage(res, cultureInfo), res.SourceName); } return res; }