Esempio n. 1
0
        protected void CheckSettingsAndFirstRow(DataTable dt, SettingsNameResultSet settings)
        {
            if (dt.Rows.Count == 0)
            {
                return;
            }

            var dr = dt.Rows[0];

            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                var columnName = dr.Table.Columns[i].ColumnName;
                CheckSettingsFirstRowCell(
                    settings.GetColumnRole(columnName)
                    , settings.GetColumnType(columnName)
                    , dr.Table.Columns[columnName]
                    , dr.IsNull(columnName) ? DBNull.Value : dr[columnName]
                    , new string[]
                {
                    "The column named '{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."
                    , " Aren't you trying to use a comma (',' ) as a decimal separator? NBi requires that the decimal separator must be a '.'."
                    , "The column named '{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."
                }
                    );
            }
        }
Esempio n. 2
0
        protected void CheckSettingsAndDataTable(DataTable dt, SettingsNameResultSet settings)
        {
            var missingColumns = new List <KeyValuePair <string, string> >();

            foreach (var columnName in settings.GetKeyNames())
            {
                if (!dt.Columns.Contains(columnName))
                {
                    missingColumns.Add(new KeyValuePair <string, string>(columnName, "key"));
                }
            }

            foreach (var columnName in settings.GetValueNames())
            {
                if (!dt.Columns.Contains(columnName))
                {
                    missingColumns.Add(new KeyValuePair <string, string>(columnName, "value"));
                }
            }

            if (missingColumns.Count > 0)
            {
                var exception = string.Format("You've defined {0} column{1} named '{2}' as key{1} or value{1} but there is no column with {3} name{1} in the resultset. When using comparison by columns' name, you must ensure that all columns defined as keys and values are effectively available in the result-set."
                                              , missingColumns.Count > 1 ? "some" : "a"
                                              , missingColumns.Count > 1 ? "s" : string.Empty
                                              , string.Join("', '", missingColumns.Select(kv => kv.Key))
                                              , missingColumns.Count > 1 ? "these" : "this"
                                              );

                throw new EquivalerException(exception);
            }
        }
Esempio n. 3
0
        public void Execute_TwoCustomColumns_ThreeGroups()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new object[] { "alpha", 1d, 10 }, new object[] { "alpha", 1, 20 }, new object[] { "beta", 2, 30 }, new object[] { "alpha", 2, 40 } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            rs.Columns[0].ColumnName = "first";
            rs.Columns[1].ColumnName = "second";
            rs.Columns[1].SetOrdinal(0);

            var settings = new SettingsNameResultSet(new List <IColumnDefinition>()
            {
                new Column()
                {
                    Identifier = new ColumnNameIdentifier("first"), Role = ColumnRole.Key, Type = ColumnType.Text
                },
                new Column()
                {
                    Identifier = new ColumnNameIdentifier("second"), Role = ColumnRole.Key, Type = ColumnType.Numeric
                },
            }
                                                     );
            var grouping = new NameByColumnGrouping(settings);

            var result = grouping.Execute(rs);

            Assert.That(result, Has.Count.EqualTo(3));
            Assert.That(result[new KeyCollection(new object[] { "alpha", 1m })].Rows, Has.Count.EqualTo(2));
            Assert.That(result[new KeyCollection(new object[] { "alpha", 2m })].Rows, Has.Count.EqualTo(1));
            Assert.That(result[new KeyCollection(new object[] { "beta", 2m })].Rows, Has.Count.EqualTo(1));
        }
Esempio n. 4
0
 protected void WriteSettingsToDataTableProperties(DataTable dt, SettingsNameResultSet settings)
 {
     foreach (DataColumn column in dt.Columns)
     {
         WriteSettingsToDataTableProperties(
             column
             , settings.GetColumnRole(column.ColumnName)
             , settings.GetColumnType(column.ColumnName)
             , settings.GetTolerance(column.ColumnName)
             , settings.GetRounding(column.ColumnName)
             );
     }
 }
Esempio n. 5
0
        protected void RemoveIgnoredColumns(DataTable dt, SettingsNameResultSet settings)
        {
            var i = 0;

            while (i < dt.Columns.Count)
            {
                if (settings.GetColumnRole(dt.Columns[i].ColumnName) == ColumnRole.Ignore)
                {
                    dt.Columns.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
        }
Esempio n. 6
0
        public void Execute_SingleColumn_TwoGroups()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new object[] { "alpha", 1 }, new object[] { "alpha", 2 }, new object[] { "beta", 3 }, new object[] { "alpha", 4 } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            rs.Columns[0].ColumnName = "first";

            var settings = new SettingsNameResultSet(new List <IColumnDefinition>()
            {
                new Column()
                {
                    Identifier = new ColumnNameIdentifier("first"), Role = ColumnRole.Key, Type = ColumnType.Text
                },
            }
                                                     );
            var grouping = new NameByColumnGrouping(settings);

            var result = grouping.Execute(rs);

            Assert.That(result, Has.Count.EqualTo(2));
            Assert.That(result[new KeyCollection(new[] { "alpha" })].Rows, Has.Count.EqualTo(3));
            Assert.That(result[new KeyCollection(new[] { "beta" })].Rows, Has.Count.EqualTo(1));
        }
Esempio n. 7
0
 public NameEquivaler(IEnumerable <IRowsAnalyzer> analyzers, SettingsNameResultSet settings)
     : base(analyzers)
 {
     base.Settings = settings;
 }
Esempio n. 8
0
 public NameEvaluator(SettingsNameResultSet settings)
     : base(settings)
 {
 }