protected void BuildDefaultSettings(int columnsCount)
 {
     Settings = new ResultSetComparisonSettings(
         columnsCount,
         ResultSetComparisonSettings.KeysChoice.AllExpectLast,
         ResultSetComparisonSettings.ValuesChoice.Last);
 }
 protected void BuildDefaultSettings(int columnsCount)
 {
     Settings = new ResultSetComparisonSettings(
         columnsCount,
         ResultSetComparisonSettings.KeysChoice.AllExpectLast,
         ResultSetComparisonSettings.ValuesChoice.Last);
 }
        protected void CheckSettingsAndDataTable(DataTable dt, ResultSetComparisonSettings settings)
        {
            var max = settings.GetMaxColumnIndexDefined();
            if (dt.Columns.Count <= max)
            {
                var exception = string.Format("You've defined a column with an index of {0}, meaning that your result set would have at least {1} columns but your result set has only {2} columns."
                    , max
                    , max + 1
                    , dt.Columns.Count);

                if (dt.Columns.Count == max && settings.GetMinColumnIndexDefined() == 1)
                    exception += " You've no definition for a column with an index of 0. Are you sure you'vent started to index at 1 in place of 0?";

                throw new ResultSetComparerException(exception);
            }
        }
        protected void CheckSettingsAndFirstRow(DataTable dt, ResultSetComparisonSettings settings)
        {
            if (dt.Rows.Count == 0)
            {
                return;
            }

            var dr = dt.Rows[0];

            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                if (!dr.IsNull(i))
                {
                    if (settings.IsNumeric(i) && IsNumericField(dr.Table.Columns[i]))
                    {
                        continue;
                    }

                    var numericConverter = new NumericConverter();
                    if (settings.IsNumeric(i) && !(numericConverter.IsValid(dr[i]) || BaseComparer.IsValidInterval(dr[i])))
                    {
                        var exception = string.Format("The column with an index of {0} is expecting a numeric value but the first row of your result set contains a value '{1}' not recognized as a valid numeric value or a valid interval."
                                                      , i, dr[i].ToString());

                        if (numericConverter.IsValid(dr[i].ToString().Replace(",", ".")))
                        {
                            exception += " Aren't you trying to use a comma (',' ) as a decimal separator? NBi requires that the decimal separator must be a '.'.";
                        }

                        throw new ResultSetComparerException(exception);
                    }

                    if (settings.IsDateTime(i) && IsDateTimeField(dr.Table.Columns[i]))
                    {
                        return;
                    }

                    if (settings.IsDateTime(i) && !BaseComparer.IsValidDateTime(dr[i].ToString()))
                    {
                        throw new ResultSetComparerException(
                                  string.Format("The column with an index of {0} is expecting a date & time value but the first row of your result set contains a value '{1}' not recognized as a valid date & time value."
                                                , i, dr[i].ToString()));
                    }
                }
            }
        }
        protected void CheckSettingsAndDataTable(DataTable dt, ResultSetComparisonSettings settings)
        {
            var max = settings.GetMaxColumnIndexDefined();

            if (dt.Columns.Count <= max)
            {
                var exception = string.Format("You've defined a column with an index of {0}, meaning that your result set would have at least {1} columns but your result set has only {2} columns."
                                              , max
                                              , max + 1
                                              , dt.Columns.Count);

                if (dt.Columns.Count == max && settings.GetMinColumnIndexDefined() == 1)
                {
                    exception += " You've no definition for a column with an index of 0. Are you sure you'vent started to index at 1 in place of 0?";
                }

                throw new ResultSetComparerException(exception);
            }
        }
        protected void WriteSettingsToDataTableProperties(DataTable dt, ResultSetComparisonSettings settings)
        {
            foreach (DataColumn column in dt.Columns)
            {
                if (column.ExtendedProperties.ContainsKey("NBi::Role"))
                {
                    column.ExtendedProperties["NBi::Role"] = settings.GetColumnRole(column.Ordinal);
                }
                else
                {
                    column.ExtendedProperties.Add("NBi::Role", settings.GetColumnRole(column.Ordinal));
                }

                if (column.ExtendedProperties.ContainsKey("NBi::Type"))
                {
                    column.ExtendedProperties["NBi::Type"] = settings.GetColumnType(column.Ordinal);
                }
                else
                {
                    column.ExtendedProperties.Add("NBi::Type", settings.GetColumnType(column.Ordinal));
                }

                if (column.ExtendedProperties.ContainsKey("NBi::Tolerance"))
                {
                    column.ExtendedProperties["NBi::Tolerance"] = settings.GetTolerance(column.Ordinal);
                }
                else
                {
                    column.ExtendedProperties.Add("NBi::Tolerance", settings.GetTolerance(column.Ordinal));
                }

                if (column.ExtendedProperties.ContainsKey("NBi::Rounding"))
                {
                    column.ExtendedProperties["NBi::Rounding"] = settings.GetRounding(column.Ordinal);
                }
                else
                {
                    column.ExtendedProperties.Add("NBi::Rounding", settings.GetRounding(column.Ordinal));
                }
            }
        }
        protected void CheckSettingsAndFirstRow(DataTable dt, ResultSetComparisonSettings settings)
        {
            if (dt.Rows.Count == 0)
                return;

            var dr = dt.Rows[0];
            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                if (!dr.IsNull(i))
                {
                    if (settings.IsNumeric(i) && IsNumericField(dr.Table.Columns[i]))
                        continue;

                    if (settings.IsNumeric(i) && !(BaseComparer.IsValidNumeric(dr[i]) || BaseComparer.IsValidInterval(dr[i])))
                    {
                        var exception = string.Format("The column with an index of {0} is expecting a numeric value but the first row of your result set contains a value '{1}' not recognized as a valid numeric value or a valid interval."
                            , i, dr[i].ToString());

                        if (BaseComparer.IsValidNumeric(dr[i].ToString().Replace(",", ".")))
                            exception += " Aren't you trying to use a comma (',' ) as a decimal separator? NBi requires that the decimal separator must be a '.'.";

                        throw new ResultSetComparerException(exception);
                    }

                    if (settings.IsDateTime(i) && IsDateTimeField(dr.Table.Columns[i]))
                        return;

                    if (settings.IsDateTime(i) && !BaseComparer.IsValidDateTime(dr[i].ToString()))
                    {
                        throw new ResultSetComparerException(
                            string.Format("The column with an index of {0} is expecting a date & time value but the first row of your result set contains a value '{1}' not recognized as a valid date & time value."
                                , i, dr[i].ToString()));
                    }
                }
            }
        }
 public DataRowBasedResultSetComparer(ResultSetComparisonSettings settings)
 {
     Settings = settings;
 }
