Example #1
0
 public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     return(ExtensibleObjectValidator.GetValidationErrors(
                this,
                validationContext
                ));
 }
 public void Should_Validate_If_The_Properties_Are_Valid()
 {
     ExtensibleObjectValidator
     .GetValidationErrors(
         new ExtensiblePersonObject()
         .SetProperty("Name", "John", validate: false)
         .SetProperty("Age", 42, validate: false)
         ).Count.ShouldBe(0); //All Valid
 }
Example #3
0
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var results = ExtensibleObjectValidator.GetValidationErrors(this, validationContext);

            foreach (var result in ValidateReceiver(validationContext))
            {
                results.Add(result);
            }

            return(results);
        }
Example #4
0
    public static TSource SetProperty <TSource>(
        this TSource source,
        string name,
        object value,
        bool validate = true)
        where TSource : IHasExtraProperties
    {
        if (validate)
        {
            ExtensibleObjectValidator.CheckValue(source, name, value);
        }

        source.ExtraProperties[name] = value;

        return(source);
    }
    public void Should_Not_Validate_If_The_Properties_Are_Not_Valid()
    {
        ExtensibleObjectValidator
        .GetValidationErrors(
            new ExtensiblePersonObject()
            ).Count.ShouldBe(2); // Name & Age

        ExtensibleObjectValidator
        .GetValidationErrors(
            new ExtensiblePersonObject()
            .SetProperty("Address", new string('x', 256), validate: false)
            ).Count.ShouldBe(3); // Name, Age & Address

        ExtensibleObjectValidator
        .GetValidationErrors(
            new ExtensiblePersonObject()
            .SetProperty("Age", 42, validate: false)
            ).Count.ShouldBe(1); // Name

        ExtensibleObjectValidator
        .GetValidationErrors(
            new ExtensiblePersonObject()
            .SetProperty("Address", new string('x', 256), validate: false)
            .SetProperty("Age", 100, validate: false)
            ).Count.ShouldBe(3); // Name, Age & Address

        ExtensibleObjectValidator
        .GetValidationErrors(
            new ExtensiblePersonObject()
            .SetProperty("Name", "John", validate: false)
            .SetProperty("Age", 42, validate: false)
            .SetProperty("Password", "123", validate: false)
            .SetProperty("PasswordRepeat", "1256", validate: false)
            ).Count.ShouldBe(1); // PasswordRepeat != Password

        ExtensibleObjectValidator
        .GetValidationErrors(
            new ExtensiblePersonObject()
            .SetProperty("Name", "BadValue", validate: false)
            .SetProperty("Age", 42, validate: false)
            ).Count.ShouldBe(1); //Name is 'BadValue'!
    }