Ejemplo n.º 1
0
        public void DataFrameToDataSet_FewRows_FastEnougth(int x)
        {
            var objects = new List <object>();

            for (int i = 0; i < x; i++)
            {
                objects.Add(new object[] { i, i.ToString(), null, i * 2 });
            }


            var rs = new NBiRs.ResultSet();

            rs.Load(objects.AsEnumerable().Cast <object[]>());
            Assert.That(rs.Rows.Count, Is.EqualTo(x));
            var frame = Frame.ReadReader(rs.Table.CreateDataReader());

            Assert.That(frame.RowCount, Is.EqualTo(x));


            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var dt = frame.ToDataTable(new string[] { "yo" });

            stopWatch.Stop();
            Assert.That(dt.Rows.Count, Is.EqualTo(x));
            Assert.That(stopWatch.ElapsedMilliseconds, Is.LessThan(5000));
        }
Ejemplo n.º 2
0
        public void Matches_MdxQueryAndResulSetWithCorrectSettings_Matching()
        {
            //Buiding object used during test
            var rs = new ResultSet();
            var objs = new List<object[]>();
            objs.Add(new object[] { "CY 2005", "1874469.00" });
            objs.Add(new object[] { "CY 2006", "4511243.0" });
            objs.Add(new object[] { "CY 2007", "4709851" });
            objs.Add(new object[] { "CY 2008", "1513940" });
            rs.Load(objs);

            var ctr = new EqualToConstraint(rs);
            ctr.Using(new ResultSetComparisonSettings(
                    ResultSetComparisonSettings.KeysChoice.First,
                    ResultSetComparisonSettings.ValuesChoice.Last,
                    new NumericAbsoluteTolerance(500, SideTolerance.Both)
                )
            );

            var query = "SELECT [Measures].[Amount] ON 0, NON EMPTY([Date].[Calendar].[Calendar Year]) ON 1 FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.True);
        }
Ejemplo n.º 3
0
        public void Execute_AllStrategyColumnNotFullyNullOrEmpty_NoColumnRemoved()
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load(new[] { new object[] { 1, 120, "(null)" }, new object[] { 2, 155, "(empty)" }, new object[] { 3, 178, "xyz" } });
            rs.Columns[0].ColumnName = "Col0";
            rs.Columns[1].ColumnName = "Col1";
            rs.Columns[2].ColumnName = "Col2";

            var predicateInfo = Mock.Of <IPredicateInfo>(
                p => p.ComparerType == ComparerType.NullOrEmpty &&
                p.ColumnType == ColumnType.Text &&
                p.Not == true &&
                p.Operand == new ColumnDynamicIdentifier("i", (int i) => i + 1)
                );

            var hold = new HoldWhileCondition(new AllRowsStrategy(), predicateInfo);

            hold.Execute(rs);

            Assert.That(rs.Columns.Count, Is.EqualTo(2));
            Assert.That(rs.Columns[0].ColumnName, Is.EqualTo("Col0"));
            Assert.That(rs.Columns[1].ColumnName, Is.EqualTo("Col1"));
            Assert.That(rs.Rows.Count, Is.EqualTo(3));
        }
Ejemplo n.º 4
0
        public virtual ResultSet Build(IList <IRow> rows)
        {
            var rs = new ResultSet();

            rs.Load(rows);
            return(rs);
        }
Ejemplo n.º 5
0
        public void Execute_LoaderAndTransformer_TransformerCalledWithLoaderResult()
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load("a;1");

            var loaderStub = new Mock <IResultSetResolver>();

            loaderStub.Setup(l => l.Execute()).Returns(rs);
            var loader = loaderStub.Object;

            var transformerMock = new Mock <TransformationProviderMockable>();

            transformerMock.Setup(l => l.Transform(rs));
            var transformer = transformerMock.Object;

            var builder = new ResultSetServiceBuilder();

            builder.Setup(loader);
            if (transformer != null)
            {
                builder.Setup(transformer.Transform);
            }
            var service = builder.GetService();

            service.Execute();

            transformerMock.Verify(t => t.Transform(rs), Times.Once);
        }
