• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TestValidator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TestValidator的典型用法代码示例。如果您正苦于以下问题:C# TestValidator类的具体用法?C# TestValidator怎么用?C# TestValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TestValidator类属于命名空间,在下文中一共展示了TestValidator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Can_access_expression_in_message

        public void Can_access_expression_in_message()
        {
            var v = new TestValidator();
            v.RuleFor(x => x.Forename).Matches(@"^\w\d$").WithMessage("test {RegularExpression}");

            var result = v.Validate(new Person {Forename = ""});
            result.Errors.Single().ErrorMessage.ShouldEqual(@"test ^\w\d$");
        }
开发者ID:yesmarket,项目名称:FluentValidation,代码行数:8,代码来源:RegularExpressionValidatorTests.cs


示例17: EnumValidatorTests

        public EnumValidatorTests()
        {
            CultureScope.SetDefaultCulture();

            validator = new TestValidator {
                v => v.RuleFor(x => x.Gender).IsInEnum()
            };
        }
开发者ID:gordey4doronin,项目名称:FluentValidation,代码行数:8,代码来源:EnumValidatorTests.cs


示例18: Populates_errors

		public void Populates_errors() {
			var validator = new TestValidator {
				v => v.RuleFor(x => x.Surname).NotNull()
			};

			var ex = (ValidationException)typeof(ValidationException).ShouldBeThrownBy(() => validator.ValidateAndThrow(new Person()));
			ex.Errors.Count().ShouldEqual(1);
		}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:8,代码来源:ValidateAndThrowTester.cs


示例19: When_passing_string_to_localizable_lambda_should_convert_to_string_accessor

		public void When_passing_string_to_localizable_lambda_should_convert_to_string_accessor() {
			var validator = new TestValidator() {
				v => v.RuleFor(x => x.Surname).SetValidator(new FooValidator())
			};

			var result = validator.Validate(new Person());
			result.Errors.Single().ErrorMessage.ShouldEqual("foo");
		}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:8,代码来源:PropertyValidatorTester.cs


示例20: Should_store_comparison_type

		public void Should_store_comparison_type() {
			var validator = new TestValidator(v => v.RuleFor(x => x.Forename).NotEqual(x => x.Surname));
			var propertyValidator = validator.CreateDescriptor()
				.GetValidatorsForMember("Forename")
				.OfType<NotEqualValidator>()
				.Single();
			propertyValidator.Comparison.ShouldEqual(Comparison.NotEqual);
		}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:8,代码来源:NotEqualValidatorTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TestViewModel类代码示例发布时间:2022-05-24
下一篇:
C# TestUser类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap