当前位置: 首页>>代码示例>>C#>>正文


C# TestValidator类代码示例

本文整理汇总了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()));
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:7,代码来源:ValidateAndThrowTester.cs

示例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();
        }
开发者ID:cjberg,项目名称:FluentValidation,代码行数:7,代码来源:EqualValidatorTests.cs

示例3: EmailValidatorTests

		public EmailValidatorTests() {
            CultureScope.SetDefaultCulture();

            validator = new TestValidator {
				v => v.RuleFor(x => x.Email).EmailAddress()
			};
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:7,代码来源:EmailValidatorTests.cs

示例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);
		}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:7,代码来源:EqualValidatorTests.cs

示例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")
     };
 }
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:7,代码来源:PredicateValidatorTester.cs

示例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);
        }
开发者ID:yesmarket,项目名称:FluentValidation,代码行数:25,代码来源:ExactLengthValidatorTester.cs

示例7: PredicateValidatorTester

 public PredicateValidatorTester()
 {
     CultureScope.SetDefaultCulture();
     validator = new TestValidator {
         v => v.RuleFor(x => x.Forename).Must(forename => forename == "Jeremy")
     };
 }
开发者ID:regisbsb,项目名称:FluentValidation,代码行数:7,代码来源:PredicateValidatorTester.cs

示例8: CreditCardValidatorTests

		public CreditCardValidatorTests() {
			CultureScope.SetDefaultCulture();

			validator = new TestValidator {
				v => v.RuleFor(x => x.CreditCard).CreditCard()
			};
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:7,代码来源:CreditCardValidatorTests.cs

示例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"));
		}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:7,代码来源:EqualValidatorTests.cs

示例10: Setup

		public void Setup() {
			Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

			validator = new TestValidator {
				v => v.RuleFor(x => x.Email).EmailAddress()
			};
		}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:7,代码来源:EmailValidatorTests.cs

示例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();
		}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:7,代码来源:ValidateAndThrowTester.cs

示例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");
 }
开发者ID:Tigraine,项目名称:FluentValidation,代码行数:7,代码来源:LocalisedMessagesTester.cs

示例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();
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:8,代码来源:NotEmptyTester.cs

示例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();
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:8,代码来源:NotEmptyTester.cs

示例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();
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:8,代码来源:NotEmptyTester.cs


注:本文中的TestValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。