public void CanValidateElementByProperties()
        {
            var nullFirstNameCollection = TestingDataFactory.ElementValidation.CollectionWithNullFirstNames();
            var emptyLastNameCollection = TestingDataFactory.ElementValidation.CollectionWithEmptyLastNames();
            var nullElementCollection   = TestingDataFactory.ElementValidation.CollectionWithNullElement();

            var notNullFirstNameValidator = new ElementValidator <GenericParameter>();

            notNullFirstNameValidator.CreatePropertyRule(x => x.FirstName).NotNull();

            var notEmptyLastNameValidator = new ElementValidator <GenericParameter>();

            notEmptyLastNameValidator.CreatePropertyRule(x => x.LastName).NotEmpty();

            var compositePropertiesValidator = new ElementValidator <GenericParameter>();

            compositePropertiesValidator.CreatePropertyRule(x => x.FirstName).NotNull();
            compositePropertiesValidator.CreatePropertyRule(x => x.LastName).NotEmpty();

            Assert.IsTrue(notNullFirstNameValidator.Validate(emptyLastNameCollection).IsValid);
            Assert.IsTrue(notEmptyLastNameValidator.Validate(nullFirstNameCollection).IsValid);

            Assert.IsFalse(notNullFirstNameValidator.Validate(nullFirstNameCollection).IsValid);
            Assert.IsFalse(notEmptyLastNameValidator.Validate(emptyLastNameCollection).IsValid);

            Assert.IsTrue(notNullFirstNameValidator.Validate(nullElementCollection).IsValid);
            Assert.IsTrue(notEmptyLastNameValidator.Validate(nullElementCollection).IsValid);
            Assert.IsTrue(compositePropertiesValidator.Validate(nullElementCollection).IsValid);

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

            var notNullFirstNameValidator = new ElementValidator<GenericParameter>();
            notNullFirstNameValidator.CreatePropertyRule(x => x.FirstName).NotNull();

            var notEmptyLastNameValidator = new ElementValidator<GenericParameter>();
            notEmptyLastNameValidator.CreatePropertyRule(x => x.LastName).NotEmpty();

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

            Assert.IsTrue(notNullFirstNameValidator.Validate(emptyLastNameCollection).IsValid);
            Assert.IsTrue(notEmptyLastNameValidator.Validate(nullFirstNameCollection).IsValid);            

            Assert.IsFalse(notNullFirstNameValidator.Validate(nullFirstNameCollection).IsValid);
            Assert.IsFalse(notEmptyLastNameValidator.Validate(emptyLastNameCollection).IsValid);

            Assert.IsTrue(notNullFirstNameValidator.Validate(nullElementCollection).IsValid);
            Assert.IsTrue(notEmptyLastNameValidator.Validate(nullElementCollection).IsValid);
            Assert.IsTrue(compositePropertiesValidator.Validate(nullElementCollection).IsValid);

            Assert.IsFalse(compositePropertiesValidator.Validate(nullFirstNameCollection).IsValid);
            Assert.IsFalse(compositePropertiesValidator.Validate(emptyLastNameCollection).IsValid);
        }
        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);
        }
        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);
        }