Пример #1
0
 public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     return(ExtensibleObjectValidator.GetValidationErrors(
                this,
                validationContext
                ));
 }
Пример #2
0
 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
 }
 public void Should_Validate_If_The_Properties_Are_Valid()
 {
     ExtensibleObjectValidator
     .GetValidationErrors(
         new ExtensiblePersonObject
     {
         ExtraProperties =
         {
             { "Name", "John" },
             { "Age",  "42"   },
         }
     }
         ).Count.ShouldBe(0); //All Valid
 }
Пример #4
0
        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'!
        }
        public void Should_Not_Validate_If_The_Properties_Are_Not_Valid()
        {
            ExtensibleObjectValidator
            .GetValidationErrors(
                new ExtensiblePersonObject()
                ).Count.ShouldBe(2); // Name & Age

            ExtensibleObjectValidator
            .GetValidationErrors(
                new ExtensiblePersonObject
            {
                ExtraProperties =
                {
                    { "Address", new string('x', 256) }
                }
            }
                ).Count.ShouldBe(3); // Name, Age & Address

            ExtensibleObjectValidator
            .GetValidationErrors(
                new ExtensiblePersonObject
            {
                ExtraProperties =
                {
                    { "Age", "42" }
                }
            }
                ).Count.ShouldBe(1); // Name

            ExtensibleObjectValidator
            .GetValidationErrors(
                new ExtensiblePersonObject
            {
                ExtraProperties =
                {
                    { "Address", new string('x', 256) },
                    { "Age",     "100" }
                }
            }
                ).Count.ShouldBe(3); // Name, Age & Address

            ExtensibleObjectValidator
            .GetValidationErrors(
                new ExtensiblePersonObject
            {
                ExtraProperties =
                {
                    { "Name",           "John" },
                    { "Age",            "42"   },
                    { "Password",       "123"  },
                    { "PasswordRepeat", "1256" }
                }
            }
                ).Count.ShouldBe(1); // PasswordRepeat != Password

            ExtensibleObjectValidator
            .GetValidationErrors(
                new ExtensiblePersonObject
            {
                ExtraProperties =
                {
                    { "Name", "BadValue" },
                    { "Age",  "42"       },
                }
            }
                ).Count.ShouldBe(1); //Name is 'BadValue'!
        }