public void Setup() { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); validator = new TestValidator { v => v.RuleFor(x => x.Email).EmailAddress() }; }
public CreditCardValidatorTests() { CultureScope.SetDefaultCulture(); validator = new TestValidator { v => v.RuleFor(x => x.CreditCard).CreditCard() }; }
public EmailValidatorTests() { CultureScope.SetDefaultCulture(); validator = new TestValidator { v => v.RuleFor(x => x.Email).EmailAddress() }; }
public void Throws_exception() { var validator = new TestValidator { v => v.RuleFor(x => x.Surname).NotNull() }; typeof(ValidationException).ShouldBeThrownBy(() => validator.ValidateAndThrow(new Person())); }
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); }
public PredicateValidatorTester() { CultureScope.SetDefaultCulture(); validator = new TestValidator { v => v.RuleFor(x => x.Forename).Must(forename => forename == "Jeremy") }; }
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); }
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")); }
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(); }
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"); }
public void Setup() { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); validator = new TestValidator { v => v.RuleFor(x => x.Forename).Must(forename => forename == "Jeremy") }; }
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(); }
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); }
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(); }
public RegularExpressionValidatorTests() { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); validator = new TestValidator { v => v.RuleFor(x => x.Surname).Matches(@"^\w\d$") }; }
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(); }
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(); }
public void Can_access_expression_in_message_lambda_regex() { var v = new TestValidator(); v.RuleFor(x => x.Forename).Matches(x => x.AnotherRegex).WithMessage("test {RegularExpression}"); var result = v.Validate(new Person { Forename = "", AnotherRegex = new System.Text.RegularExpressions.Regex(@"^\w\d$") }); result.Errors.Single().ErrorMessage.ShouldEqual(@"test ^\w\d$"); }
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(); }
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(); }
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$"); }
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"); }
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); }
public EnumValidatorTests() { CultureScope.SetDefaultCulture(); validator = new TestValidator { v => v.RuleFor(x => x.Gender).IsInEnum() }; }
public void Setup() { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); _validator = new TestValidator { v => v.RuleFor(x => x.CreditCard).IsCreditCard() }; }
public PredicateValidatorTester() { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); validator = new TestValidator { v => v.RuleFor(x => x.Forename).Must(forename => forename == "Jeremy") }; }
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."); }
public void When_validation_fails_error_should_be_set() { var validator = new TestValidator { v => v.RuleFor(x => x.Surname).NotEmpty() }; var result = validator.Validate(new Person { Surname = null }); result.Errors.Single().ErrorMessage.ShouldEqual("'Surname' should not be empty."); }
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"); }
public CreditCardValidatorTests() { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); validator = new TestValidator { v => v.RuleFor(x => x.CreditCard).CreditCard() }; }
public ChallengeParticipantsControllerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator validator) : base( testData, testMapper, validator) { }
public TransactionTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base(testData, testMapper, testValidator) { }
public ChallengePostRequestValidatorTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator validator) : base( testData, testMapper, validator) { }
public CashierTestFileStorageTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public ParticipantQueryTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator validator) : base(testData, testMapper, validator) { }
public MatchTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator validator) : base(testData, testMapper, validator) { }
public DoxatagHistoryControllerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public ChallengeScoreboardTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public ClanMemberRemovedIntegrationEventHandlerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public AddressBookControllerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public PromotionRedeemedDomainEventTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public AccountServiceTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public ParticipantMatchesControllerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator validator) : base( testData, testMapper, validator) { }
public ActionResult App(Test account) { //validate my data TestValidator validator = new TestValidator(); ValidationResult result = validator.Validate(account); int time; if (Session["time"] == null) { time = 0; Session["time"] = time; return(View("App", account)); } time = (int)Session["time"]; Session["time"] = time + 1; if (result.IsValid == false) { if (time >= 3) { // Show the captcha. account.b = true; ViewBag.ErrMessage = "Invalid Captcha"; return(View("App", account)); } else { ViewBag.Err = "Invalid CouponCode"; return(View("App", account)); } } else { return(View("Success", account)); } /* if (count <= 3) * { * count=count +1; * * ViewBag.error = "Invalid CouponCode"; * return View("Index", account); * } * else * { * * return View("captcha",account); * } * } * * else * { * ViewBag.account = account; * return View("Success"); * } * } * */ /* public ActionResult Check(Account acc) * { * * * if (!this.IsCaptchaValid("")) * { * ViewBag.error = "Invalid Captcha"; * return View("captcha", acc); * } * else * { * ViewBag.account = acc; * return View("Success"); * * } * }*/ }
public ChallengePayoutBucketSizeTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public IdentityTestFileStorageTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public ChallengeRepositoryTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator validator) : base(testData, testMapper, validator) { }
public PasswordControllerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public UserWithdrawFailedIntegrationEventHandlerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public void SetUp() { this.validator = new TestValidator(); this.report = this.validator.Validate(new TestClass()).Result; }
public ChallengeSynchronizedIntegrationEventHandlerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public UserGameCredentialRemovedIntegrationEventHandlerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public void Setup() { _validator = new TestValidator(); _fixture = CreateFixture(); }
public UserTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base(testData, testMapper, testValidator) { }
public ChallengeServiceTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public AccountDecoratorTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base(testData, testMapper, testValidator) { }
public ChallengeParticipantRegisteredIntegrationEventHandlerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base(testData, testMapper, testValidator) { }
public PromotionControllerTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public ChallengePayoutStrategyTest(TestDataFixture testData, TestMapperFixture testMapper, TestValidator testValidator) : base( testData, testMapper, testValidator) { }
public void TestDifferentDsl() { //Create a test using method chaining var testA = Test("A cool test") .Samples(250) .Generator( Pair(Triplet(Generators.Character, Str, Generators.Float), Array(PosSmallInteger))) .Property("A property") .Then(i => (1 + 2).I()) .BeginBlock() .Equals(i => 1 + 2) .Or() .Equals(i => 2 + 1) .EndBlock() .And() .BeginBlock() .Equals(0) .And() .BeginBlock() .IsNotEqual(int.MaxValue) .Or() .IsNotEqual(1) .EndBlock() .EndBlock() .Property("Is not the difference") .Then(i => (1 + 2).I()) .IsNotEqual(i => 1 - 2) .Build(); //Create the exact same test using nested lambdas var testB = Test("A cool test") .Samples(250) .Generator( Pair(Triplet(Generators.Character, Str, Generators.Float), Array(PosSmallInteger))) .Property("A property") .ThenLambda(i => (1 + 2).I()) .Satisfies(b => b.And( _ => b.Or( __ => b.Equals(i => 1 + 2), __ => b.Equals(i => 2 + 1) ), _ => b.And( __ => b.Equals(0), __ => b.Or( ___ => b.IsNotEqual(int.MaxValue), ___ => b.IsNotEqual(1) ) ) ) ) .Property("Is not the difference") .ThenLambda(i => (1 + 2).I()) .Satisfies(b => b.IsNotEqual(i => 1 - 2)) .Build(); var validator = TestValidator.Create(testA, testB); validator.Assert(); }