Example #9
0
 public DataRowKeysComparer(ResultSetComparisonSettings settings, int columnCount)
 {
     this.settings = settings;
     settings.ApplyTo(columnCount);
 }
Example #10
0
 public ResultSetComparer(ResultSetComparisonSettings settings)
 {
     Settings = settings;
 }
Example #11
0
 protected void BuildDefaultSettings(int columnsCount)
 {
     Settings = new SingleRowComparisonSettings();
 }
 public DataRowBasedResultSetComparer(ResultSetComparisonSettings settings)
 {
     Settings = settings;
 }
        protected void WriteSettingsToDataTableProperties(DataTable dt, ResultSetComparisonSettings settings)
        {
            foreach (DataColumn column in dt.Columns)
            {
                if (column.ExtendedProperties.ContainsKey("NBi::Role"))
                    column.ExtendedProperties["NBi::Role"] = settings.GetColumnRole(column.Ordinal);
                else
                    column.ExtendedProperties.Add("NBi::Role", settings.GetColumnRole(column.Ordinal));

                if (column.ExtendedProperties.ContainsKey("NBi::Type"))
                    column.ExtendedProperties["NBi::Type"] = settings.GetColumnType(column.Ordinal);
                else
                    column.ExtendedProperties.Add("NBi::Type", settings.GetColumnType(column.Ordinal));

                if (column.ExtendedProperties.ContainsKey("NBi::Tolerance"))
                    column.ExtendedProperties["NBi::Tolerance"] = settings.GetTolerance(column.Ordinal);
                else
                    column.ExtendedProperties.Add("NBi::Tolerance", settings.GetTolerance(column.Ordinal));

                if (column.ExtendedProperties.ContainsKey("NBi::Rounding"))
                    column.ExtendedProperties["NBi::Rounding"] = settings.GetRounding(column.Ordinal);
                else
                    column.ExtendedProperties.Add("NBi::Rounding", settings.GetRounding(column.Ordinal));
            }
        }
        protected NBiConstraint InstantiateConstraint()
        {
            EqualToConstraint ctr = null;

            if (ConstraintXml.GetCommand() != null)
            {
                var commandText = ConstraintXml.GetCommand().CommandText;
                var connectionString = ConstraintXml.GetCommand().Connection.ConnectionString;
                IEnumerable<IQueryParameter> parameters = null;
                IEnumerable<IQueryTemplateVariable> variables = null;
                if (ConstraintXml.Query != null)
                {
                    parameters = ConstraintXml.Query.GetParameters();
                    variables = ConstraintXml.Query.GetVariables();
                }

                var commandBuilder = new CommandBuilder();
                var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables);
                ctr = new EqualToConstraint(cmd);
            }
            else if (ConstraintXml.ResultSet != null)
            {
                if (!string.IsNullOrEmpty(ConstraintXml.ResultSet.File))
                {
                    Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in external file!");
                    ctr = new EqualToConstraint(ConstraintXml.ResultSet.GetFile());
                    if (ConstraintXml.Settings.CsvProfile != null)
                        ctr=ctr.CsvProfile(ConstraintXml.Settings.CsvProfile);
                }
                else if (ConstraintXml.ResultSet.Rows!=null)
                {
                    Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in embedded resultSet!");
                    ctr = new EqualToConstraint(ConstraintXml.ResultSet.Rows);
                }
            }
            else if (ConstraintXml.XmlSource != null)
            {
                if (!string.IsNullOrEmpty(ConstraintXml.XmlSource.GetFile()))
                {
                    Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, string.Format("Xml file at '{0}'", ConstraintXml.XmlSource.GetFile()));

                    var selects = new List<AbstractSelect>();
                    var factory = new SelectFactory();
                    foreach (var select in ConstraintXml.XmlSource.XPath.Selects)
                        selects.Add(factory.Instantiate(select.Value, select.Attribute));

                    var engine = new XPathFileEngine(ConstraintXml.XmlSource.GetFile(), ConstraintXml.XmlSource.XPath.From.Value, selects);

                    ctr = new EqualToConstraint(engine);
                }
                else
                    throw new ArgumentException("File's can't be empty when declaring an xml-source.");
            }

            if (ctr==null)
                throw new ArgumentException();

            //Manage settings for comparaison
            var settings = new ResultSetComparisonSettings(
                    ConstraintXml.KeysDef,
                    ConstraintXml.ValuesDef,
                    ConstraintXml.ValuesDefaultType,
                    new NumericToleranceFactory().Instantiate(ConstraintXml.Tolerance),
                    ConstraintXml.ColumnsDef
                );

            ctr.Using(settings);

            if (ConstraintXml.ParallelizeQueries)
                ctr = ctr.Parallel();
            else
                ctr = ctr.Sequential();

            //Manage persistance
            //EqualToConstraint.PersistanceItems persi = 0;
            //if (ConstraintXml.GetCommand() != null)
            //    persi += (int)EqualToConstraint.PersistanceItems.actual;
            //if (SystemUnderTestXml is QueryXml)
            //    persi += (int)EqualToConstraint.PersistanceItems.expected;
            //if (!(persi==0 || ConstraintXml.Query==null || string.IsNullOrEmpty(ConstraintXml.Test.Name)))
            //    ctr.Persist(ConstraintXml.Persistance, persi, ConstraintXml.Test.Name);

            return ctr;
        }
