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); }
private static Validator CreateOperationDateValidator(BoundDate b) { var v = new Validator(); var i = new ItemValidator(); i.AddSecondaryConstraint(b); v.AddItemValidator(i, "operation_date", typeof(DateTime)); return(v); }
private static Validator CreateParentDobValidator(BoundDate b) { var v = new Validator(); var i = new ItemValidator(); i.AddSecondaryConstraint(b); v.AddItemValidator(i, "parent_dob", typeof(DateTime)); return(v); }
private Validator CreateChiAndAgeValidators() { var validator = new Validator(); var vChi = new ItemValidator { PrimaryConstraint = (PrimaryConstraint)Validator.CreateConstraint("chi", Consequence.Wrong) }; var vAge = new ItemValidator(); var age = (BoundDouble)Validator.CreateConstraint("bounddouble", Consequence.Wrong); age.Lower = 0; age.Upper = 120; vAge.AddSecondaryConstraint(age); validator.AddItemValidator(vChi, "chi", typeof(string)); validator.AddItemValidator(vAge, "age", typeof(int)); return(validator); }
public void simple_integer_bounds() { var v = new Validator(); var b = (BoundDouble)Validator.CreateConstraint("bounddouble", Consequence.Wrong); b.Lower = 5; b.Upper = 120; var i = new ItemValidator(); i.AddSecondaryConstraint(b); v.AddItemValidator(i, "number", typeof(int)); var d = new Dictionary <string, object>(); d.Add("number", 119); Assert.IsNull(v.Validate(d)); }
public void validation_scenario_CHI_and_age() { // 1. Create a new Validator - this is responsible for validating the entire target object (dictionary) var validator = new Validator(); // 2. Create new ItemValidator - this is respoonsible for validating an individual item in the target object var chi = new ItemValidator(); // 3. Set the ItemValidator's PrimaryConstraint (must be valid CHI) // (using Validator's CreateConstraint() method to create a Primary Constraint (CHI)) chi.PrimaryConstraint = (PrimaryConstraint)Validator.CreateConstraint("chi", Consequence.Wrong); // 4. Add the ItemValidator to our Validator, specifying the item it should validate against validator.AddItemValidator(chi, "chi", typeof(string)); // 5. Create a new ItemValidator (in this case, must be valid CHI and sensible age value) var age = new ItemValidator(); // 6. No PrimaryConstraint. In this case we ADD a SecondaryConstraint (age) var ageConstraint = (BoundDouble)Validator.CreateConstraint("bounddouble", Consequence.Wrong); ageConstraint.Lower = 0; ageConstraint.Upper = 30; age.AddSecondaryConstraint(ageConstraint); // 7. Add the ItemValidator to our Validator, specifying the item it should validate against validator.AddItemValidator(age, "age", typeof(int)); // 8. Create a target object (dictionary) against which to validate var domainObject = new Dictionary <string, object>(); domainObject.Add("chi", TestConstants._VALID_CHI); domainObject.Add("age", 12); // 9. Validate, passing in the target object to be validated against Assert.IsNull(validator.Validate(domainObject)); }