Esempio n. 1
0
        /// <summary>
        /// Validates row names and value types against schema
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        public virtual Exception Validate(ResultSetSchema schema)
        {
            schema.ThrowIfNull("schema");

            var ex = schema.Validate(true);

            if (ex != null)
            {
                return(new InvalidOperationException("Invalid schema", ex));
            }

            ex = CheckForEmptyValuesWithoutColumnName();
            if (ex != null)
            {
                return(ex);
            }

            ex = CheckForInvalidCOlumnNames(schema);
            if (ex != null)
            {
                return(ex);
            }

            ex = CheckForInvalidValueTypes(schema);
            if (ex != null)
            {
                return(ex);
            }

            return(null); // nothing to validate here TODO: validate against given schema!!
        }
Esempio n. 2
0
        private Exception CheckForInvalidCOlumnNames(ResultSetSchema schema)
        {
            var columnName = this.Keys.Where(key => !schema.Columns.Any(column => column.Name == key)).FirstOrDefault();

            if (columnName != null)
            {
                return(new InvalidOperationException($"Column '{columnName}' is not defined in schema"));
            }

            return(null);
        }
Esempio n. 3
0
        private Exception CheckForInvalidValueTypes(ResultSetSchema schema)
        {
            var invalidColumn = this.Where(kv => schema.Columns.Any(column => column.Name == kv.Key && kv.Value != null && kv.Value != DBNull.Value && kv.Value.GetType() != column.ClrType))
                                .Select(kv => new { ColumnName = kv.Key, ValueType = kv.Value.GetType().FullName }).FirstOrDefault();

            if (invalidColumn != null)
            {
                return(new InvalidOperationException($"Value for '{ invalidColumn.ColumnName}' is of type '{invalidColumn.ValueType}' while schema defines type '{schema.GetColumn(invalidColumn.ColumnName).ClrType.FullName}'"));
            }

            return(null);
        }
Esempio n. 4
0
        public virtual Exception Validate(ResultSetSchema schema, bool recursive = false)
        {
            schema.ThrowIfNull("schema");

            if (recursive)
            {
                foreach (var row in this)
                {
                    var ex = row.Validate(schema);
                    if (ex != null)
                    {
                        return(new InvalidOperationException("Found invalid row(s)", ex));
                    }
                }
            }

            return(null);
        }