Ejemplo n.º 6
0
        public void Execute_AllStrategyColumnNotFullyNullOrEmpty_NoColumnRemoved()
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load(new[] { new object[] { "(null)", 1, 120 }, new object[] { "(empty)", 2, 155 }, new object[] { "xyz", 3, 178 } });
            rs.Columns[0].ColumnName = "Col0";
            rs.Columns[1].ColumnName = "Col1";
            rs.Columns[2].ColumnName = "Col2";

            var predicateInfo = Mock.Of <IPredicateInfo>(
                p => p.ComparerType == ComparerType.NullOrEmpty &&
                p.ColumnType == ColumnType.Text &&
                p.Not == false &&
                p.Operand == new ColumnPositionIdentifier(0)
                );

            var remove = new RemoveWhileCondition(new AllRowsStrategy(), predicateInfo);

            remove.Execute(rs);

            Assert.That(rs.Columns.Count, Is.EqualTo(3));
            Assert.That(rs.Columns[0].ColumnName, Is.EqualTo("Col0"));
            Assert.That(rs.Columns[1].ColumnName, Is.EqualTo("Col1"));
            Assert.That(rs.Columns[2].ColumnName, Is.EqualTo("Col2"));
            Assert.That(rs.Rows.Count, Is.EqualTo(3));
        }
Ejemplo n.º 7
0
        public void Matches_AnyIDbCommandAsActualAndAnyPathAsExpectation_EngineCompareTheTwoResultSetsPreviouslyCreated()
        {
            var rsActual = new ResultSet();
            rsActual.Load("a;b;c");
            var rsExpect = new ResultSet();
            rsExpect.Load("x;y;z");
            var cmd = new SqlCommand();

            var rsbStub = new Mock<IResultSetBuilder>();
            rsbStub.Setup(engine => engine.Build(It.IsAny<IDbCommand>()))
                .Returns(rsActual);
            rsbStub.Setup(engine => engine.Build(It.IsAny<string>()))
                .Returns(rsExpect);

            var rsbFake = rsbStub.Object;

            var rscMock = new Mock<IResultSetComparer>();
            rscMock.Setup(engine => engine.Compare(rsActual, rsExpect))
                .Returns(ResultSetCompareResult.NotMatching);
            var rsc = rscMock.Object;

            var equalToConstraint = new EqualToConstraint("my path for expectation") {ResultSetBuilder = rsbFake, Engine = rsc };

            //Method under test
            equalToConstraint.Matches(cmd);

            //Test conclusion
            //Test conclusion
            rscMock.Verify(engine => engine.Compare(rsActual, rsExpect), Times.Once());
        }
Ejemplo n.º 8
0
        public void Execute_LoaderAndTwoAlters_SecondAlterCalledWithResultOfFirst()
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load("a;1");

            var loaderStub = new Mock <IResultSetResolver>();

            loaderStub.Setup(l => l.Execute()).Returns(It.IsAny <NBi.Core.ResultSet.ResultSet>());
            var loader = loaderStub.Object;

            var transformer1Stub = new Mock <TransformationProviderMockable>();

            transformer1Stub.Setup(l => l.Transform(It.IsAny <NBi.Core.ResultSet.ResultSet>())).Returns(rs);
            var transformer1 = transformer1Stub.Object;

            var transformer2Mock = new Mock <TransformationProviderMockable>();

            transformer2Mock.Setup(l => l.Transform(It.IsAny <NBi.Core.ResultSet.ResultSet>()));
            var transformer2 = transformer2Mock.Object;

            var builder = new ResultSetServiceBuilder();

            builder.Setup(loader);
            builder.Setup(transformer1.Transform);
            builder.Setup(transformer2.Transform);
            var service = builder.GetService();

            service.Execute();

            transformer2Mock.Verify(t => t.Transform(rs), Times.Once);
        }
Ejemplo n.º 9
0
        public void Load_ThreeIRowsWithTwoICells_ThreeRowsAndTwoColumns()
        {
            var objects = new RowXml[] {
                new RowXml {
                    _cells= new List<CellXml> {
                        new CellXml() {Value= "CY 2001"},
                        new CellXml() {Value= "1000"}
                    }
                },
                new RowXml {
                     _cells= new List<CellXml> {
                        new CellXml() {Value= "CY 2002"},
                        new CellXml() {Value= "10.4"}
                    }
                },
                new RowXml {
                     _cells= new List<CellXml> {
                        new CellXml() {Value= "CY 2003"},
                        new CellXml() {Value= "200"}
                    }
                }
            };

            var rs = new NBiRs.ResultSet();
            rs.Load(objects);

            Assert.That(rs.Columns.Count, Is.EqualTo(2));
            Assert.That(rs.Rows.Count, Is.EqualTo(3));

            Assert.That(rs.Rows[0].ItemArray[0], Is.EqualTo("CY 2001"));
            Assert.That(rs.Rows[0].ItemArray[1], Is.EqualTo("1000"));
        }
