示例#1
0
        public void Apply_XOr_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    "(null)", 10, 100
                },
                new List <object>()
                {
                    "(empty)", 2, 75
                },
                new List <object>()
                {
                    "(empty)", 20, 75
                },
                new List <object>()
                {
                    "C", 5, 50
                },
                new List <object>()
                {
                    "C", 15, 50
                }
            }));

            var rs = service.Execute();

            var aliases = new[] { Mock.Of <IColumnAlias>(v => v.Column == 0 && v.Name == "a") };

            var predicate1 = new Mock <PredicateArgs>();

            predicate1.SetupGet(p => p.ColumnType).Returns(ColumnType.Text);
            predicate1.SetupGet(p => p.ComparerType).Returns(ComparerType.NullOrEmpty);
            var predication1 = new Mock <PredicationArgs>();

            predication1.SetupGet(p => p.Identifier).Returns(new ColumnNameIdentifier("a"));
            predication1.SetupGet(p => p.Predicate).Returns(predicate1.Object);

            var predicate2 = new Mock <ReferencePredicateArgs>();

            predicate2.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
            predicate2.SetupGet(p => p.ComparerType).Returns(ComparerType.LessThan);
            predicate2.SetupGet(p => p.Reference).Returns(new LiteralScalarResolver <decimal>(10));
            var predication2 = new Mock <PredicationArgs>();

            predication2.SetupGet(p => p.Identifier).Returns(new ColumnOrdinalIdentifier(1));
            predication2.SetupGet(p => p.Predicate).Returns(predicate1.Object);

            var factory = new ResultSetFilterFactory(null);
            var filter  = factory.Instantiate(CombinationOperator.XOr, new[] { predication1.Object, predication2.Object }, new Context(null, aliases, Array.Empty <IColumnExpression>()));
            var result  = filter.Apply(rs);

            Assert.That(result.Rows, Has.Count.EqualTo(3));
        }
示例#2
0
        private NBi.Core.ResultSet.ResultSet Build()
        {
            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 = "keyColumn";
            rs.Columns[1].ColumnName = "valueColumn";
            return(rs);
        }
示例#3
0
        public void Apply_AndWillNotEvaluateAll_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    null
                },
                new List <object>()
                {
                    5
                },
                new List <object>()
                {
                    10
                },
                new List <object>()
                {
                    null
                },
                new List <object>()
                {
                    20
                },
            }));

            var rs = service.Execute();

            var aliases = new[] { Mock.Of <IColumnAlias>(v => v.Column == 0 && v.Name == "a") };

            var predicate1 = new Mock <IPredicateInfo>();

            predicate1.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
            predicate1.SetupGet(p => p.ComparerType).Returns(ComparerType.Null);
            predicate1.SetupGet(p => p.Not).Returns(true);
            predicate1.SetupGet(p => p.Operand).Returns("#0");

            var predicate2 = new Mock <IPredicateInfo>();

            predicate2.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
            predicate2.SetupGet(p => p.ComparerType).Returns(ComparerType.LessThan);
            predicate2.SetupGet(p => p.Operand).Returns("#0");
            predicate2.As <IReferencePredicateInfo>().SetupGet(p => p.Reference).Returns(10);

            var factory = new PredicateFilterFactory();
            var filter  = factory.Instantiate(aliases, new IColumnExpression[0], CombinationOperator.And, new[] { predicate1.Object, predicate2.Object });
            var result  = filter.Apply(rs);

            Assert.That(result.Rows, Has.Count.EqualTo(1));
        }
示例#4
0
        public void Execute_NotExistingColumnFailureStrategy_IgnoreIssue()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new[] { "100,12", "Alpha" }, new[] { "100", "Beta" }, new[] { "0,1", "Gamma" } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var renamer = new NewNameRenamingEngine(
                new ColumnNameIdentifier("unexistingColumn"),
                new LiteralScalarResolver <string>("myNewName")
                );

            Assert.Throws <NBiException>(() => renamer.Execute(rs));
        }
