public void TestValidate_3() { _sample.MaxLengthValue = "abcdefg"; var result = DataAnnotationValidation.Validate(_sample); Assert.True(result.Count(t => t.ErrorMessage == "最大长度是2") == 1); }
public void TestValidate_Name_Required() { _sample.Name = null; var result = DataAnnotationValidation.Validate(_sample); Assert.Equal("姓名不能为空", result.First().ErrorMessage); }
public void TestValidate_2() { _sample.TestValue = null; var result = DataAnnotationValidation.Validate(_sample); Assert.True(result.Count(t => t.ErrorMessage == "测试值不能为空") == 1); }
public void TestValidate_Resource() { _sample.EnglishName = null; var result = DataAnnotationValidation.Validate(_sample); Assert.Equal("英文名不能为空", result.First().ErrorMessage); }
public void TestValidate_1() { _sample.TestValue = null; _sample.StringValue = " "; var result = DataAnnotationValidation.Validate(_sample); Assert.Equal(2, result.Count); }
public void TestValidate() { _sample.Name = null; _sample.EnglishName = " "; var result = DataAnnotationValidation.Validate(_sample); Assert.Equal(2, result.Count); }
public void Channel_Validate_Name_Required_Test() { var name = ""; var channel = new Channel(name, description, icon, bgColor, slug, order, link, @class, imageClass, parentId); var validationResultCollection = DataAnnotationValidation.Validate(channel); Assert.Equal(1, validationResultCollection.Count); Assert.Equal("The Name field is required.", validationResultCollection.First().ErrorMessage); }
/// <summary> /// 验证 /// </summary> public void Validate() { var result = DataAnnotationValidation.Validate(this); if (result.IsValid == false) { throw new Warning(result.First().ErrorMessage); } }
/// <summary> /// 数据验证 /// </summary> public virtual void Validation() { var collection = DataAnnotationValidation.Validate(this); if (!collection.IsValid) { throw new Exceptions.Warning(collection.Select(t => t.ErrorMessage).ToList()); } }
/// <summary> /// 验证 /// </summary> public virtual ValidationResultCollection Validate() { var result = DataAnnotationValidation.Validate(this); if (result.IsValid) { return(ValidationResultCollection.Success); } throw new Warning(result.First().ErrorMessage); }
/// <summary> /// 验证 /// </summary> /// <typeparam name="T">验证对象类型</typeparam> /// <param name="value">验证值</param> public static ValidationResultCollection Validate <T>(this T value) where T : class { var result = DataAnnotationValidation.Validate(value); if (result.IsValid) { return(ValidationResultCollection.Success); } throw new Warning(result.First().ErrorMessage); }
/// <summary> /// 获取验证结果 /// </summary> /// <returns></returns> private ValidationResultCollection GetValidationResults() { var result = DataAnnotationValidation.Validate(this); Validate(result); foreach (var rule in _rules) { result.Add(rule.Validate()); } return(result); }
/// <summary> /// 验证 /// </summary> public virtual ValidationResultCollection Validate() { ValidateMoney(); var result = DataAnnotationValidation.Validate(this); if (result.IsValid) { return(ValidationResultCollection.Success); } throw new Exception(result.First().ErrorMessage); }
/// <summary> /// 验证 /// </summary> public override ValidationResultCollection Validate() { var result = DataAnnotationValidation.Validate(this); if (NewPassword != ConfirmPassword) { result.Add(new ValidationResult("新密码不一致")); } if (result.IsValid) { return(ValidationResultCollection.Success); } throw new Warning(result.First().ErrorMessage); }
public void Channel_Validate_Name_Range_Test() { var name = "2"; var channel = new Channel(name, description, icon, bgColor, slug, order, link, @class, imageClass, parentId); var validationResultCollection = DataAnnotationValidation.Validate(channel); Assert.Equal(1, validationResultCollection.Count); Assert.Equal("The field Name must be a string or array type with a minimum length of '2'.", validationResultCollection.First().ErrorMessage); name = "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"; channel.Change(name, description, icon, bgColor, slug, order, link, @class, imageClass, parentId); validationResultCollection = DataAnnotationValidation.Validate(channel); Assert.Equal(1, validationResultCollection.Count); Assert.Equal("The field Name must be a string with a maximum length of 50.", validationResultCollection.First().ErrorMessage); }