Ejemplo n.º 10
0
        public void Matches_AnyResultSets_EngineCalledOnceResultSetBuilderTwice()
        {
            var rs = new ResultSet();
            rs.Load("a;b;c");
            var cmd = new SqlCommand();

            var rsbMock = new Mock<ResultSetBuilder>();
            rsbMock.Setup(engine => engine.Build(It.IsAny<object>()))
                .Returns(rs);
            var rsb = rsbMock.Object;

            var rscMock = new Mock<IResultSetComparer>();
            rscMock.Setup(engine => engine.Compare(It.IsAny<ResultSet>(), It.IsAny<ResultSet>()))
                .Returns(new ResultSetCompareResult() { Difference = ResultSetDifferenceType.None });
            var rsc = rscMock.Object;

            var equalToConstraint = new EqualToConstraint(rs) {Engine = rsc, ResultSetBuilder=rsb };
            equalToConstraint.ResultSetBuilder = rsb;

            //Method under test
            equalToConstraint.Matches(cmd);

            //Test conclusion
            //Test conclusion
            rscMock.Verify(engine => engine.Compare(It.IsAny<ResultSet>(), It.IsAny<ResultSet>()), Times.Once());
            rsbMock.Verify(engine => engine.Build(It.IsAny<object>()), Times.Exactly(2));
        }
        private (Rs.ResultSet rs, ISequenceResolver resolver) Initialize()
        {
            var dataTable = new DataTable()
            {
                TableName = "MyTable"
            };

            dataTable.Columns.Add(new DataColumn("Id"));
            dataTable.Columns.Add(new DataColumn("Numeric value"));
            dataTable.Columns.Add(new DataColumn("Boolean value"));
            for (int i = 0; i < 20; i++)
            {
                dataTable.LoadDataRow(new object[] { "Alpha", i, true }, false);
            }
            dataTable.AcceptChanges();
            var rs = new Rs.ResultSet();

            rs.Load(dataTable);

            var scalarResolvers = new List <IScalarResolver>()
            {
                new LiteralScalarResolver <string>("2015-01-01"),
                new LiteralScalarResolver <string>("2016-01-01"),
                new LiteralScalarResolver <string>("2017-01-01"),
            };
            var args     = new ListSequenceResolverArgs(scalarResolvers);
            var resolver = new ListSequenceResolver <DateTime>(args);

            return(rs, resolver);
        }
Ejemplo n.º 12
0
        public void Matches_IDbCommandAsActualAndPathAsExpectation_ResulSetBuildersCreateResultSetsUsingActualAndExpectationProvided()
        {
            var rsActual = new ResultSet();
            rsActual.Load("a;b;1");
            var rsExpect = new ResultSet();
            rsExpect.Load("x;y;2");
            var cmd = new SqlCommand();

            var rsbMock = new Mock<IResultSetBuilder>();
            rsbMock.Setup(engine => engine.Build(cmd))
                .Returns(rsActual);
            rsbMock.Setup(engine => engine.Build("my path for expectation"))
                .Returns(rsExpect);
            var rsb = rsbMock.Object;

            var equalToConstraint = new EqualToConstraint("my path for expectation") {ResultSetBuilder = rsb };

            //Method under test
            equalToConstraint.Matches(cmd);

            //Test conclusion
            //Test conclusion
            rsbMock.Verify(engine => engine.Build(cmd), Times.Once());
            rsbMock.Verify(engine => engine.Build("my path for expectation"), Times.Once());
        }
Ejemplo n.º 13
0
 public virtual ResultSet Build(IDbCommand cmd)
 {
     var qe = new QueryEngineFactory().GetExecutor(cmd);
     var ds = qe.Execute();
     var rs = new ResultSet();
     rs.Load(ds);
     return rs;
 }
Ejemplo n.º 14
0
        public virtual ResultSet Build(string path)
        {
            var reader = new CsvReader(profile);
            var dataTable = reader.Read(path, false);

            var rs = new ResultSet();
            rs.Load(dataTable);
            return rs;
        }
Ejemplo n.º 15
0
        public virtual ResultSet Build(IDbCommand cmd)
        {
            var qe = new QueryEngineFactory().GetExecutor(cmd);
            var ds = qe.Execute();
            var rs = new ResultSet();

            rs.Load(ds);
            return(rs);
        }
