本文整理汇总了C#中ValidationErrors类的典型用法代码示例。如果您正苦于以下问题:C# ValidationErrors类的具体用法?C# ValidationErrors怎么用?C# ValidationErrors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationErrors类属于命名空间,在下文中一共展示了ValidationErrors类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WhenInvalid
public void WhenInvalid()
{
Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
IValidationErrors errors = new ValidationErrors();
ErrorMessageAction action = new ErrorMessageAction("{0}, {1}", "errors");
action.Parameters = new IExpression[] {Expression.Parse("Name"), Expression.Parse("Nationality")};
action.Execute(false, context, null, errors);
Assert.IsFalse(errors.IsEmpty);
Assert.AreEqual(1, errors.GetErrors("errors").Count);
Assert.AreEqual(context.Name + ", " + context.Nationality, errors.GetResolvedErrors("errors", new NullMessageSource())[0]);
}
示例2: FalseScalarExpression
public void FalseScalarExpression()
{
Inventor tesla = new Inventor();
tesla.Name = "Soltan Gris";
ConditionValidator validator = new ConditionValidator(Expression.Parse("Name == 'Nikola Tesla'"), null);
validator.Actions = new ErrorMessageAction[] {new ErrorMessageAction("Wrong name", "InventorValidator") };
IValidationErrors errors = new ValidationErrors();
Assert.IsFalse(validator.Validate(tesla, errors));
Assert.IsFalse(errors.IsEmpty);
IList<string> namedErrors = errors.GetResolvedErrors("InventorValidator", new NullMessageSource());
Assert.AreEqual(1, namedErrors.Count);
string error = (string) namedErrors[0];
Assert.AreEqual("Wrong name", error);
}
示例3: WithNull
public void WithNull()
{
RequiredValidator validator = new RequiredValidator();
validator.Test = Expression.Parse("null");
IValidationErrors errors = new ValidationErrors();
Assert.IsFalse(validator.Validate(null, errors));
}
示例4: Delete
public bool Delete(ref ValidationErrors errors, string id)
{
try
{
//检查是否有下级
if (dbContainer.SysModules.AsQueryable().Where(a => a.SysModule2.Id == id).Count() > 0)
{
errors.Add("有下属关联,请先删除下属!");
return false;
}
m_Rep.Delete(dbContainer, id);
if (dbContainer.SaveChanges() > 0)
{
//清理无用的项
dbContainer.P_Sys_ClearUnusedRightOperate();
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
errors.Add(ex.Message);
ExceptionHander.WriteException(ex);
return false;
}
}
示例5: Create
/// <summary>
/// 创建一个菜单
/// </summary>
/// <param name="validationErrors">返回的错误信息</param>
/// <param name="db">数据库上下文</param>
/// <param name="entity">一个菜单</param>
/// <returns></returns>
public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
{
int count = 1;
foreach (string item in entity.SysOperationId.GetIdSort())
{
SysOperation sys = new SysOperation { Id = item };
db.SysOperation.Attach(sys);
entity.SysOperation.Add(sys);
count++;
}
repository.Create(db, entity);
if (count == repository.Save(db))
{
//创建后重置菜单编码
List<int> flags = new List<int>();//层级
GetMenus2(null, flags);
db.SaveChanges();
return true;
}
else
{
validationErrors.Add("创建出错了");
}
return false;
}
示例6: Create
public bool Create(ref ValidationErrors errors, SysModuleOperateModel model)
{
try
{
SysModuleOperate entity = m_Rep.GetById(model.Id);
if (entity != null)
{
errors.Add(Suggestion.PrimaryRepeat);
return false;
}
entity = new SysModuleOperate();
entity.Id = model.Id;
entity.Name = model.Name;
entity.KeyCode = model.KeyCode;
entity.ModuleId = model.ModuleId;
entity.IsValid = model.IsValid;
entity.Sort = model.Sort;
if (m_Rep.Create(entity) == 1)
{
return true;
}
else
{
errors.Add(Suggestion.InsertFail);
return false;
}
}
catch (Exception ex)
{
errors.Add(ex.Message);
ExceptionHander.WriteException(ex);
return false;
}
}
示例7: OnField_WithValidationError
public void OnField_WithValidationError()
{
ValidationErrors errors = new ValidationErrors();
errors.AddError("country_name", new ValidationError("country_name", "91803", "invalid country"));
Assert.AreEqual(ValidationErrorCode.ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, errors.OnField("country_name")[0].Code);
Assert.AreEqual("invalid country", errors.OnField("country_name")[0].Message);
}
示例8: Size_WithShallowErrors
public void Size_WithShallowErrors()
{
ValidationErrors errors = new ValidationErrors();
errors.AddError("country_name", new ValidationError("country_name", "1", "invalid country"));
errors.AddError("another_field", new ValidationError("another_field", "2", "another message"));
Assert.AreEqual(2, errors.Count);
}
示例9: Validate
public override void Validate(string value, ValidationErrors errors)
{
if (!IsPresent(value))
{
errors.Add(Key,ErrorMessage);
}
}
示例10: WithNegativeNumber
public void WithNegativeNumber()
{
RequiredValidator validator = new RequiredValidator();
validator.Test = Expression.Parse("-100");
IValidationErrors errors = new ValidationErrors();
Assert.IsTrue(validator.Validate(null, errors));
}
示例11: Create
/// <summary>
/// 创建一个人员
/// </summary>
/// <param name="validationErrors">返回的错误信息</param>
/// <param name="db">数据库上下文</param>
/// <param name="entity">一个人员</param>
/// <returns></returns>
public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysPerson entity)
{
int count = 1;
foreach (string item in entity.SysRoleId.GetIdSort())
{
SysRole sys = new SysRole { Id = item };
db.SysRole.Attach(sys);
entity.SysRole.Add(sys);
count++;
}
foreach (string item in entity.SysDocumentId.GetIdSort())
{
SysDocument sys = new SysDocument { Id = item };
db.SysDocument.Attach(sys);
entity.SysDocument.Add(sys);
count++;
}
repository.Create(db, entity);
if (count == repository.Save(db))
{
return true;
}
else
{
validationErrors.Add("创建出错了");
}
return false;
}
示例12: Validate
public void Validate(string password, string salt, string hashedPassword, ValidationErrors errors)
{
if (RequiredValidator.IsPresent(password))//dont check salt and hashedPassword IsPresent
{
if (!new StringHasher().ComputedHashUsingGivenSaltMatchesGivenHash( password, salt, hashedPassword))
errors.Add(Key, ErrorMessage);
}
}
示例13: StudyIntegrityValidationFailure
public StudyIntegrityValidationFailure(ValidationErrors error, ValidationStudyInfo validationStudyInfo, string details)
: base(details)
{
Platform.CheckForNullReference(validationStudyInfo, "validationStudyInfo");
_error = error;
_validationStudyInfo = validationStudyInfo;
}
示例14: Validate
public override void Validate(string value, ValidationErrors errors)
{
if (RequiredValidator.IsPresent(value))
{
if(value.Length > _maxLength || value.Length < _minLength)
errors.Add(Key,ErrorMessage);
}
}
示例15: Validate
public override void Validate(string guidstring, ValidationErrors errors)
{
Guid guid;
if (!Guid.TryParse(guidstring, out guid))
{
errors.Add(Key, ErrorMessage);
}
}