本文整理汇总了C#中Field.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# Field.Validate方法的具体用法?C# Field.Validate怎么用?C# Field.Validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Field
的用法示例。
在下文中一共展示了Field.Validate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanValidateByRule
public void CanValidateByRule(DataType dataType, object value, string ruleType, string ruleContent, bool expected)
{
var rule = new Rule {Type = ruleType, Content = ruleContent};
var schema = new FieldSchema { DataType = dataType, Rules = new[]{rule} };
var field = new Field(schema, value);
field.Validate();
if (expected)
{
Assert.AreEqual(0, field.Errors.Count());
Assert.AreEqual(NodeState.Valid, field.State);
}
else
{
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(ruleType, field.Errors.First().Type);
}
}
示例2: CanValidateCompare
public void CanValidateCompare(DataType type, object input, string compareType, string against, bool expected)
{
var field = new Field(new FieldSchema
{
DataType = type,
Rules = new[] { new Rule { Type = compareType, Content = against } }
}, input);
field.Validate();
if (expected)
{
Assert.AreEqual(0, field.Errors.Count());
}
else
{
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(compareType, field.Errors.First().Type);
}
}
示例3: ShouldValidateEvaluation
public void ShouldValidateEvaluation(DataType type, string expression, bool expected)
{
var schema = new FieldSchema { DataType = type, Default = expression };
var field = new Field(schema);
field.Validate();
var actual = field.State == NodeState.Valid;
Assert.AreEqual(expected, actual);
if (actual)
{
CollectionAssert.IsEmpty(field.Errors);
}
else
{
CollectionAssert.IsNotEmpty(field.Errors);
Assert.AreEqual(ValidationType.Evaluation, field.Errors.First().Type);
}
}
示例4: ShouldStopValidationOnIsRequiredIfFailed
public void ShouldStopValidationOnIsRequiredIfFailed()
{
var schema = new FieldSchema
{
Rules = new List<Rule>
{
new Rule { Type = ValidationType.MinSize, Content = "2"},
new Rule { Type = ValidationType.Exist },
}
};
var field = new Field(schema, "");
field.Validate();
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(ValidationType.Exist, field.Errors.First().Type);
}
示例5: ShouldStopValidationOnFormatIfFailed
public void ShouldStopValidationOnFormatIfFailed()
{
var schema = new FieldSchema
{
DataType = DataType.Integer,
Rules = new List<Rule>
{
new Rule
{
Type = ValidationType.Max,
Content = "100",
}
}
};
var field = new Field(schema, "abc123");
field.Validate();
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(ValidationType.Format, field.Errors.First().Type);
}
示例6: ShouldStopValidationOnEvaluationIfFailed
public void ShouldStopValidationOnEvaluationIfFailed()
{
var schema = new FieldSchema
{
DataType = DataType.Integer,
Rules = new List<Rule>
{
new Rule
{
Type = ValidationType.Max,
Content = "100",
}
},
Default = "=x^2+2*x+1"
};
var field = new Field(schema);
field.Validate();
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(ValidationType.Evaluation, field.Errors.First().Type);
}
示例7: CanValidateUniqueNessForList
public void CanValidateUniqueNessForList(string input, bool expected)
{
var field = new Field(new ListSchema
{
DataType = DataType.List,
Rules = new[] { new Rule { Type = ValidationType.Unique } }
}, input);
field.Validate();
if (expected)
{
Assert.AreEqual(0, field.Errors.Count());
}
else
{
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(ValidationType.Unique, field.Errors.First().Type);
}
}
示例8: CanValidateSize
public void CanValidateSize(DataType type, object input, int size, string sizeType, bool expected)
{
var rules = new[] {new Rule {Type = sizeType, Content = size.ToString(CultureInfo.InvariantCulture)}};
var schema = type == DataType.List
? (ValueNodeSchema)new ListSchema {Rules = rules}
: new FieldSchema
{
DataType = type,
Rules = rules
};
var field = new Field(schema, input);
field.Validate();
if (expected)
{
Assert.AreEqual(0, field.Errors.Count());
}
else
{
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(sizeType, field.Errors.First().Type);
}
}
示例9: CanValidateRequired
public void CanValidateRequired(DataType type, object input, bool expected)
{
var schema1 = type == DataType.List
? (ValueNodeSchema)new ListSchema { Rules = new[] { new Rule { Type = ValidationType.Exist } } }
: new FieldSchema { DataType = type, Rules = new[] { new Rule { Type = ValidationType.Exist } } };
var field1 = new Field(schema1, input);
field1.Validate();
if (expected)
{
Assert.AreEqual(0, field1.Errors.Count());
}
else
{
Assert.AreEqual(1, field1.Errors.Count());
Assert.AreEqual(ValidationType.Exist, field1.Errors.First().Type);
}
}
示例10: CanValidatePositive
public void CanValidatePositive(DataType type, object input, bool expected)
{
var field = new Field(new FieldSchema
{
DataType = type,
Rules = new[] { new Rule { Type = ValidationType.Positive } }
}, input);
field.Validate();
if (expected)
{
Assert.AreEqual(0, field.Errors.Count());
}
else
{
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(ValidationType.Positive, field.Errors.First().Type);
}
}
示例11: CanValidatePattern
public void CanValidatePattern(DataType type, object input, string pattern, bool expected)
{
var field = new Field(new FieldSchema
{
DataType = type,
Rules = new[] {new Rule {Type = ValidationType.Regex, Content = pattern}}
}, input);
field.Validate();
if (expected)
{
Assert.AreEqual(0, field.Errors.Count());
}
else
{
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(ValidationType.Regex, field.Errors.First().Type);
}
}
示例12: CanValidateMultiple
public void CanValidateMultiple()
{
var gte10 = new Rule {Type = ValidationType.Min, Content = "10"};
var lte100 = new Rule {Type = ValidationType.Max, Content = "100"};
var gte120 = new Rule {Type = ValidationType.Min, Content = "120"};
var schema1 = new FieldSchema
{
DataType = DataType.Integer,
Rules = new List<Rule>{gte10, lte100}
};
var field1 = new Field(schema1, "20");
var schema2 = new FieldSchema
{
DataType = DataType.Integer,
Rules = new List<Rule> { lte100, gte120 }
};
var field2 = new Field(schema2, "101");
field1.Validate();
Assert.AreEqual(0, field1.Errors.Count());
field2.Validate();
Assert.AreEqual(2, field2.Errors.Count());
}
示例13: CanValidateEnumeration
public void CanValidateEnumeration(DataType type, object input, string enumType, string listStr, bool expected)
{
var field = new Field(new FieldSchema
{
DataType = type,
Rules = new[] { new Rule { Type = enumType, Content = listStr } }
}, input);
field.Validate();
if (expected)
{
Assert.AreEqual(0, field.Errors.Count());
}
else
{
Assert.AreEqual(1, field.Errors.Count());
Assert.AreEqual(enumType, field.Errors.First().Type);
}
}
示例14: CanValidateCustom
public void CanValidateCustom()
{
var schema = new FieldSchema
{
Rules = new List<Rule>
{
new Rule { Type = "taxNumber" }
}
};
var field1 = new Field(schema, "1234567890");
field1.Validate();
Assert.AreEqual(1, field1.Errors.Count());
Assert.AreEqual("taxNumber", field1.Errors.First().Type);
var field2 = new Field(schema, "4400112594");
field2.Validate();
Assert.AreEqual(0, field2.Errors.Count());
}