Ejemplo n.º 16
0
        public virtual ResultSet Build(string path)
        {
            var reader    = new CsvReader(profile);
            var dataTable = reader.Read(path, false);

            var rs = new ResultSet();

            rs.Load(dataTable);
            return(rs);
        }
Ejemplo n.º 17
0
        public void Load_TwoObjectsArray_TwoRowsAndThreeColumns()
        {
            var objects = new object[] { new object[] { "A", "B", "C" }, new object[] { "D", "E", "F" } }.AsEnumerable().Cast<object[]>();

            var rs = new NBiRs.ResultSet();
            rs.Load(objects);

            Assert.That(rs.Columns.Count, Is.EqualTo(3));
            Assert.That(rs.Rows.Count, Is.EqualTo(2));
        }
Ejemplo n.º 18
0
        public void Load_TwoObjectsArray_TwoRowsAndThreeColumns()
        {
            var objects = new object[] { new object[] { "A", "B", "C" }, new object[] { "D", "E", "F" } }.AsEnumerable().Cast <object[]>();

            var rs = new NBiRs.ResultSet();

            rs.Load(objects);

            Assert.That(rs.Columns.Count, Is.EqualTo(3));
            Assert.That(rs.Rows.Count, Is.EqualTo(2));
        }
Ejemplo n.º 19
0
        public ResultSet Parse(string raw)
        {
            raw = raw.Replace(Definition.TextQualifier.ToString(), "");
            var rows = raw.Split(new string[] {"\r\n"}, System.StringSplitOptions.RemoveEmptyEntries);
            var rowfields = rows.Select<string, string[]>(
                r=> r.Split(new char[] { Definition.FieldSeparator }, System.StringSplitOptions.RemoveEmptyEntries)
                );

            var rs = new ResultSet();
            rs.Load(rowfields);
            return rs;
        }
Ejemplo n.º 20
0
        public void Execute_FirstRowByOrdinal_CorrectEvaluation()
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load(new[] { new object[] { "a", 1 }, new object[] { "b", 2 } });

            var context  = Context.None;
            var args     = new ContextScalarResolverArgs(context, new ColumnOrdinalIdentifier(0));
            var resolver = new ContextScalarResolver <string>(args);

            context.Switch(rs.Table.Rows[0]);
            Assert.That(resolver.Execute(), Is.EqualTo("a"));
        }
Ejemplo n.º 21
0
        public ResultSet Parse(string raw)
        {
            raw = raw.Replace(Definition.TextQualifier.ToString(), "");
            var rows      = raw.Split(new string[] { "\r\n" }, System.StringSplitOptions.RemoveEmptyEntries);
            var rowfields = rows.Select <string, string[]>(
                r => r.Split(new char[] { Definition.FieldSeparator }, System.StringSplitOptions.RemoveEmptyEntries)
                );

            var rs = new ResultSet();

            rs.Load(rowfields);
            return(rs);
        }
Ejemplo n.º 22
0
        public void Load_ThreeIRowsWithTwoICells_ThreeRowsAndTwoColumns()
        {
            var objects = new RowXml[] {
                new RowXml {
                    _cells = new List <CellXml> {
                        new CellXml()
                        {
                            Value = "CY 2001"
                        },
                        new CellXml()
                        {
                            Value = "1000"
                        }
                    }
                },
                new RowXml {
                    _cells = new List <CellXml> {
                        new CellXml()
                        {
                            Value = "CY 2002"
                        },
                        new CellXml()
                        {
                            Value = "10.4"
                        }
                    }
                },
                new RowXml {
                    _cells = new List <CellXml> {
                        new CellXml()
                        {
                            Value = "CY 2003"
                        },
                        new CellXml()
                        {
                            Value = "200"
                        }
                    }
                }
            };

            var rs = new NBiRs.ResultSet();

            rs.Load(objects);

            Assert.That(rs.Columns.Count, Is.EqualTo(2));
            Assert.That(rs.Rows.Count, Is.EqualTo(3));

            Assert.That(rs.Rows[0].ItemArray[0], Is.EqualTo("CY 2001"));
            Assert.That(rs.Rows[0].ItemArray[1], Is.EqualTo("1000"));
        }
