public void Integration_SimpleFileCheck()
        {
            const int EXPECTED_ERRORCOUNT = 5;

            string[] fileContents = System.IO.File.ReadAllLines(@"data\simplefile.csv");

            List <ValidationError> errors    = new List <ValidationError>();
            RowValidator           validator = new RowValidator(",");

            validator.AddColumnValidator(1, new UniqueColumnValidator());
            // no validator on 2
            validator.AddColumnValidator(3, new TextFormatValidator(@"^\d\d\d\d-\d\d-\d\d$"));
            validator.AddColumnValidator(4, new NotNullableValidator());
            validator.AddColumnValidator(5, new NumberValidator());

            foreach (string currentRow in fileContents)
            {
                if (!validator.IsValid(currentRow))
                {
                    errors.AddRange(validator.GetError().Errors);
                    validator.ClearErrors();
                }
            }

            Assert.AreEqual(EXPECTED_ERRORCOUNT, errors.Count);
        }
Beispiel #2
0
 private void TransferConvertedColumns(ConvertedValidators converted)
 {
     foreach (KeyValuePair <int, List <IValidator> > column in converted.Columns)
     {
         foreach (IValidator columnValidator in column.Value)
         {
             _rowValidator.AddColumnValidator(column.Key, columnValidator);
         }
     }
 }
Beispiel #3
0
        public void WhenValidatingARow_ErrorsHaveRowContentInformation()
        {
            string[] ROWS = new string[] {
                "1,a name",
                "2,another name",
                "1,a name",
                "3,someone different"
            };

            _rowValidator.AddColumnValidator(1, new UniqueColumnValidator());
            List <RowValidationError> errors = ValidateRows(ROWS);

            Assert.AreEqual(ROWS[2], errors[0].Content);
        }
 private void TransferConvertedColumns(ConvertedValidators converted)
 {
     foreach (KeyValuePair <int, List <IValidator> > column in converted.Columns)
     {
         foreach (IValidator columnValidator in column.Value)
         {
             if (columnValidator.GetType().Equals(typeof(NameValidator)))
             {
                 _colValidator.AddColumnValidator(column.Key, columnValidator);
             }
             else
             {
                 _rowValidator.AddColumnValidator(column.Key, columnValidator);
             }
         }
     }
 }
Beispiel #5
0
        public void RowValidator_WhenGettingColumnValidators_ReturnsValidators()
        {
            _validator.AddColumnValidator(1, new ValidatorGroup(new List <IValidator>()
            {
                new StringLengthValidator(3)
            }));
            _validator.AddColumnValidator(2, new NotNullableValidator());
            _validator.AddColumnValidator(4, new StringLengthValidator(4));

            List <ValidatorGroup> columnValidators = _validator.GetColumnValidators();

            Assert.AreEqual(4, columnValidators.Count);
        }