public void SetUp()
        {
            mocks = new MockRepository();
            mockContext = mocks.CreateMock<IApplicationContext>();

            advice = new ParameterValidationAdvice();
            advice.ApplicationContext = mockContext;

            requiredValidator = new RequiredValidator();
            requiredValidator.Actions.Add(new ErrorMessageAction("error.required", "errors"));
        }
        public void TestCollection()
        {
            IList persons = new ArrayList();

            persons.Add(new TestObject("Damjan Tomic", 24));
            persons.Add(new TestObject("Goran Milosavljevic", 24));
            persons.Add(new TestObject("Ivan Cikic", 28));
            
            RequiredValidator req = new RequiredValidator("Name", "true");

            RegularExpressionValidator reg = new RegularExpressionValidator("Name", "true", @"[a-z]*\s[a-z]*");
            reg.Options = RegexOptions.IgnoreCase;
            
            CollectionValidator validator = new CollectionValidator();
            validator.Validators.Add(req);
            validator.Validators.Add(reg);                        
            
            Assert.IsTrue(validator.Validate(persons, new ValidationErrors()));
        }
Ejemplo n.º 3
0
        public void TestValidationErrorsAreCollected()
        {
            IList persons = new ArrayList();

            persons.Add(new TestObject(null, 24));
            persons.Add(new TestObject("Goran Milosavljevic", 24));
            persons.Add(new TestObject("Ivan Cikic", 28));
            persons.Add(new TestObject(null, 20));

            RequiredValidator req = new RequiredValidator("Name", "true");

            req.Actions.Add(new ErrorMessageAction("1", new string[] { "firstProvider", "secondProvider" }));

            CollectionValidator validator = new CollectionValidator(true, true);

            validator.Validators.Add(req);

            IValidationErrors ve = new ValidationErrors();

            Assert.IsFalse(validator.Validate(persons, ve));
            Assert.IsFalse(ve.IsEmpty);
        }
        public void TestNestingCollectionValidator()
        {            
            Society soc = new Society();
            soc.Members.Add(new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian"));
            soc.Members.Add(new Inventor("Mihajlo Pupin", new DateTime(1854, 10, 9), "Serbian"));
            
            
            RequiredValidator req = new RequiredValidator("Name", "true");

            RegularExpressionValidator reg = new RegularExpressionValidator("Name", "true", @"[a-z]*\s[a-z]*");
            reg.Options = RegexOptions.IgnoreCase;
            
            CollectionValidator validator = new CollectionValidator();
            validator.Validators.Add(req);
            validator.Validators.Add(reg);                        
                       
            validator.Context = Expression.Parse("Members");
            
            Assert.IsTrue(validator.Validate(soc, new ValidationErrors()));
            
            validator.Context = null;
            Assert.IsTrue(validator.Validate(soc.Members, new ValidationErrors()));
        }
        public void TestValidationErrorsAreCollected()
        {
            IList persons = new ArrayList();

            persons.Add(new TestObject(null, 24));
            persons.Add(new TestObject("Goran Milosavljevic", 24));
            persons.Add(new TestObject("Ivan Cikic", 28));
            persons.Add(new TestObject(null, 20));

            RequiredValidator req = new RequiredValidator("Name", "true");
            req.Actions.Add(new ErrorMessageAction("1", new string[] { "firstProvider", "secondProvider" }));

            CollectionValidator validator = new CollectionValidator(true,true);
            
            validator.Validators.Add(req);

            IValidationErrors ve = new ValidationErrors();

            Assert.IsFalse(validator.Validate(persons, ve));
            Assert.IsFalse(ve.IsEmpty);
            
        }
 public void TestWithWrongArgumentType()
 {
     RequiredValidator req = new RequiredValidator("Name", "true");
     CollectionValidator validator = new CollectionValidator();
     validator.Validators.Add(req);
     
     TestObject tObj = new TestObject("Damjan Tomic", 24);
     
     //This should cause the ArgumentException because tObj is not a Collection
     Assert.IsTrue(validator.Validate(tObj, new ValidationErrors()));              
 }