示例#5
0
        public void Apply_XOr_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    "(null)", 10, 100
                },
                new List <object>()
                {
                    "(empty)", 2, 75
                },
                new List <object>()
                {
                    "(empty)", 20, 75
                },
                new List <object>()
                {
                    "C", 5, 50
                },
                new List <object>()
                {
                    "C", 15, 50
                }
            }));

            var rs = service.Execute();

            var aliases = new[] { Mock.Of <IColumnAlias>(v => v.Column == 0 && v.Name == "a") };

            var predicate1 = new Mock <IPredicateInfo>();

            predicate1.SetupGet(p => p.ColumnType).Returns(ColumnType.Text);
            predicate1.SetupGet(p => p.ComparerType).Returns(ComparerType.NullOrEmpty);
            predicate1.SetupGet(p => p.Operand).Returns("a");

            var predicate2 = new Mock <IPredicateInfo>();

            predicate2.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
            predicate2.SetupGet(p => p.ComparerType).Returns(ComparerType.LessThan);
            predicate2.SetupGet(p => p.Operand).Returns("#1");
            predicate2.As <IReferencePredicateInfo>().SetupGet(p => p.Reference).Returns((object)10);

            var factory = new PredicateFilterFactory();
            var filter  = factory.Instantiate(aliases, new IColumnExpression[0], CombinationOperator.XOr, new[] { predicate1.Object, predicate2.Object });
            var result  = filter.Apply(rs);

            Assert.That(result.Rows, Has.Count.EqualTo(3));
        }
示例#6
0
        public void Apply_Or_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    "(null)", 10, 100
                },
                new List <object>()
                {
                    "(empty)", 2, 75
                },
                new List <object>()
                {
                    "(empty)", 20, 75
                },
                new List <object>()
                {
                    "C", 5, 50
                },
                new List <object>()
                {
                    "C", 15, 50
                }
            }));

            var rs = service.Execute();

            var aliases = new[] { Mock.Of <IColumnAlias>(v => v.Column == 0 && v.Name == "a") };

            var info1 = Mock.Of <IPredicateInfo>
                        (
                p => p.ComparerType == ComparerType.NullOrEmpty &&
                p.ColumnType == ColumnType.Text &&
                p.Operand == "a"
                        );
            var info2 = Mock.Of <IPredicateInfo>
                        (
                p => p.ComparerType == ComparerType.LessThan &&
                p.ColumnType == ColumnType.Numeric &&
                p.Operand == "#1" &&
                p.Reference == (object)10
                        );
            var factory = new PredicateFilterFactory();
            var filter  = factory.Instantiate(aliases, new IColumnExpression[0], CombinationOperator.Or, new[] { info1, info2 });
            var result  = filter.Apply(rs);

            Assert.That(result.Rows, Has.Count.EqualTo(4));
        }
示例#7
0
        public void Execute_ExistingColumnByOrdinal_ColumnRenamed()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new[] { "100,12", "Alpha" }, new[] { "100", "Beta" }, new[] { "0,1", "Gamma" } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var renamer = new NewNameRenamingEngine(
                new ColumnOrdinalIdentifier(1),
                new LiteralScalarResolver <string>("myNewName")
                );
            var newRs = renamer.Execute(rs);

            Assert.That(newRs.Columns[1].ColumnName, Is.EqualTo("myNewName"));
        }
