本文整理汇总了C#中TestValidator类的典型用法代码示例。如果您正苦于以下问题:C# TestValidator类的具体用法?C# TestValidator怎么用?C# TestValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestValidator类属于命名空间,在下文中一共展示了TestValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Throws_exception
public void Throws_exception() {
var validator = new TestValidator {
v => v.RuleFor(x => x.Surname).NotNull()
};
typeof(ValidationException).ShouldBeThrownBy(() => validator.ValidateAndThrow(new Person()));
}
示例2: Should_succeed_on_case_insensitive_comparison
public void Should_succeed_on_case_insensitive_comparison()
{
var validator = new TestValidator { v => v.RuleFor(x => x.Surname).Equal("FOO", StringComparer.OrdinalIgnoreCase) };
var result = validator.Validate(new Person { Surname = "foo" });
result.IsValid.ShouldBeTrue();
}
示例3: EmailValidatorTests
public EmailValidatorTests() {
CultureScope.SetDefaultCulture();
validator = new TestValidator {
v => v.RuleFor(x => x.Email).EmailAddress()
};
}
示例4: Should_store_comparison_type
public void Should_store_comparison_type() {
var validator = new TestValidator { v => v.RuleFor(x => x.Surname).Equal("Foo") };
var descriptor = validator.CreateDescriptor();
var propertyValidator = descriptor.GetValidatorsForMember("Surname").Cast<EqualValidator>().Single();
propertyValidator.Comparison.ShouldEqual(Comparison.Equal);
}
示例5: Setup
public void Setup()
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
validator = new TestValidator {
v => v.RuleFor(x => x.Forename).Must(forename => forename == "Jeremy")
};
}
示例6: When_exact_length_rule_failes_error_should_have_exact_length_error_errorcode
public void When_exact_length_rule_failes_error_should_have_exact_length_error_errorcode()
{
var validator = new TestValidator { v => v.RuleFor(x => x.Surname).Length(2) };
var result = validator.Validate(new Person() { Surname = "test" });
var error = result.Errors.SingleOrDefault(e => e.ErrorCode == "exact_length_error");
error.ShouldNotBeNull();
error.PropertyName.ShouldEqual("Surname");
error.AttemptedValue.ShouldEqual("test");
error.FormattedMessageArguments.Length.ShouldEqual(0);
error.FormattedMessagePlaceholderValues.Count.ShouldEqual(5);
error.FormattedMessagePlaceholderValues.ContainsKey("PropertyName").ShouldBeTrue();
error.FormattedMessagePlaceholderValues.ContainsKey("PropertyValue").ShouldBeTrue();
error.FormattedMessagePlaceholderValues.ContainsKey("MinLength").ShouldBeTrue();
error.FormattedMessagePlaceholderValues.ContainsKey("MaxLength").ShouldBeTrue();
error.FormattedMessagePlaceholderValues.ContainsKey("TotalLength").ShouldBeTrue();
error.FormattedMessagePlaceholderValues["PropertyName"].ShouldEqual("Surname");
error.FormattedMessagePlaceholderValues["PropertyValue"].ShouldEqual("test");
error.FormattedMessagePlaceholderValues["MinLength"].ShouldEqual(2);
error.FormattedMessagePlaceholderValues["MaxLength"].ShouldEqual(2);
error.FormattedMessagePlaceholderValues["TotalLength"].ShouldEqual(4);
}
示例7: PredicateValidatorTester
public PredicateValidatorTester()
{
CultureScope.SetDefaultCulture();
validator = new TestValidator {
v => v.RuleFor(x => x.Forename).Must(forename => forename == "Jeremy")
};
}
示例8: CreditCardValidatorTests
public CreditCardValidatorTests() {
CultureScope.SetDefaultCulture();
validator = new TestValidator {
v => v.RuleFor(x => x.CreditCard).CreditCard()
};
}
示例9: Should_store_property_to_compare
public void Should_store_property_to_compare() {
var validator = new TestValidator { v => v.RuleFor(x => x.Forename).Equal(x => x.Surname) };
var descriptor = validator.CreateDescriptor();
var propertyValidator = descriptor.GetValidatorsForMember("Forename").Cast<EqualValidator>().Single();
propertyValidator.MemberToCompare.ShouldEqual(typeof(Person).GetProperty("Surname"));
}
示例10: Setup
public void Setup() {
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
validator = new TestValidator {
v => v.RuleFor(x => x.Email).EmailAddress()
};
}
示例11: Does_not_throw_when_valid_async
public void Does_not_throw_when_valid_async() {
var validator = new TestValidator {
v => v.RuleFor(x => x.Surname).NotNull()
};
validator.ValidateAndThrowAsync(new Person { Surname = "foo" }).Wait();
}
示例12: Sets_localised_message_via_expression
public void Sets_localised_message_via_expression()
{
var validator = new TestValidator();
validator.RuleFor(x => x.Surname).NotEmpty().WithLocalizedMessage(() => MyResources.notempty_error);
var result = validator.Validate(new Person());
result.Errors.Single().ErrorMessage.ShouldEqual("foo");
}
示例13: When_value_is_Default_for_type_validator_should_fail_datetime
public void When_value_is_Default_for_type_validator_should_fail_datetime() {
var validator = new TestValidator {
v => v.RuleFor(x => x.DateOfBirth).NotEmpty()
};
var result = validator.Validate(new Person { DateOfBirth = default(DateTime) });
result.IsValid.ShouldBeFalse();
}
示例14: When_value_is_whitespace_validation_should_fail
public void When_value_is_whitespace_validation_should_fail() {
var validator = new TestValidator {
v => v.RuleFor(x => x.Surname).NotEmpty()
};
var result = validator.Validate(new Person { Surname = " " });
result.IsValid.ShouldBeFalse();
}
示例15: When_there_is_a_value_then_the_validator_should_pass
public void When_there_is_a_value_then_the_validator_should_pass() {
var validator = new TestValidator {
v => v.RuleFor(x => x.Surname).NotEmpty()
};
var result = validator.Validate(new Person { Surname = "Foo" });
result.IsValid.ShouldBeTrue();
}