Example #1
0
        public void PatientMustHaveAtLeastOneValidInsurancePolicy()
        {
            PatientValidator v = new PatientValidator();


            // No policies
            {
                Patient p = getValidPatient_noPolicy();

                // This requires a setter for InsurancePolicies, which is not what i want for any other purpose
                //var result = v.ShouldHaveValidationErrorFor(pat => pat.InsurancePolicies, p);

                // So we do this instead which will break at runtime if the name of the property changes
                var result = v.Validate(p);
                Assert.IsFalse(result.IsValid);
                Assert.IsTrue(result.Errors.Count == 1);
                Assert.IsTrue(result.Errors[0].PropertyName == "InsurancePolicies");
            }

            // Has an invalid policy
            {
                Patient p = getValidPatient_noPolicy();
                p.AddInsurancePolicy(InsurancePolicyUnitTests.getInvalidInsurancePolicy());
                var result = v.Validate(p);
                Assert.IsFalse(result.IsValid);
            }

            // Has an invalid and valid policy
            {
                Patient p = getValidPatient_noPolicy();
                p.AddInsurancePolicy(InsurancePolicyUnitTests.getInvalidInsurancePolicy());
                p.AddInsurancePolicy(InsurancePolicyUnitTests.getValidInsurancePolicy());
                var result = v.Validate(p);
                Assert.IsFalse(result.IsValid);
            }

            {
                // Has only valid policy
                Patient p = getValidPatient_noPolicy();
                p.AddInsurancePolicy(InsurancePolicyUnitTests.getValidInsurancePolicy());
                var result = v.Validate(p);
                Assert.IsTrue(result.IsValid);
            }
        }
Example #2
0
 internal static Patient getValidPatient()
 {
     return(getValidPatient_noPolicy().AddInsurancePolicy(InsurancePolicyUnitTests.getValidInsurancePolicy()));
 }