示例#8
0
        public void Apply_NativeExpression_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    new DateTime(2019, 10, 01, 8, 0, 0), 10, 100
                },
                new List <object>()
                {
                    new DateTime(2019, 10, 01, 23, 0, 0), 2, 75
                },
                new List <object>()
                {
                    new DateTime(2019, 10, 02, 05, 0, 0), 5, 50
                }
            }));
            var rs = service.Execute();

            rs.Table.Columns[0].ColumnName = "a";

            var aliases = new List <IColumnAlias>()
            {
                Mock.Of <IColumnAlias>(v => v.Column == 0 && v.Name == "x"),
            };

            var expressions = new List <IColumnExpression>()
            {
                Mock.Of <IColumnExpression>(
                    e => e.Value == "a | utc-to-local(Brussels) | dateTime-to-date" &&
                    e.Name == "d" &&
                    e.Language == LanguageType.Native &&
                    e.Type == ColumnType.DateTime),
            };

            var predicate = new Mock <IPredicateInfo>();

            predicate.SetupGet(p => p.ColumnType).Returns(ColumnType.DateTime);
            predicate.SetupGet(p => p.ComparerType).Returns(ComparerType.MoreThanOrEqual);
            predicate.SetupGet(p => p.Operand).Returns(new ColumnNameIdentifier("d"));
            predicate.As <IReferencePredicateInfo>().SetupGet(p => p.Reference).Returns((object)new DateTime(2019, 10, 2));

            var factory = new ResultSetFilterFactory(null);
            var filter  = factory.Instantiate(aliases, expressions, predicate.Object);
            var result  = filter.Apply(rs);

            Assert.That(result.Rows, Has.Count.EqualTo(2));
        }
示例#9
0
        public void Execute_NotExistingColumnSkipStrategy_IgnoreIssue()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new[] { "100,12", "Alpha" }, new[] { "100", "Beta" }, new[] { "0,1", "Gamma" } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var renamer = new NewNameRenamingEngine(
                new ColumnNameIdentifier("unexistingColumn"),
                new LiteralScalarResolver <string>("myNewName"),
                new SkipAlterationStrategy()
                );
            var newRs = renamer.Execute(rs);

            Assert.That(newRs.Columns.Cast <DataColumn>().Any(c => c.ColumnName == "unexistingColumn"), Is.False);
        }
示例#10
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();

            var settings = new SettingsOrdinalResultSet(KeysChoice.First, ValuesChoice.None, NumericAbsoluteTolerance.None);
            var grouping = new OrdinalColumnGrouping(settings, Context.None);

            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));
        }
示例#11
0
        public void Apply_MixedExpression_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    1, 10, 100
                },
                new List <object>()
                {
                    2, 2, 75
                },
                new List <object>()
                {
                    3, 5, 50
                }
            }));
            var rs = service.Execute();

            rs.Table.Columns[2].ColumnName = "c1";

            var aliases = new List <IColumnAlias>()
            {
                Mock.Of <IColumnAlias>(v => v.Column == 0 && v.Name == "a"),
            };

            var expressions = new List <IColumnExpression>()
            {
                Mock.Of <IColumnExpression>(e => e.Value == "Abs([a])+[e]" && e.Name == "d"),
                Mock.Of <IColumnExpression>(e => e.Value == "[#1]*[c1]" && e.Name == "e")
            };

            var info = Mock.Of <IPredicateInfo>
                       (
                p => p.ComparerType == ComparerType.MoreThanOrEqual &&
                p.ColumnType == ColumnType.Numeric &&
                p.Operand == "d" &&
                p.Reference == (object)200
                       );

            var factory = new PredicateFilterFactory();
            var filter  = factory.Instantiate(aliases, expressions, info);
            var result  = filter.Apply(rs);

            Assert.That(result.Rows, Has.Count.EqualTo(2));
        }
