Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataValidator" /> class.
        /// </summary>
        /// <param name="name">The validator name.</param>
        /// <param name="checkType">Type of the check.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">If any arguments are null.</exception>
        /// <exception cref="System.ArgumentException">If <c>metadata.Connection</c> is null.</exception>
        protected DataValidator(string name, string checkType, CheckMetadata metadata)
        {
            this.name = name;

            if (checkType == null)
            {
                throw new ArgumentNullException("checkType");
            }

            this.CheckType = checkType;

            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            this.metadata = metadata;

            if (this.metadata.Connection == null)
            {
                throw new ArgumentException("checkInfo.Connection is null");
            }

            this.connectionFactory = this.metadata.Connection.CreateConnectionFactory();
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityValidator" /> class.
        /// </summary>
        /// <param name="name">The validator name.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="checkType">Type of the check.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">If any arguments are null.</exception>
        protected EntityValidator(string name, string entityName, string checkType, CheckMetadata metadata)
            : base(name, checkType, metadata)
        {
            if (entityName == null)
            {
                throw new ArgumentNullException("entityName");
            }

            this.EntityName = entityName;
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericCheck" /> class.
        /// </summary>
        /// <param name="name">The check name.</param>
        /// <param name="entityName">Optional name of the entity.</param>
        /// <param name="query">The query.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">If any arguments are null.</exception>
        public GenericCheck(string name, string entityName, string query, CheckMetadata metadata)
            : base(name, "GenericQuery", metadata)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentNullException("query");
            }

            this.query = query;

            this.entityName = entityName;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnknownCheckTypeValidator" /> class.
        /// </summary>
        /// <param name="checkElement">The check element.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">If any arguments are null.</exception>
        public UnknownCheckTypeValidator(XElement checkElement, CheckMetadata metadata)
        {
            if (checkElement == null)
            {
                throw new ArgumentNullException("checkElement");
            }

            this.checkElement = checkElement;

            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            this.metadata = metadata;
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmptyTableValidator" /> class.
 /// </summary>
 /// <param name="name">The validator name.</param>
 /// <param name="entityName">Name of the entity.</param>
 /// <param name="invert">If set to <c>true</c> [invert].</param>
 /// <param name="metadata">The metadata.</param>
 public EmptyTableValidator(string name, string entityName, bool invert, CheckMetadata metadata)
     : base(name, entityName, invert ? "NotEmpty" : "Empty", metadata)
 {
     this.invert = invert;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MatchStringCheck" /> class.
 /// </summary>
 /// <param name="name">The validator name.</param>
 /// <param name="entityName">Name of the entity.</param>
 /// <param name="columnName">Name of the column.</param>
 /// <param name="pattern">The regex pattern.</param>
 /// <param name="options">The regex options.</param>
 /// <param name="metadata">The metadata.</param>
 public MatchStringCheck(string name, string entityName, string columnName, string pattern, RegexOptions options, CheckMetadata metadata)
     : base(name, entityName, columnName, "RegexMatch", metadata)
 {
     this.regex = new Regex(pattern, options | RegexOptions.Compiled);
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UniqueColumnValidator" /> class.
 /// </summary>
 /// <param name="name">The validator name.</param>
 /// <param name="entityName">Name of the entity.</param>
 /// <param name="columnNames">A comma separated list of column names.</param>
 /// <param name="metadata">The metadata.</param>
 public UniqueColumnValidator(string name, string entityName, string columnNames, CheckMetadata metadata)
     : base(name, entityName, columnNames, "UniqueColumn", metadata)
 {
 }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParallelCheck" /> class.
        /// </summary>
        /// <param name="name">The check name.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="expectedConnection">The expected connection.</param>
        /// <param name="expectedQuery">The expected query.</param>
        /// <param name="actualsQuery">The actual values query.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">
        /// If any of the arguments are null.
        /// </exception>
        public ParallelCheck(string name, string entityName, DataConnection expectedConnection, string expectedQuery, string actualsQuery, CheckMetadata metadata)
            : base(name, "ParallelQuery", metadata)
        {
            if (string.IsNullOrEmpty(expectedQuery))
            {
                throw new ArgumentNullException("expectedQuery");
            }

            this.expectedQuery = expectedQuery;

            if (string.IsNullOrEmpty(actualsQuery))
            {
                throw new ArgumentNullException("actualsQuery");
            }

            this.actualsQuery = actualsQuery;

            // If an expected values connection is not supplied then use the default.
            this.expectedConnectionFactory = (expectedConnection ?? metadata.Connection).CreateConnectionFactory();

            this.entityName = entityName;
        }
Пример #9
0
        /// <summary>
        /// Creates the check.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>A check instant.</returns>
        private IDataValidator CreateCheck(XElement element)
        {
            var filterElement = element.Element("Filter");

            var metadata = new CheckMetadata
            {
                Goal           = element.FindAttribute("Goal").ParseWithDefault(0.0),
                Owner          = FindElement(element, "Owner", this.owners),
                ProductFeature = element.FindAncestorElementAttribute("Feature", "Name"),
                Connection     = FindElement(element, "Connection", this.connections, "target"),
                Filter         = filterElement != null ? filterElement.Value : string.Empty,
                Severity       = (CheckSeverity)Enum.Parse(typeof(CheckSeverity), element.FindAncestorAttribute("Severity") ?? "Warning")
            };

            switch (element.Name.LocalName)
            {
            case "NotNull":
                return(new NullColumnValidator(
                           element.FindAttribute("Name"),
                           element.Parent.FindAttribute("Name"),
                           element.FindAttribute("Field"),
                           metadata));

            case "Unique":
                return(new UniqueColumnValidator(
                           element.FindAttribute("Name"),
                           element.Parent.FindAttribute("Name"),
                           element.FindAttribute("Fields") ?? element.FindAttribute("Field"),
                           metadata));

            case "Check":
                return(new GenericCheck(
                           element.FindAttribute("Name"),
                           element.FindAncestorElementAttribute("Entity", "Name"),
                           element.Value,
                           metadata));

            case "Match":
                var regexOptionsString = element.FindAttribute("Options");

                var options = string.IsNullOrEmpty(regexOptionsString) ? RegexOptions.None : (RegexOptions)Enum.Parse(typeof(RegexOptions), regexOptionsString);

                return(new MatchStringCheck(
                           element.FindAttribute("Name"),
                           element.Parent.FindAttribute("Name"),
                           element.FindAttribute("Field"),
                           element.FindAttribute("Expression"),
                           options,
                           metadata));

            case "Empty":
                return(new EmptyTableValidator(
                           element.FindAttribute("Name"),
                           element.Parent.FindAttribute("Name"),
                           false,
                           metadata));

            case "NotEmpty":
                return(new EmptyTableValidator(
                           element.FindAttribute("Name"),
                           element.Parent.FindAttribute("Name"),
                           true,
                           metadata));

            case "ParallelCheck":
                var expectedElement = element.Element("Expected");
                var actualElement   = element.Element("Actual");

                return(new ParallelCheck(
                           element.FindAttribute("Name"),
                           element.FindAncestorElementAttribute("Entity", "Name"),
                           FindElement(expectedElement, "Connection", this.connections, "target"),
                           expectedElement.Value,
                           actualElement.Value,
                           metadata));

            default:
                EventPublisher.Raise(new UnknownCheckEvent {
                    CheckName = element.Name.LocalName
                });
                return(new UnknownCheckTypeValidator(element, metadata));
            }
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SingleColumnValidator" /> class.
        /// </summary>
        /// <param name="name">The validator name.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="columnName">Name of the column.</param>
        /// <param name="checkType">Type of the check.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">If any arguments are null.</exception>
        protected SingleColumnValidator(string name, string entityName, string columnName, string checkType, CheckMetadata metadata)
            : base(name, entityName, checkType, metadata)
        {
            if (columnName == null)
            {
                throw new ArgumentNullException("columnName");
            }

            this.ColumnName = columnName;
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultipleColumnValidator" /> class.
        /// </summary>
        /// <param name="name">The validator name.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="columnNames">A comma separated list of column names.</param>
        /// <param name="checkType">Type of the check.</param>
        /// <param name="metadata">The metadata.</param>
        /// <exception cref="System.ArgumentNullException">If any arguments are null.</exception>
        protected MultipleColumnValidator(string name, string entityName, string columnNames, string checkType, CheckMetadata metadata)
            : base(name, entityName, checkType, metadata)
        {
            if (columnNames == null)
            {
                throw new ArgumentNullException("columnNames");
            }

            this.columnNames = columnNames
                               .Split(',')
                               .Select(n => n.Trim())
                               .ToArray();
        }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NullColumnValidator" /> class.
 /// </summary>
 /// <param name="name">The validator name.</param>
 /// <param name="entityName">Name of the entity.</param>
 /// <param name="columnName">Name of the column.</param>
 /// <param name="metadata">The metadata.</param>
 public NullColumnValidator(string name, string entityName, string columnName, CheckMetadata metadata)
     : base(name, entityName, columnName, "NotNull", metadata)
 {
 }