Example #15
0
 public EqualToConstraint Using(ResultSetComparisonSettings settings)
 {
     this.Engine.Settings = settings;
     return this;
 }
Example #16
0
        protected global::NUnit.Framework.Constraints.Constraint InstantiateConstraint()
        {
            EqualToConstraint ctr = null;

            if (ConstraintXml.GetCommand() != null)
            {
                var commandText = ConstraintXml.GetCommand().CommandText;
                var connectionString = ConstraintXml.GetCommand().Connection.ConnectionString;
                IEnumerable<IQueryParameter> parameters = null;
                IEnumerable<IQueryTemplateVariable> variables = null;
                if (ConstraintXml.Query != null)
                {
                    parameters = ConstraintXml.Query.GetParameters();
                    variables = ConstraintXml.Query.GetVariables();
                }

                var commandBuilder = new CommandBuilder();
                var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables);
                ctr = new EqualToConstraint(cmd);
            }
            else if (ConstraintXml.ResultSet != null)
            {
                if (!string.IsNullOrEmpty(ConstraintXml.ResultSet.File))
                {
                    Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in external file!");
                    ctr = new EqualToConstraint(ConstraintXml.ResultSet.GetFile());
                }
                else if (ConstraintXml.ResultSet.Rows!=null)
                {
                    Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, "ResultSet defined in embedded resultSet!");
                    ctr = new EqualToConstraint(ConstraintXml.ResultSet.Rows);
                }
            }

            if (ctr==null)
                throw new ArgumentException();

            //Manage settings for comparaison
            ResultSetComparisonSettings settings = new ResultSetComparisonSettings(
                ConstraintXml.KeysDef,
                ConstraintXml.ValuesDef,
                ToleranceFactory.BuildNumeric(ConstraintXml.Tolerance),
                ConstraintXml.ColumnsDef
                );

            ctr.Using(settings);

            if (ConstraintXml.ParallelizeQueries)
                ctr = ctr.Parallel();
            else
                ctr = ctr.Sequential();

            //Manage persistance
            //EqualToConstraint.PersistanceItems persi = 0;
            //if (ConstraintXml.GetCommand() != null)
            //    persi += (int)EqualToConstraint.PersistanceItems.actual;
            //if (SystemUnderTestXml is QueryXml)
            //    persi += (int)EqualToConstraint.PersistanceItems.expected;
            //if (!(persi==0 || ConstraintXml.Query==null || string.IsNullOrEmpty(ConstraintXml.Test.Name)))
            //    ctr.Persist(ConstraintXml.Persistance, persi, ConstraintXml.Test.Name);

            return ctr;
        }
Example #17
0
 public SingleRowComparer(ResultSetComparisonSettings settings)
 {
     Settings = settings;
 }