示例#12
0
        public void Execute_SingleColumn_TwoGroups()
        {
            var args      = new ObjectsResultSetResolverArgs(new[] { new object[] { "alpha", 1 }, new object[] { "beta", 2 }, new object[] { "BETA", 3 }, new object[] { "alpha", 4 } });
            var resolver  = new ObjectsResultSetResolver(args);
            var rs        = resolver.Execute();
            var lowerCase = new SinglePredication(new TextLowerCase(false), new ColumnOrdinalIdentifier(0));
            var upperCase = new SinglePredication(new TextUpperCase(false), new ColumnOrdinalIdentifier(0));

            var grouping = new CaseGrouping(new IPredication[] { lowerCase, upperCase }, Context.None);

            var result = grouping.Execute(rs);

            Assert.That(result, Has.Count.EqualTo(2));
            Assert.That(result.ElementAt(0).Value.Rows, Has.Count.EqualTo(3));
            Assert.That(result.ElementAt(1).Value.Rows, Has.Count.EqualTo(1));
        }
示例#13
0
        public void Execute_TwoColumns_ThreeGroups()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new object[] { "alpha", "1", 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();

            var settings = new SettingsOrdinalResultSet(KeysChoice.AllExpectLast, ValuesChoice.None, NumericAbsoluteTolerance.None);
            var grouping = new OrdinalByColumnGrouping(settings);

            var result = grouping.Execute(rs);

            Assert.That(result, Has.Count.EqualTo(3));
            Assert.That(result[new KeyCollection(new object[] { "alpha", "1" })].Rows, Has.Count.EqualTo(2));
            Assert.That(result[new KeyCollection(new object[] { "alpha", "2" })].Rows, Has.Count.EqualTo(1));
            Assert.That(result[new KeyCollection(new object[] { "beta", "2" })].Rows, Has.Count.EqualTo(1));
        }
示例#14
0
        public void Apply_Rows_Success(object[] values, ColumnType columnType, int index)
        {
            var i    = 0;
            var objs = values.Select(x => new object[] { ++i, x }).ToArray();

            var args     = new ObjectsResultSetResolverArgs(objs);
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var ranking    = new BottomRanking(new ColumnOrdinalIdentifier(1), columnType, null, null);
            var filteredRs = ranking.Apply(rs);

            Assert.That(filteredRs.Rows.Count, Is.EqualTo(1));
            Assert.That(filteredRs.Rows[0].ItemArray[0], Is.EqualTo(index.ToString()));
            Assert.That(filteredRs.Rows[0].ItemArray[1], Is.EqualTo(values.Min()));
        }
示例#15
0
        public void Execute_Top2None_ResultSetReduced()
        {
            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();

            var filter = new TopRanking(2, new ColumnOrdinalIdentifier(1), ColumnType.Numeric);

            var rankingByGroup = new GroupByFilter(filter, new NoneGrouping());

            var result = rankingByGroup.Apply(rs);

            Assert.That(result.Table.Rows, Has.Count.EqualTo(2));
            Assert.That(result.Table.Rows.Cast <DataRow>().Where(x => x[0].ToString() == "alpha").Count(), Is.EqualTo(1));
            Assert.That(result.Table.Rows.Cast <DataRow>().Where(x => x[0].ToString() == "beta").Count(), Is.EqualTo(1));
        }
示例#16
0
        public void Apply_MixedExpression_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    1, 10, 100
                },
                new List <object>()
                {
                    2, 2, 75
                },
                new List <object>()
                {
                    3, 5, 50
                }
            }));
            var rs = service.Execute();

            rs.Table.Columns[2].ColumnName = "c1";

            var aliases = new List <IColumnAlias>()
            {
                Mock.Of <IColumnAlias>(v => v.Column == 0 && v.Name == "a"),
            };

            var expressions = new List <IColumnExpression>()
            {
                Mock.Of <IColumnExpression>(e => e.Value == "Abs([a])+[e]" && e.Name == "d" && e.Language == LanguageType.NCalc),
                Mock.Of <IColumnExpression>(e => e.Value == "[#1]*[c1]" && e.Name == "e" && e.Language == LanguageType.NCalc)
            };

            var predicate = new Mock <IPredicateInfo>();

            predicate.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
            predicate.SetupGet(p => p.ComparerType).Returns(ComparerType.MoreThanOrEqual);
            predicate.SetupGet(p => p.Operand).Returns(new ColumnNameIdentifier("d"));
            predicate.As <IReferencePredicateInfo>().SetupGet(p => p.Reference).Returns((object)200);

            var factory = new ResultSetFilterFactory(null);
            var filter  = factory.Instantiate(aliases, expressions, predicate.Object);
            var result  = filter.Apply(rs);

            Assert.That(result.Rows, Has.Count.EqualTo(2));
        }
