public void InclusiveBetween_WhenSerialisedReturnsCorrectValues()
        {
            var anotherIntRules = TestListingHelper.GetDeserialisedValidatorRules(TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.AnotherInt).InclusiveBetween(2, 10)))["validatorList"]["anotherInt"]["range"];

            anotherIntRules["from"].ToObject <int>().Should().Be(2);
            anotherIntRules["to"].ToObject <int>().Should().Be(10);
        }
        public void Length_WhenSerialisedReturnsCorrectValues()
        {
            var forenameRules = TestListingHelper.GetDeserialisedValidatorRules(TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).Length(2, 10)))["validatorList"]["forename"]["length"];

            forenameRules["min"].ToObject <int>().Should().Be(2);
            forenameRules["max"].ToObject <int>().Should().Be(10);
        }
        public void ExclusiveBetween_ReturnsCorrectValues()
        {
            var anotherIntRules = TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.AnotherInt)
                                                                      .ExclusiveBetween(5, 8))
                                  .ValidatorList[nameof(Person.AnotherInt)];

            anotherIntRules["exclusiveRange"].Should().BeOfType(typeof(FromToValues));

            FromToValues values = (FromToValues)anotherIntRules["exclusiveRange"];

            values.From.Should().Be(5);
            values.To.Should().Be(8);
        }
 public void WhenSerialised_ReturnsCorrectMessage() =>
 TestListingHelper.GetDeserialisedValidatorRules(TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).NotEmpty()))["errorList"]["forename"]["required"].ToString().Should().Be("'Forename' must not be empty.");
 public void Types_IncludeChildTypes() =>
 TestListingHelper.GetValidatorRules().TypeList[$"{nameof(Address)}.{nameof(Address.Line1)}"]
 .Should().Be("string");
 public void Validator_IncludesGrandChildValidatorRules() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Address).SetValidator(new AddressValidator()))
 .ValidatorList["Address.Country.Name"].Should().NotBeNull();
Esempio n. 7
0
 public void Equal_ReturnsCorrectMessageForValue() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).Equal("Foo bar"))
 .ErrorList[nameof(Person.Forename)]["compare"].Should().Be("'Forename' must be equal to 'Foo bar'.");
 public void ExactLength_ReturnsCorrectValue() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).Length(10))
 .ValidatorList[key : nameof(Person.Forename)]["exactLength"].Should().Be(10);
 public void Matches_ReturnsRegularExpression() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).Matches("^[A-Za-z]+$"))
 .ValidatorList[key : nameof(Person.Forename)]["regex"].Should().Be("^[A-Za-z]+$");
 public void NotEmpty_ReturnsRequiredRule() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).NotEmpty())
 .ValidatorList[key : nameof(Person.Forename)]["required"].Should().Be(true);
 public void LessThan_ReturnsCorrectLimitValue() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.NullableInt).LessThan(100))
 .ValidatorList[key : nameof(Person.NullableInt)]["lessThan"].Should().Be(100);
 public void Types_IncludeDate() =>
 TestListingHelper.GetValidatorRules().TypeList[nameof(Person.DateOfBirth)]
 .Should().Be("date");
Esempio n. 13
0
 public void Matches_ReturnsCorrectMessage() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).Matches("^[A-Za-z]+$"))
 .ErrorList[nameof(Person.Forename)]["regex"].Should().Be("'Forename' is not in the correct format.");
 public void Types_IncludeBoolean() =>
 TestListingHelper.GetValidatorRules().TypeList[nameof(Person.IsActive)]
 .Should().Be("boolean");
 public void Types_IncludeNumber() =>
 TestListingHelper.GetValidatorRules().TypeList[nameof(Person.Id)]
 .Should().Be("number");
Esempio n. 16
0
 public void ChildValidator_ReturnsCorrectMessage() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Address).SetValidator(new AddressValidator()))
 .ErrorList[$"{nameof(Address)}.{nameof(Address.Line1)}"]["required"].Should().Be("'Line1' must not be empty.");
Esempio n. 17
0
 public void ExclusiveBetween_ReturnsCorrectMessage() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.AnotherInt).ExclusiveBetween(5, 8))
 .ErrorList[nameof(Person.AnotherInt)]["exclusiveRange"].Should().Be("'Another Int' must be between 5 and 8 (exclusive).");
Esempio n. 18
0
 public void EmailAddress_ReturnsCorrectMessage() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Email).EmailAddress())
 .ErrorList[nameof(Person.Email)]["regex"].Should().Be("'Email' is not a valid email address.");
 public void Types_IncludeCollectionTypes() =>
 TestListingHelper.GetValidatorRules().TypeList[$"{nameof(Person.Orders)}.{nameof(Order.Amount)}"]
 .Should().Be("number");
 public void Types_IntegerReturnsNumber() =>
 TestListingHelper.GetValidatorRules().TypeList[nameof(Person.NullableInt)]
 .Should().Be("number");
 public void TwoValidators_ReturnTwoRulesAndMessages() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.NullableInt).NotNull().LessThan(100))
 .ValidatorList[key : nameof(Person.NullableInt)].Count.Should().Be(2);
 public void Types_DecimalReturnsNumber() =>
 TestListingHelper.GetValidatorRules().TypeList[nameof(Person.Discount)]
 .Should().Be("number");
 public void GreaterThanOrEqualTo_ReturnsCorrectLimitValue() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.NullableInt).GreaterThanOrEqualTo(100))
 .ValidatorList[key : nameof(Person.NullableInt)]["greaterThanOrEqualTo"].Should().Be(100);
 public void Types_DoubleReturnsNumber() =>
 TestListingHelper.GetValidatorRules().TypeList[nameof(Person.Age)]
 .Should().Be("number");
 public void Equal_ReturnsCorrectComparisonValue() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).Equal("Foo bar"))
 .ValidatorList[key : nameof(Person.Forename)]["compare"].Should().Be("Foo bar");
 public void Types_FloatOrSingleReturnsNumber() =>
 TestListingHelper.GetValidatorRules().TypeList[nameof(Person.SomeSingleValue)]
 .Should().Be("number");
 public void EmailAddress_ReturnsRegularExpression() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Email).EmailAddress())
 .ValidatorList[key : nameof(Person.Email)]["regex"].Should().NotBeNull();
 public void Types_IncludeString() =>
 TestListingHelper.GetValidatorRules().TypeList[nameof(Person.Surname)]
 .Should().Be("string");
 public void Validator_IncludesCollectionRules() =>
 TestListingHelper.GetValidatorRules(v => v.RuleForEach(x => x.Orders).SetValidator(new OrderValidator()))
 .ValidatorList["Orders.Amount"].Should().NotBeNull();
Esempio n. 30
0
 public void ExactLength_ReturnsCorrectMessage() =>
 TestListingHelper.GetValidatorRules(v => v.RuleFor(x => x.Forename).Length(10))
 .ErrorList[nameof(Person.Forename)]["exactLength"].Should().Be("'Forename' must be 10 characters in length.");