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


C# TestValidator.Validate方法代码示例

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


在下文中一共展示了TestValidator.Validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Validates_with_nullable_property

		public void Validates_with_nullable_property() {
			var validator = new TestValidator(v => v.RuleFor(x => x.Id).LessThanOrEqualTo(x => x.NullableInt));

			var resultNull = validator.Validate(new Person { Id = 0, NullableInt = null });
			var resultLess = validator.Validate(new Person { Id = 0, NullableInt = -1 });
			var resultEqual = validator.Validate(new Person { Id = 0, NullableInt = 0 });
			var resultMore = validator.Validate(new Person { Id = 0, NullableInt = 1 });

			resultNull.IsValid.ShouldBeFalse();
			resultLess.IsValid.ShouldBeFalse();
			resultEqual.IsValid.ShouldBeTrue();
			resultMore.IsValid.ShouldBeTrue();
		}
开发者ID:JeremySkinner,项目名称:FluentValidation,代码行数:13,代码来源:LessThanOrEqualToValidatorTester.cs

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: When_value_is_empty_string_validator_should_pass

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

			var result = validator.Validate(new Person { Surname = "" });
			result.IsValid.ShouldBeTrue();
		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:8,代码来源:EmptyTester.cs

示例8: 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

示例9: 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

示例10: 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

示例11: Validates_across_properties

		public void Validates_across_properties() {
			var validator = new TestValidator(
				v => v.RuleFor(x => x.Forename).NotEqual(x => x.Surname)
			);

			var result = validator.Validate(new Person { Surname = "foo", Forename = "foo" });
			result.IsValid.ShouldBeFalse();
		}
开发者ID:Rocketmakers,项目名称:FluentValidation,代码行数:8,代码来源:NotEqualValidatorTests.cs

示例12: Uses_localized_name

		public void Uses_localized_name() {
			var validator = new TestValidator {
				v => v.RuleFor(x => x.Surname).NotNull().WithLocalizedName(() => MyResources.CustomProperty)
			};

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

示例13: Resolves_nested_properties

		public void Resolves_nested_properties() {
			var validator = new TestValidator {
				v => v.RuleFor(x => x.Address.Country).NotNull()
			};

			var error = validator.Validate(new Person { Address = new Address() }).Errors.Single();
			error.PropertyName.ShouldEqual("Address.Country");

		}
开发者ID:jango2015,项目名称:FluentValidation,代码行数:9,代码来源:NameResolutionPluggabilityTester.cs

示例14: Can_use_placeholders_with_localized_messages_using_expressions

        public void Can_use_placeholders_with_localized_messages_using_expressions()
        {
            var validator = new TestValidator {
                v => v.RuleFor(x => x.Surname).NotNull().WithLocalizedMessage(() => TestMessages.PlaceholderMessage, x => 1)
            };

            var result = validator.Validate(new Person());
            result.Errors.Single().ErrorMessage.ShouldEqual("Test 1");
        }
开发者ID:xelossan,项目名称:FluentValidation,代码行数:9,代码来源:LocalisedMessagesTester.cs

示例15: When_input_is_null_then_the_validator_should_pass

        public void When_input_is_null_then_the_validator_should_pass()
        {
            var validator = new TestValidator {
                v => v.RuleFor(x => x.Surname).Length(5)
            };

            var result = validator.Validate(new Person {Surname = null});
            result.IsValid.ShouldBeTrue();
        }
开发者ID:emisand,项目名称:FluentValidation,代码行数:9,代码来源:LengthValidatorTests.cs


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