Ejemplo n.º 23
0
        public virtual ResultSet Build(string path)
        {
            if (!System.IO.File.Exists(path))
            {
                throw new ExternalDependencyNotFoundException(path);
            }

            var reader    = new CsvReader(profile);
            var dataTable = reader.Read(path);

            var rs = new ResultSet();

            rs.Load(dataTable);
            return(rs);
        }
Ejemplo n.º 24
0
        public void Execute_DuplicatedIdentifiers_ColumnFilterped(string id1, string id2)
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load("a;1;120");
            rs.Columns[0].ColumnName = "Foo";
            rs.Columns[1].ColumnName = "Col1";
            rs.Columns[2].ColumnName = "Col2";

            var factory = new ColumnIdentifierFactory();

            var filter = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate(id1), factory.Instantiate(id2) }));

            filter.Execute(rs);

            Assert.That(rs.Columns.Count, Is.EqualTo(1));
        }
Ejemplo n.º 25
0
        public void Transform_NativeTranformationUnknown_Exception()
        {
            var resultSet = new NBi.Core.ResultSet.ResultSet();

            resultSet.Load("\t;10");

            var transformation = Mock.Of <ITransformationInfo>
                                 (
                t => t.Language == LanguageType.Native &&
                t.OriginalType == NBi.Core.ResultSet.ColumnType.Text &&
                t.Code == "unknown"
                                 );

            var provider = new TransformationProvider();

            Assert.Throws <NotImplementedTransformationException>(() => provider.Add(new ColumnOrdinalIdentifier(0), transformation));
        }
Ejemplo n.º 26
0
        public void Execute_NonExistingIdentifiers_ColumnSkipped(string id)
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load("a;1;120");
            rs.Columns[0].ColumnName = "Foo";
            rs.Columns[1].ColumnName = "Col1";
            rs.Columns[2].ColumnName = "Col2";

            var factory = new ColumnIdentifierFactory();

            var skip = new ProjectAwayEngine(new ProjectAwayArgs(new[] { factory.Instantiate(id) }));

            skip.Execute(rs);

            Assert.That(rs.Columns.Count, Is.EqualTo(3));
        }
Ejemplo n.º 27
0
        public void Execute_LoaderOnly_ReturnsLoadedResultSet()
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load("a;1");

            var loaderMock = new Mock <IResultSetResolver>();

            loaderMock.Setup(l => l.Execute()).Returns(rs);
            var loader = loaderMock.Object;

            var builder = new ResultSetServiceBuilder();

            builder.Setup(loader);
            var service = builder.GetService();
            var result  = service.Execute();

            Assert.That(result, Is.EqualTo(rs));
        }
Ejemplo n.º 28
0
        public void Execute_MultipleIdentifiersNotSameOrder_ColumnFilteredOrderChanged(string id1, string id2)
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load("a;1;120");
            rs.Columns[0].ColumnName = "Foo";
            rs.Columns[1].ColumnName = "Col1";
            rs.Columns[2].ColumnName = "Bar";

            var factory = new ColumnIdentifierFactory();

            var project = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate(id1), factory.Instantiate(id2) }));

            project.Execute(rs);

            Assert.That(rs.Columns.Count, Is.EqualTo(2));
            Assert.That(rs.Columns[0].ColumnName, Is.EqualTo("Bar"));
            Assert.That(rs.Columns[1].ColumnName, Is.EqualTo("Foo"));
        }
Ejemplo n.º 29
0
        public void Execute_LoaderOnly_LoaderCalled()
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load("a;1");

            var loaderMock = new Mock <IResultSetResolver>();

            loaderMock.Setup(l => l.Execute()).Returns(rs);
            var loader = loaderMock.Object;

            var builder = new ResultSetServiceBuilder();

            builder.Setup(loader);
            var service = builder.GetService();

            service.Execute();

            loaderMock.Verify(l => l.Execute(), Times.Once);
        }
Ejemplo n.º 30
0
        public void Transform_SimpleTranformation_Correct()
        {
            var resultSet = new NBi.Core.ResultSet.ResultSet();

            resultSet.Load("aaaa;10");

            var transformation = Mock.Of <ITransformationInfo>
                                 (
                t => t.Language == LanguageType.CSharp &&
                t.OriginalType == NBi.Core.ResultSet.ColumnType.Text &&
                t.Code == "value.Substring(0,1)"
                                 );

            var provider = new TransformationProvider();

            provider.Add(new ColumnOrdinalIdentifier(0), transformation);
            provider.Transform(resultSet);

            Assert.That(resultSet.Rows[0][0], Is.EqualTo("a"));
        }
