public void is_valid_should_work()
        {
            var person = new Person();


            var entityValidator = new EntityValidator();

            entityValidator.IsValid(person).Should().Be.False();

            person.Age  = 20;
            person.Name = "José F. Romaniello";
            entityValidator.IsValid(person).Should().Be.True();
        }
Esempio n. 2
0
        public void is_valid_should_work()
        {
            var person = new Person();


            var entityValidator = new EntityValidator(new ValidatorRunner(new CachedValidationRegistry()));

            entityValidator.IsValid(person).Should().Be.False();

            person.Age  = 20;
            person.Name = "José F. Romaniello";
            entityValidator.IsValid(person).Should().Be.True();
        }
Esempio n. 3
0
        private void Validate(T entity)
        {
            var validator = new EntityValidator();

            if (validator.IsValid(entity) == false)
            {
                throw new UcoinValidationException(validator.GetInvalidMessages());
            }
        }
Esempio n. 4
0
        public void ThrowExceptionIfInvalid()
        {
            var validator = new EntityValidator();

            if (!validator.IsValid(this))
            {
                throw new CustomValidationException(validator.GetInvalidMessages());
            }
        }
Esempio n. 5
0
        public void Add(TEntity item)
        {
            var context = new EntityValidtionContext <TEntity>(item);
            var errors  = new List <String>();

            if (EntityValidator <TEntity> .IsValid(item, context, errors))
            {
                _items.Add(item);
            }
            else
            {
                /* foreach (var error in errors)
                 *   throw new Exception(error);*/
            }
        }
Esempio n. 6
0
        private void Validate(IEnumerable <T> entities)
        {
            var validator = new EntityValidator();
            var errorList = new List <string>();

            foreach (var e in entities)
            {
                if (validator.IsValid(e) == false)
                {
                    errorList.AddRange(validator.GetInvalidMessages());
                }
            }
            if (errorList.Any())
            {
                throw new UcoinValidationException(errorList);
            }
        }
Esempio n. 7
0
        public void The_attributes_on_the_properties_should_be_used_for_validation()
        {
            IValidator<Member> validator = new EntityValidator<Member>();

            Member member = new Member();

            IEnumerable<IViolation> violations;

            member.Validate(validator, out violations);

            Assert.That(validator.IsValid(member, out violations), Is.False);

            List<IViolation> violationList = new List<IViolation>(violations);

            Assert.That(violationList.Count, Is.EqualTo(2));

            Assert.That(violationList[0], Is.TypeOf(typeof(NullValueViolation)));
            Assert.That(violationList[1], Is.TypeOf(typeof(NullValueViolation)));
        }