示例#17
0
        public void Execute_ExistingColumnByName_ColumnRenamed()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new[] { "100,12", "Alpha" }, new[] { "100", "Beta" }, new[] { "0,1", "Gamma" } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            rs.Columns[1].ColumnName = "myOldName";

            var renamer = new NewNameRenamingEngine(
                new ColumnNameIdentifier("myOldName"),
                new LiteralScalarResolver <string>("myNewName")
                );
            var newRs = renamer.Execute(rs);

            Assert.That(newRs.Columns[1].ColumnName, Is.EqualTo("myNewName"));
            Assert.That(newRs.Columns.Cast <DataColumn>().Any(c => c.ColumnName == "myOldName"), Is.False);
        }
示例#18
0
        public void Execute_SingleKeyMultipleValue_ExpectedResultSet()
        {
            var resolver = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new[] {
                new object[] { "alpha", "A", 1, -1 },
                new object[] { "alpha", "B", 2, -2 },
                new object[] { "beta", "A", 3, -3 },
                new object[] { "beta", "B", 4, -4 }
            }
                    ));
            var rs = resolver.Execute();

            rs.Columns[0].ColumnName = "keyColumn";
            rs.Columns[1].ColumnName = "headerColumn";
            rs.Columns[2].ColumnName = "value1Column";
            rs.Columns[3].ColumnName = "value2Column";

            var args = new UnstackArgs(
                new ColumnNameIdentifier("headerColumn"),
                new List <IColumnDefinitionLight>()
            {
                Mock.Of <IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text)
            }
                );

            var unstack = new UnstackEngine(args);
            var result  = unstack.Execute(rs);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Columns.Count, Is.EqualTo(5));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "keyColumn"));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "A_value1Column"));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "B_value1Column"));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "A_value2Column"));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "B_value2Column"));
            Assert.That(result.Rows.Count, Is.EqualTo(2));
            Assert.That(Convert.ToInt32(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "alpha")["A_value1Column"]) == 1);
            Assert.That(Convert.ToInt32(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "alpha")["B_value1Column"]) == 2);
            Assert.That(Convert.ToInt32(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "beta")["A_value1Column"]) == 3);
            Assert.That(Convert.ToInt32(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "beta")["B_value1Column"]) == 4);
            Assert.That(Convert.ToInt32(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "alpha")["A_value2Column"]) == -1);
            Assert.That(Convert.ToInt32(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "alpha")["B_value2Column"]) == -2);
            Assert.That(Convert.ToInt32(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "beta")["A_value2Column"]) == -3);
            Assert.That(Convert.ToInt32(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "beta")["B_value2Column"]) == -4);
        }
示例#19
0
        private NBi.Core.ResultSet.ResultSet BuildLarge(int count)
        {
            var values = new List <object>();

            for (int i = 0; i < count; i++)
            {
                values.Add(new object[] { i % 2 == 0 ? "alpha" : "beta", 1 });
            }

            var args     = new ObjectsResultSetResolverArgs(values);
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            rs.Columns[0].ColumnName = "keyColumn";
            rs.Columns[1].ColumnName = "valueColumn";
            return(rs);
        }