Ejemplo n.º 31
0
        public void Transform_NativeTranformationBlankToNull_Correct()
        {
            var resultSet = new NBi.Core.ResultSet.ResultSet();

            resultSet.Load("\t;10");

            var transformation = Mock.Of <ITransformationInfo>
                                 (
                t => t.Language == LanguageType.Native &&
                t.OriginalType == NBi.Core.ResultSet.ColumnType.Text &&
                t.Code == "blank-to-null"
                                 );

            var provider = new TransformationProvider();

            provider.Add(new ColumnOrdinalIdentifier(0), transformation);
            provider.Transform(resultSet);

            Assert.That(resultSet.Rows[0][0], Is.EqualTo("(null)"));
        }
Ejemplo n.º 32
0
        public void Transform_NativeTranformationTrim_Correct()
        {
            var resultSet = new NBi.Core.ResultSet.ResultSet();

            resultSet.Load(" aaaa  ;10");

            var transformation = Mock.Of <ITransformationInfo>
                                 (
                t => t.Language == LanguageType.Native &&
                t.OriginalType == ColumnType.Text &&
                t.Code == "text-to-trim"
                                 );

            var provider = new TransformationProvider(new ServiceLocator(), Context.None);

            provider.Add(new ColumnOrdinalIdentifier(0), transformation);
            provider.Transform(resultSet);

            Assert.That(resultSet.Rows[0][0], Is.EqualTo("aaaa"));
        }
Ejemplo n.º 33
0
        public void Transform_NativeTranformationFirstCharWithContext_Correct()
        {
            var resultSet = new NBi.Core.ResultSet.ResultSet();

            resultSet.Load(new[] { new object[] { "123456789", 6 }, new object[] { "abcdefgh", 2 } });

            var transformation = Mock.Of <ITransformationInfo>
                                 (
                t => t.Language == LanguageType.Native &&
                t.OriginalType == ColumnType.Text &&
                t.Code == "text-to-first-chars(#1)"
                                 );

            var provider = new TransformationProvider(new ServiceLocator(), Context.None);

            provider.Add(new ColumnOrdinalIdentifier(0), transformation);
            provider.Transform(resultSet);

            Assert.That(resultSet.Rows[0][0], Is.EqualTo("123456"));
            Assert.That(resultSet.Rows[1][0], Is.EqualTo("ab"));
        }
Ejemplo n.º 34
0
        public void Transform_TypeSwitch_Correct()
        {
            var resultSet = new NBi.Core.ResultSet.ResultSet();
            var obj       = new object[] { new DateTime(2016, 10, 1) };

            resultSet.Load(Enumerable.Repeat(obj, 1));

            var transformation = Mock.Of <ITransformationInfo>
                                 (
                t => t.Language == LanguageType.CSharp &&
                t.OriginalType == NBi.Core.ResultSet.ColumnType.DateTime &&
                t.Code == "value.Month + (value.Year-2000)*12"
                                 );

            var provider = new TransformationProvider();

            provider.Add(new ColumnOrdinalIdentifier(0), transformation);
            provider.Transform(resultSet);

            Assert.That(resultSet.Rows[0][0], Is.EqualTo(202));
        }
Ejemplo n.º 35
0
        public void Execute_AllStrategyAllColumnNotNullOrEmpty_ThreeColumnsHold()
        {
            var rs = new NBi.Core.ResultSet.ResultSet();

            rs.Load(new[] { new object[] { "xyz", 1, 120 }, new object[] { "abc", 2, 155 } });
            rs.Columns[0].ColumnName = "Col0";
            rs.Columns[1].ColumnName = "Col1";
            rs.Columns[2].ColumnName = "Col2";

            var predicateInfo = Mock.Of <IPredicateInfo>(
                p => p.ComparerType == ComparerType.NullOrEmpty &&
                p.ColumnType == ColumnType.Text &&
                p.Not == true &&
                p.Operand == new ColumnDynamicIdentifier("i", (int i) => i + 1)
                );

            var hold = new HoldWhileCondition(new AllRowsStrategy(), predicateInfo);

            hold.Execute(rs);

            Assert.That(rs.Columns.Count, Is.EqualTo(3));
            Assert.That(rs.Rows.Count, Is.EqualTo(2));
        }
