public void CanValidateElement()
        {
            var validCollection = TestingDataFactory.ElementValidation.SimpleRange(3, 5);
            var invalidCollection = TestingDataFactory.ElementValidation.SimpleRange(1, 6);
            var validator = new ElementValidator<int>();
            validator.CreateRule().LessThan(6).GreaterThan(2);

            Assert.IsTrue(validator.Validate(validCollection).IsValid);
            Assert.IsFalse(validator.Validate(invalidCollection).IsValid);
        }
        public void CanSetErrorMessage()
        {
            var invalidCollection = TestingDataFactory.ElementValidation.SimpleRange(1, 6);
            var validator         = new ElementValidator <int>();

            validator.CreateRule().LessThan(6).GreaterThan(2);
            validator.SetErrorMessage(ErrorMessageText);
            var result = validator.Validate(invalidCollection);

            Assert.AreEqual(result.First().ErrorMessage, ErrorMessageText);
        }
        public void CanValidateElement()
        {
            var validCollection   = TestingDataFactory.ElementValidation.SimpleRange(3, 5);
            var invalidCollection = TestingDataFactory.ElementValidation.SimpleRange(1, 6);
            var validator         = new ElementValidator <int>();

            validator.CreateRule().LessThan(6).GreaterThan(2);

            Assert.IsTrue(validator.Validate(validCollection).IsValid);
            Assert.IsFalse(validator.Validate(invalidCollection).IsValid);
        }
        public void CanValidateElementAndProperty()
        {
            var nullFirstNameCollection = TestingDataFactory.ElementValidation.CollectionWithNullFirstNames();
            var emptyLastNameCollection = TestingDataFactory.ElementValidation.CollectionWithEmptyLastNames();
            var nullElementCollection = TestingDataFactory.ElementValidation.CollectionWithNullElement();

            var compositeValidator = new ElementValidator<GenericParameter>();
            compositeValidator.CreatePropertyRule(x => x.LastName).NotEmpty();
            compositeValidator.CreateRule().NotNull();

            Assert.IsTrue(compositeValidator.Validate(nullFirstNameCollection).IsValid);
            Assert.IsFalse(compositeValidator.Validate(emptyLastNameCollection).IsValid);
            Assert.IsFalse(compositeValidator.Validate(nullElementCollection).IsValid);
        }
        public void CanValidateElementAndProperty()
        {
            var nullFirstNameCollection = TestingDataFactory.ElementValidation.CollectionWithNullFirstNames();
            var emptyLastNameCollection = TestingDataFactory.ElementValidation.CollectionWithEmptyLastNames();
            var nullElementCollection   = TestingDataFactory.ElementValidation.CollectionWithNullElement();

            var compositeValidator = new ElementValidator <GenericParameter>();

            compositeValidator.CreatePropertyRule(x => x.LastName).NotEmpty();
            compositeValidator.CreateRule().NotNull();

            Assert.IsTrue(compositeValidator.Validate(nullFirstNameCollection).IsValid);
            Assert.IsFalse(compositeValidator.Validate(emptyLastNameCollection).IsValid);
            Assert.IsFalse(compositeValidator.Validate(nullElementCollection).IsValid);
        }
        public void CanUseElementAndFluentValidation()
        {
            var nullFirstNameCollection = TestingDataFactory.ElementValidation.CollectionWithNullFirstNames();
            var emptyLastNameCollection = TestingDataFactory.ElementValidation.CollectionWithEmptyLastNames();
            var nullElementCollection   = TestingDataFactory.ElementValidation.CollectionWithNullElement();

            var compositeValidator = new ElementValidator <GenericParameter>();

            compositeValidator.AddValidator(new InlineValidator <GenericParameter>
            {
                v => v.RuleFor(x => x.LastName).NotEmpty()
            });
            compositeValidator.CreateRule().NotNull();

            Assert.IsTrue(compositeValidator.Validate(nullFirstNameCollection).IsValid);
            Assert.IsFalse(compositeValidator.Validate(emptyLastNameCollection).IsValid);
            Assert.IsFalse(compositeValidator.Validate(nullElementCollection).IsValid);
        }
        public void CanSetErrorMessage()
        {
            var invalidCollection = TestingDataFactory.ElementValidation.SimpleRange(1, 6);
            var validator = new ElementValidator<int>();
            validator.CreateRule().LessThan(6).GreaterThan(2);
            validator.SetErrorMessage(ErrorMessageText);
            var result = validator.Validate(invalidCollection);

            Assert.AreEqual(result.First().ErrorMessage, ErrorMessageText);
        }
        public void CanValidateByProppertyAndElementAndFluentValidation()
        {
            var nullFirstNameCollection = TestingDataFactory.ElementValidation.CollectionWithNullFirstNames();
            var shortFirstNameCollection = TestingDataFactory.ElementValidation.CollectionWithShortFirstNames();
            var emptyLastNameCollection = TestingDataFactory.ElementValidation.CollectionWithEmptyLastNames();
            var nullElementCollection = TestingDataFactory.ElementValidation.CollectionWithNullElement();

            var compositeValidator = new ElementValidator<GenericParameter>();
            compositeValidator.AddValidator(new InlineValidator<GenericParameter>
                                                {
                                                    v => v.RuleFor(x => x.LastName).NotEmpty()
                                                });
            compositeValidator.CreateRule().NotNull();
            compositeValidator.CreatePropertyRule(x => x.FirstName).NotEmpty();

            Assert.IsFalse(compositeValidator.Validate(nullFirstNameCollection).IsValid);
            Assert.IsFalse(compositeValidator.Validate(emptyLastNameCollection).IsValid);
            Assert.IsFalse(compositeValidator.Validate(nullElementCollection).IsValid);
            Assert.IsTrue(compositeValidator.Validate(shortFirstNameCollection).IsValid);
        }