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);
        }
Exemplo n.º 2
0
        protected bool doMatch(ResultSet actual)
        {
            this.actualResultSet = actual;

            var validationEngine = new RowValidator();

            evaluationResults = new List <RowEvaluationResult>();
            int rowIndex = 0;

            foreach (DataRow row in actualResultSet.Rows)
            {
                var valuedVariables = new Dictionary <string, Object>();
                foreach (var v in variables)
                {
                    valuedVariables.Add(v.Name, row[v.Column]);
                }

                var valuedExpressions = new List <ValuedExpression>();
                foreach (var e in expressions)
                {
                    valuedExpressions.Add(new ValuedExpression(e.Value, row[e.Column], e.Type, e.Tolerance));
                }

                evaluationResults.Add(new RowEvaluationResult(rowIndex, valuedVariables, validationEngine.Execute(valuedVariables, valuedExpressions)));
                rowIndex += 1;
            }
            bool value = evaluationResults.Aggregate <RowEvaluationResult, bool>(true, (total, r) => total && (r.CountExpressionValidationFailed() == 0));

            return(value);
        }
Exemplo n.º 3
0
        public void Execute_BasicMathInvalid_False()
        {
            var expressions = new List <ValuedExpression>();

            expressions.Add(new ValuedExpression("=4+4", 0));

            var validator = new RowValidator();
            var result    = validator.Execute(new Dictionary <string, object>(), expressions).Aggregate <ExpressionEvaluationResult, bool>(true, (total, r) => total && r.IsValid);

            Assert.That(result, Is.False);
        }
Exemplo n.º 4
0
        public void Execute_BasicMathValid_True()
        {
            var expressions = new List <ValuedExpression>()
            {
                new ValuedExpression("=4+4", 8)
            };

            var validator = new RowValidator();
            var result    = validator.Execute(new Dictionary <string, object>(), expressions).Aggregate(true, (total, r) => total && r.IsValid);

            Assert.That(result, Is.True);
        }
Exemplo n.º 5
0
        public void Execute_VariableValid_True()
        {
            var expressions = new List <ValuedExpression>();

            expressions.Add(new ValuedExpression("=X+4", 9));
            var variables = new Dictionary <string, object>();

            variables["X"] = 5;

            var validator = new RowValidator();
            var result    = validator.Execute(variables, expressions).Aggregate <ExpressionEvaluationResult, bool>(true, (total, r) => total && r.IsValid);

            Assert.That(result, Is.True);
        }
Exemplo n.º 6
0
        public void Execute_MathVariablesToleranceInvalid_False()
        {
            var expressions = new List <ValuedExpression>();

            expressions.Add(new ValuedExpression("=Abs(x*y)", 0, 2));
            var variables = new Dictionary <string, object>();

            variables["x"] = -5;
            variables["y"] = 2;

            var validator = new RowValidator();
            var result    = validator.Execute(variables, expressions).Aggregate <ExpressionEvaluationResult, bool>(true, (total, r) => total && r.IsValid);

            Assert.That(result, Is.False);
        }
Exemplo n.º 7
0
        public void Execute_VariableInvalid_False()
        {
            var expressions = new List <ValuedExpression>()
            {
                new ValuedExpression("=X+4", 0)
            };
            var variables = new Dictionary <string, object>()
            {
                { "X", 5 }
            };

            var validator = new RowValidator();
            var result    = validator.Execute(variables, expressions).Aggregate(true, (total, r) => total && r.IsValid);

            Assert.That(result, Is.False);
        }
Exemplo n.º 8
0
        public void Execute_MathVariablesValid_True()
        {
            var expressions = new List <ValuedExpression>()
            {
                new ValuedExpression("=Abs(x*y)", 10)
            };
            var variables = new Dictionary <string, object>()
            {
                { "x", -5 },
                { "y", 2 }
            };
            var validator = new RowValidator();
            var result    = validator.Execute(variables, expressions).Aggregate(true, (total, r) => total && r.IsValid);

            Assert.That(result, Is.True);
        }
Exemplo n.º 9
0
 public void Setup()
 {
     _validator = new RowValidator(",");
 }
Exemplo n.º 10
0
 public Validator()
 {
     _rowValidator = new RowValidator();
     _rowSeperator = "\r\n";
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initialises a new instance of Validator
 /// </summary>
 internal Validator()
 {
     _rowValidator = new RowValidator();
     _rowSeperator = "\r\n";
 }