Ejemplo n.º 36
0
        public void Load_ThreeIRowsWithTwoICells_ThreeRowsAndTwoColumns()
        {
            var objects = new List <IRow> {
                Mock.Of <IRow> (
                    x => x.Cells == new List <ICell> {
                    Mock.Of <ICell>(y => (string)(y.Value) == "CY 2001"),
                    Mock.Of <ICell>(y => (decimal)(y.Value) == 1000)
                }
                    )
                ,
                Mock.Of <IRow>(
                    x => x.Cells == new List <ICell> {
                    Mock.Of <ICell>(y => (string)(y.Value) == "CY 2002"),
                    Mock.Of <ICell>(y => (decimal)(y.Value) == 10.4m)
                }
                    )
                ,
                Mock.Of <IRow>(
                    x => x.Cells == new List <ICell> {
                    Mock.Of <ICell>(y => (string)(y.Value) == "CY 2003"),
                    Mock.Of <ICell>(y => (decimal)(y.Value) == 200)
                }
                    )
            };

            var rs = new NBiRs.ResultSet();

            rs.Load(objects);

            Assert.That(rs.Columns.Count, Is.EqualTo(2));
            Assert.That(rs.Rows.Count, Is.EqualTo(3));

            Assert.That(rs.Rows[0].ItemArray[0], Is.EqualTo("CY 2001"));
            Assert.That(rs.Rows[0].ItemArray[1], Is.EqualTo(1000));
            Assert.That(rs.Rows[1].ItemArray[0], Is.EqualTo("CY 2002"));
            Assert.That(rs.Rows[1].ItemArray[1], Is.EqualTo(10.4));
        }
Ejemplo n.º 37
0
        public void Transform_SimpleTranformation_CorrectHandlingOfColumnNames()
        {
            var resultSet = new NBi.Core.ResultSet.ResultSet();

            resultSet.Load("aaaa;10");
            resultSet.Columns[0].ColumnName = "MyCol0";
            resultSet.Columns[1].ColumnName = "MyCol1";

            var transformation = Mock.Of <ITransformationInfo>
                                 (
                t => t.Language == LanguageType.CSharp &&
                t.OriginalType == ColumnType.Text &&
                t.Code == "value.Substring(0,1)"
                                 );

            var provider = new TransformationProvider(new ServiceLocator(), Context.None);

            provider.Add(new ColumnOrdinalIdentifier(0), transformation);
            provider.Transform(resultSet);

            Assert.That(resultSet.Columns[0].ColumnName, Is.EqualTo("MyCol0"));
            Assert.That(resultSet.Columns[1].ColumnName, Is.EqualTo("MyCol1"));
            Assert.That(resultSet.Columns.Count, Is.EqualTo(2));
        }
Ejemplo n.º 38
0
 public virtual ResultSet Build(IList<IRow> rows)
 {
     var rs = new ResultSet();
     rs.Load(rows);
     return rs;
 }