示例#20
0
        public void Apply_TopTwo_Success(object[] values, ColumnType columnType, int[] index)
        {
            var i    = 0;
            var objs = values.Select(x => new object[] { ++i, x }).ToArray();

            var args     = new ObjectsResultSetResolverArgs(objs);
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var ranking    = new TopRanking(2, new ColumnOrdinalIdentifier(1), columnType, null, null);
            var filteredRs = ranking.Apply(rs);

            Assert.That(filteredRs.Rows.Count, Is.EqualTo(2));
            Assert.That(filteredRs.Rows[0].ItemArray[0], Is.EqualTo(index[0]));
            Assert.That(filteredRs.Rows[0].ItemArray[1], Is.EqualTo(values.Max()));
            Assert.That(filteredRs.Rows[1].ItemArray[0], Is.EqualTo(index[1]));
            Assert.That(filteredRs.Rows[1].ItemArray[1], Is.EqualTo(values.Except(Enumerable.Repeat(values.Max(), 1)).Max()));
        }
示例#21
0
        public void Apply_Alias_Success(object[] values, ColumnType columnType, int index)
        {
            var i    = 0;
            var objs = values.Select(x => new object[] { ++i, x }).ToArray();

            var args     = new ObjectsResultSetResolverArgs(objs);
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var alias = Mock.Of <IColumnAlias>(x => x.Column == 1 && x.Name == "myValue");

            var ranking    = new BottomRanking(new ColumnNameIdentifier("myValue"), columnType, Enumerable.Repeat(alias, 1), null);
            var filteredRs = ranking.Apply(rs);

            Assert.That(filteredRs.Rows.Count, Is.EqualTo(1));
            Assert.That(filteredRs.Rows[0].ItemArray[0], Is.EqualTo(index.ToString()));
            Assert.That(filteredRs.Rows[0].ItemArray[1], Is.EqualTo(values.Min()));
        }
示例#22
0
        public void Execute_StandardRsColumnOrdinal_CorrectExtension()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new object[] { "Alpha", 1, 2 }, new object[] { "Beta", 3, 2 }, new object[] { "Gamma", 5, 7 } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var extender = new NCalcExtendEngine(
                new ServiceLocator(),
                new Context(null),
                new ColumnOrdinalIdentifier(3),
                "[#1] * [#2]"
                );
            var newRs = extender.Execute(rs);

            Assert.That(newRs.Columns.Count, Is.EqualTo(4));
            Assert.That(newRs.Rows[0][3], Is.EqualTo(2));
            Assert.That(newRs.Rows[1][3], Is.EqualTo(6));
            Assert.That(newRs.Rows[2][3], Is.EqualTo(35));
        }
示例#23
0
        public void Execute_Top2OneKey_ResultSetReduced()
        {
            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();

            var settings = new SettingsOrdinalResultSet(KeysChoice.First, ValuesChoice.None, NumericAbsoluteTolerance.None);
            var grouping = new OrdinalColumnGrouping(settings, Context.None);

            var filter = new TopRanking(2, new ColumnOrdinalIdentifier(1), ColumnType.Numeric);

            var rankingByGroup = new GroupByFilter(filter, grouping);

            var result = rankingByGroup.Apply(rs);

            Assert.That(result.Table.Rows, Has.Count.EqualTo(3));
            Assert.That(result.Table.Rows.Cast <DataRow>().Where(x => x[0].ToString() == "alpha").Count(), Is.EqualTo(2));
            Assert.That(result.Table.Rows.Cast <DataRow>().Where(x => x[0].ToString() == "beta").Count(), Is.EqualTo(1));
        }
示例#24
0
        public void Apply_Exp_Success(object[] values, ColumnType columnType, int index)
        {
            var i    = 0;
            var objs = values.Select(x => new object[] { ++i, x }).ToArray();

            var args     = new ObjectsResultSetResolverArgs(objs);
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var alias = Mock.Of <IColumnAlias>(x => x.Column == 1 && x.Name == "myValue");
            var exp   = Mock.Of <IColumnExpression>(x => x.Name == "exp" && x.Value == "myValue % 10");

            var ranking    = new TopRanking(new ColumnNameIdentifier("exp"), columnType, Enumerable.Repeat(alias, 1), Enumerable.Repeat(exp, 1));
            var filteredRs = ranking.Apply(rs);

            Assert.That(filteredRs.Rows.Count, Is.EqualTo(1));
            Assert.That(filteredRs.Rows[0].ItemArray[0], Is.EqualTo(index));
            Assert.That(filteredRs.Rows[0].ItemArray[1], Is.EqualTo("139"));
        }
