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 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));
        }
Example #3
0
        public void ValidateSetsDefaultVariables()
        {
            TestPage page = new TestPage(HttpContext.Current);
            TestUserControl c1 = new TestUserControl();
            page.Controls.Add(c1);

            ConditionValidator v1 = new ConditionValidator("#page == #this.Page", null);
            ConditionValidator v2 = new ConditionValidator("#usercontrol == #this", null);

            Assert.IsTrue(c1.Validate(c1, v1, v2));
        }