Represents a reference to an externally defined validator object

This class allows validation groups to reference validators that are defined outside of the group itself.

It also allows users to narrow the context for the referenced validator by specifying value for the Context property.

Inheritance: IValidator, IObjectFactoryAware
        public void ContextNarrowing()
        {
            Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
            
            ConditionValidator cv1 = new ConditionValidator("DOB.Year == 1856", null);
            ConditionValidator cv2 = new ConditionValidator("Year == 1856", null);
            
            StaticListableObjectFactory factory = new StaticListableObjectFactory();
            factory.AddObject("cv1", cv1);
            factory.AddObject("cv2", cv2);

            ValidatorReference v1 = new ValidatorReference();
            v1.ObjectFactory = factory;
            v1.Name = "cv1";

            IValidationErrors errors = new ValidationErrors();

            Assert.IsTrue(v1.Validate(context, null, errors));
            Assert.IsTrue(v1.Validate(context, errors));

            ValidatorReference v2 = new ValidatorReference();
            v2.ObjectFactory = factory;
            v2.Name = "cv2";
            v2.Context = Expression.Parse("DOB");

            Assert.IsTrue(v2.Validate(context, null, errors));
            Assert.IsTrue(v2.Validate(context, errors));

            ValidatorReference v3 = new ValidatorReference("false");
            v3.ObjectFactory = factory;
            v3.Name = "cv2";
            v3.Context = Expression.Parse("DOB");

            Assert.IsTrue(v3.Validate(null, errors));
        }
        public void FalseValidatorReferenceNotEvaluatedBecauseWhenExpressionReturnsFalse()
        {
            StaticListableObjectFactory factory = new StaticListableObjectFactory();
            factory.AddObject("validator", new FalseValidator());

            ValidatorReference v = new ValidatorReference("false");
            v.ObjectFactory = factory;
            v.Name = "validator";

            IValidationErrors errors = new ValidationErrors();
            Assert.IsTrue(v.Validate(null, null, errors));
            Assert.IsTrue(v.Validate(null, errors));
        }
        public void FalseValidatorReference()
        {
            StaticListableObjectFactory factory = new StaticListableObjectFactory();
            factory.AddObject("validator", new FalseValidator());

            ValidatorReference v = new ValidatorReference();
            v.ObjectFactory = factory;
            v.Name = "validator";

            IValidationErrors errors = new ValidationErrors();
            Assert.IsFalse(v.Validate(null, null, errors));
            Assert.IsFalse(v.Validate(null, errors));
        }
        public void FalseValidatorReferenceNotEvaluatedBecauseWhenExpressionReturnsFalse()
        {
            StaticListableObjectFactory factory = new StaticListableObjectFactory();

            factory.AddObject("validator", new FalseValidator());

            ValidatorReference v = new ValidatorReference("false");

            v.ObjectFactory = factory;
            v.Name          = "validator";

            IValidationErrors errors = new ValidationErrors();

            Assert.IsTrue(v.Validate(null, null, errors));
            Assert.IsTrue(v.Validate(null, errors));
        }
        public void FalseValidatorReference()
        {
            StaticListableObjectFactory factory = new StaticListableObjectFactory();

            factory.AddObject("validator", new FalseValidator());

            ValidatorReference v = new ValidatorReference();

            v.ObjectFactory = factory;
            v.Name          = "validator";

            IValidationErrors errors = new ValidationErrors();

            Assert.IsFalse(v.Validate(null, null, errors));
            Assert.IsFalse(v.Validate(null, errors));
        }
        public void ContextNarrowing()
        {
            Inventor context = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");

            ConditionValidator cv1 = new ConditionValidator("DOB.Year == 1856", null);
            ConditionValidator cv2 = new ConditionValidator("Year == 1856", null);

            StaticListableObjectFactory factory = new StaticListableObjectFactory();

            factory.AddObject("cv1", cv1);
            factory.AddObject("cv2", cv2);

            ValidatorReference v1 = new ValidatorReference();

            v1.ObjectFactory = factory;
            v1.Name          = "cv1";

            IValidationErrors errors = new ValidationErrors();

            Assert.IsTrue(v1.Validate(context, null, errors));
            Assert.IsTrue(v1.Validate(context, errors));

            ValidatorReference v2 = new ValidatorReference();

            v2.ObjectFactory = factory;
            v2.Name          = "cv2";
            v2.Context       = Expression.Parse("DOB");

            Assert.IsTrue(v2.Validate(context, null, errors));
            Assert.IsTrue(v2.Validate(context, errors));

            ValidatorReference v3 = new ValidatorReference("false");

            v3.ObjectFactory = factory;
            v3.Name          = "cv2";
            v3.Context       = Expression.Parse("DOB");

            Assert.IsTrue(v3.Validate(null, errors));
        }