示例#25
0
        public void Execute_EnforcedColumnsThatWasNotExpected_ExpectedResultSet()
        {
            var resolver = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new[] {
                new object[] { "alpha", "A", 1 },
                new object[] { "alpha", "B", 2 },
                new object[] { "beta", "A", 3 },
                new object[] { "beta", "B", 4 }
            }
                    ));
            var rs = resolver.Execute();

            rs.Columns[0].ColumnName = "keyColumn";
            rs.Columns[1].ColumnName = "headerColumn";
            rs.Columns[2].ColumnName = "valueColumn";

            var args = new UnstackArgs(
                new ColumnNameIdentifier("headerColumn"),
                new List <IColumnDefinitionLight>()
            {
                Mock.Of <IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text)
            },
                new List <ColumnNameIdentifier>()
            {
                new ColumnNameIdentifier("C")
            }
                );

            var unstack = new UnstackEngine(args);
            var result  = unstack.Execute(rs);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Columns.Count, Is.EqualTo(4));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "keyColumn"));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "A"));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "B"));
            Assert.That(result.Columns.Cast <DataColumn>().Any(x => x.ColumnName == "C"));
            Assert.That(result.Rows.Count, Is.EqualTo(2));
            Assert.That(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "alpha")["C"] == DBNull.Value);
            Assert.That(result.Rows.Cast <DataRow>().Single(x => x["keyColumn"] as string == "alpha")["C"] == DBNull.Value);
        }
示例#26
0
        public void Execute_TwoColumns_ThreeGroups()
        {
            var args      = new ObjectsResultSetResolverArgs(new[] { new object[] { "alpha", "1", 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();
            var lowerCase = new SinglePredication(new TextLowerCase(false), new ColumnOrdinalIdentifier(0));
            var upperCase = new AndCombinationPredication(new List <IPredication>()
            {
                new SinglePredication(new TextUpperCase(false), new ColumnOrdinalIdentifier(0)),
                new SinglePredication(new TextEqual(false, new LiteralScalarResolver <string>("1")), new ColumnOrdinalIdentifier(1)),
            });

            var grouping = new CaseGrouping(new IPredication[] { lowerCase, upperCase }, Context.None);

            var result = grouping.Execute(rs);

            Assert.That(result, Has.Count.EqualTo(3));
            Assert.That(result.ElementAt(0).Value.Rows, Has.Count.EqualTo(2));
            Assert.That(result.ElementAt(1).Value.Rows, Has.Count.EqualTo(1));
            Assert.That(result.ElementAt(2).Value.Rows, Has.Count.EqualTo(1));
        }
示例#27
0
        public void Execute_MiddleColumnIsText_MiddleColumnIsNumeric()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new[] { "Alpha", "100,12", "true" }, new[] { "Beta", "100", "false" }, new[] { "Gamma", "N/A", "false" } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var factory   = new ConverterFactory();
            var converter = factory.Instantiate("text", "numeric", null, "fr-fr");

            Assert.That(converter, Is.Not.Null);
            Assert.That(converter, Is.TypeOf <TextToNumericConverter>());

            var engine = new ConverterEngine("#1", converter);

            engine.Execute(rs);

            Assert.That(rs.Columns[1].DataType, Is.EqualTo(typeof(decimal)));
            Assert.That(rs.Columns.Count, Is.EqualTo(3));
            Assert.That(rs.Rows[0][1], Is.EqualTo(100.12));
            Assert.That(rs.Rows[1][1], Is.EqualTo(100));
            Assert.That(rs.Rows[2][1], Is.EqualTo(DBNull.Value));
        }
示例#28
0
        public void Apply_UnexistingColumnName_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    "(null)", 10, 100
                },
                new List <object>()
                {
                    "(empty)", 2, 75
                },
                new List <object>()
                {
                    "C", 5, 50
                }
            }));
            var rs = service.Execute();

            rs.Table.Columns[0].ColumnName = "first";
            rs.Table.Columns[1].ColumnName = "second";
            rs.Table.Columns[2].ColumnName = "third";

            var predicate = new Mock <IPredicateInfo>();

            predicate.SetupGet(p => p.ColumnType).Returns(ColumnType.Text);
            predicate.SetupGet(p => p.ComparerType).Returns(ComparerType.NullOrEmpty);
            predicate.SetupGet(p => p.Operand).Returns(new ColumnNameIdentifier("Unexisting"));

            var factory = new ResultSetFilterFactory(null);
            var filter  = factory.Instantiate(new IColumnAlias[0], new IColumnExpression[0], predicate.Object);
            var ex      = Assert.Throws <ArgumentException>(() => filter.Apply(rs));

            Assert.That(ex.Message, Is.StringContaining("first"));
            Assert.That(ex.Message, Is.StringContaining("second"));
            Assert.That(ex.Message, Is.StringContaining("third"));
        }