Ejemplo n.º 39
0
        public ResultSet Build(string json)
        {
            var dt = (DataTable)JsonConvert.DeserializeObject(json, (typeof(DataTable)));

            var isArrayConverted = false;

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                var column = dt.Columns[i];
                if (column.DataType == typeof(DataTable))
                {
                    if (isArrayConverted)
                    {
                        throw new InvalidOperationException("NBi can't convert a JSON document with more than one array to a result-set.");
                    }

                    isArrayConverted = true;
                    var newColumns = new List <DataColumn>();
                    foreach (DataRow row in dt.Rows)
                    {
                        if ((row.ItemArray[column.Ordinal]) is DataTable rowTable) //could be the case if the array is empty
                        {
                            foreach (DataColumn subColumn in rowTable.Columns)
                            {
                                var columnName = string.Format("{0}.{1}", column.ColumnName, subColumn.ColumnName);
                                if (!newColumns.Exists(c => c.ColumnName == columnName))
                                {
                                    var newColumn = new DataColumn()
                                    {
                                        ColumnName   = columnName,
                                        DataType     = subColumn.DataType,
                                        AllowDBNull  = true,
                                        DefaultValue = DBNull.Value
                                    };
                                    newColumn.ExtendedProperties.Add("split", subColumn.ColumnName);
                                    newColumns.Add(newColumn);
                                }
                            }
                        }
                    }

                    var j = 1;
                    foreach (var newColumn in newColumns)
                    {
                        dt.Columns.Add(newColumn);
                        newColumn.SetOrdinal(column.Ordinal + j);
                        j++;
                    }

                    var k = 0;
                    while (k < dt.Rows.Count)
                    {
                        var masterRow = dt.Rows[k];
                        var subTable  = (masterRow.ItemArray[column.Ordinal]) as DataTable;
                        var l         = 1;
                        foreach (DataRow rowTable in subTable.Rows)
                        {
                            var newRow = dt.NewRow();
                            foreach (DataColumn columnIter in dt.Columns)
                            {
                                if (column != columnIter && !columnIter.ExtendedProperties.ContainsKey("split"))
                                {
                                    newRow[columnIter] = masterRow[columnIter];
                                }
                                else if (column != columnIter && columnIter.ExtendedProperties.ContainsKey("split"))
                                {
                                    var columnName = (string)columnIter.ExtendedProperties["split"];
                                    if (rowTable.Table.Columns.Contains(columnName))
                                    {
                                        newRow[columnIter] = rowTable[columnName];
                                    }
                                }
                            }
                            dt.Rows.InsertAt(newRow, k + l);
                            l++;
                        }
                        if (l > 1) //If the array is empty we don't need to remove the row!
                        {
                            dt.Rows.RemoveAt(k);
                        }

                        k += l;
                    }

                    dt.Columns.Remove(column);

                    foreach (DataColumn columnIter in dt.Columns)
                    {
                        if (columnIter.ExtendedProperties.ContainsKey("split"))
                        {
                            columnIter.ExtendedProperties.Remove("split");
                        }
                    }
                }
            }


            var rs = new ResultSet();

            rs.Load(dt);
            return(rs);
        }
Ejemplo n.º 40
0
        public void Matches_TwoIdenticalResultSets_ReturnTrue()
        {
            var rs = new ResultSet();
            rs.Load("a;X;1");

            var cmd = new SqlCommand();

            var rsbMock = new Mock<IResultSetBuilder>();
            rsbMock.Setup(engine => engine.Build(It.IsAny<IDbCommand>()))
                .Returns(rs);
            rsbMock.Setup(engine => engine.Build(rs))
                .Returns(rs);
            var rsb = rsbMock.Object;

            var equalToConstraint = new EqualToConstraint(rs) { ResultSetBuilder = rsb };

            //Method under test
            var res = equalToConstraint.Matches(cmd);

            //Test conclusion
            rsbMock.Verify(engine => engine.Build(rs), Times.Once());
            Assert.That(res, Is.True);
        }
Ejemplo n.º 41
0
        public void Matches_MdxQueryAndResulSetWithoutKeyValuesInfo_Matching()
        {
            //Buiding object used during test
            var rs = new ResultSet();
            var objs = new List<object[]>();
            objs.Add(new object[] { "CY 2005", "1874469.00" });
            objs.Add(new object[] { "CY 2006", "4511243.0" });
            objs.Add(new object[] { "CY 2007", "4709851" });
            objs.Add(new object[] { "CY 2008", "1513940" });
            rs.Load(objs);

            var ctr = new EqualToConstraint(rs);

            var query = "SELECT [Measures].[Amount] ON 0, NON EMPTY([Date].[Calendar].[Calendar Year]) ON 1 FROM [Adventure Works]";
            var cmd = new AdomdCommand(query, new AdomdConnection(ConnectionStringReader.GetAdomd()));

            //Call the method to test
            var actual = ctr.Matches(cmd);

            //Assertion
            Assert.That(actual, Is.True);
        }
Ejemplo n.º 42
0
        public void Matches_TwoDifferentResultSets_ReturnFalse()
        {
            var rsActual = new ResultSet();
            rsActual.Load("a;b;1");
            var rsExpect = new ResultSet();
            rsExpect.Load("a;X;1");

            var cmd = new SqlCommand();

            var rsbMock = new Mock<IResultSetBuilder>();
            rsbMock.Setup(engine => engine.Build(It.IsAny<IDbCommand>()))
                .Returns(rsActual);
            rsbMock.Setup(engine => engine.Build(rsExpect))
                .Returns(rsExpect);
            var rsb = rsbMock.Object;

            var equalToConstraint = new EqualToConstraint(rsExpect) {ResultSetBuilder = rsb };

            //Method under test
            var res = equalToConstraint.Matches(cmd);

            //Test conclusion
            rsbMock.Verify(engine => engine.Build(rsExpect), Times.Once());
            Assert.That(res, Is.False);
        }