예제 #1
0
        public void Validate_WhenMultipleErrors_ReturnsAllErrors()
        {
            var validator = new Validator();

            var chi = new ItemValidator();

            chi.PrimaryConstraint = (PrimaryConstraint)Validator.CreateConstraint("chi", Consequence.Wrong);
            var prediction = new Prediction(new ChiSexPredictor(), "gender");

            chi.AddSecondaryConstraint(prediction);
            validator.AddItemValidator(chi, "chi", typeof(string));

            var         age           = new ItemValidator();
            BoundDouble ageConstraint = (BoundDouble)Validator.CreateConstraint("bounddouble", Consequence.Wrong);

            ageConstraint.Lower = 0;
            ageConstraint.Upper = 30;
            age.AddSecondaryConstraint(ageConstraint);
            validator.AddItemValidator(age, "age", typeof(int));

            var row = new Dictionary <string, object>();

            row.Add("chi", TestConstants._INVALID_CHI_CHECKSUM);
            row.Add("age", 31);
            row.Add("gender", "F");

            ValidationFailure result = validator.Validate(row);

            Assert.AreEqual(2, result.GetExceptionList().Count);
        }
예제 #2
0
        public void must_occur_before_field_INVALID_violation_report()
        {
            var b = (BoundDate)Validator.CreateConstraint("bounddate", Consequence.Wrong);

            b.Lower          = DateTime.MinValue;
            b.UpperFieldName = "dob";

            var v = CreateParentDobValidator(b);

            ValidationFailure result = v.Validate(TestConstants.ParentDobOccursAfterDob);

            if (result == null)
            {
                Assert.Fail();
            }

            List <ValidationFailure> l = result.GetExceptionList();

            StringAssert.EndsWith("Expected a date less than [" + b.UpperFieldName + "].", l[0].Message);
            Console.WriteLine(result.Message);
        }