示例#29
0
        public void Execute_MiddleColumnIsTextualDate_MiddleColumnIsDate()
        {
            var args     = new ObjectsResultSetResolverArgs(new[] { new[] { "Alpha", "06/01/2018", "true" }, new[] { "Beta", "17/12/2015", "false" }, new[] { "Gamma", "Before 2014", "false" } });
            var resolver = new ObjectsResultSetResolver(args);
            var rs       = resolver.Execute();

            var factory   = new ConverterFactory();
            var converter = factory.Instantiate("text", "date", new DateTime(2013, 1, 1), "fr-fr");

            Assert.That(converter, Is.Not.Null);
            Assert.That(converter, Is.TypeOf <TextToDateConverter>());

            var engine = new ConverterEngine("#1", converter);

            engine.Execute(rs);

            Assert.That(rs.Columns[1].DataType, Is.EqualTo(typeof(DateTime)));
            Assert.That(rs.Columns.Count, Is.EqualTo(3));
            Assert.That(rs.Rows[0][1], Is.EqualTo(new DateTime(2018, 1, 6)));
            Assert.That(rs.Rows[1][1], Is.EqualTo(new DateTime(2015, 12, 17)));
            Assert.That(rs.Rows[2][1], Is.EqualTo(new DateTime(2013, 1, 1)));
        }
示例#30
0
        public void Apply_Variable_CorrectResult()
        {
            var service = new ObjectsResultSetResolver(
                new ObjectsResultSetResolverArgs(
                    new object[]
            {
                new List <object>()
                {
                    "(null)", 10, 100
                },
                new List <object>()
                {
                    "(empty)", 2, 75
                },
                new List <object>()
                {
                    "C", 5, 50
                }
            }));

            var rs = service.Execute();

            var aliases = new[] { Mock.Of <IColumnAlias>(v => v.Column == 0 && v.Name == "a") };

            var predicate = new Mock <IPredicateInfo>();

            predicate.SetupGet(p => p.ColumnType).Returns(ColumnType.Text);
            predicate.SetupGet(p => p.ComparerType).Returns(ComparerType.NullOrEmpty);
            predicate.SetupGet(p => p.Operand).Returns(new ColumnNameIdentifier("a"));

            var factory = new ResultSetFilterFactory(null);
            var filter  = factory.Instantiate(aliases, new IColumnExpression[0], predicate.Object);
            var result  = filter.Apply(rs);

            Assert.That(result.Rows, Has.Count.EqualTo(2));
        }