Exemple #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));
        }
Exemple #2
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);
        }
Exemple #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));
        }
        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);
        }
Exemple #5
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);
        }
        public void Write(string filename, ResultSet rs)
        {
            if (rs.Table == null)
                throw new Exception("The underlying Table of the ResultSet cannot be null");

            OnWrite(filename, rs);
        }
Exemple #7
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"));
        }
        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);
        }
        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());
        }
        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));
        }
Exemple #11
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));
        }
        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());
        }
Exemple #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;
 }
        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;
        }
Exemple #15
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));
        }
        protected override void OnWrite(string filename, ResultSet rs)
        {
            var str = BuildContent(rs.Table);

            var file = Path.Combine(Path.GetFullPath(PersistencePath), filename);
            using (StreamWriter outfile = new StreamWriter(file, false, Encoding.UTF8))
            {
                outfile.Write(str);
            }
        }
Exemple #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));
        }
Exemple #18
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;
        }
Exemple #19
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"));
        }
Exemple #20
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"));
        }
 /// <summary>
 /// Handle an IDbCommand and compare its row-count to a another value
 /// </summary>
 /// <param name="actual">An OleDbCommand, SqlCommand or AdomdCommand</param>
 /// <returns>true, if the row-count of query execution validates the child constraint</returns>
 public override bool Matches(object actual)
 {
     if (actual is IDbCommand)
         return Process((IDbCommand)actual);
     else if (actual is ResultSet)
     {
         actualResultSet = (ResultSet)actual;
         return Matches(actualResultSet.Rows.Count);
     }
     else if (actual is int)
         return doMatch(((int)actual));
     else
         return false;
 }
Exemple #22
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));
        }
Exemple #23
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));
        }
Exemple #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));
        }
        public void Execute_PrimarySuccessful_SecondaryNotExecuted()
        {
            var expectedRs = new NBi.Core.ResultSet.ResultSet();
            var primary    = Mock.Of <IResultSetResolver>();

            Mock.Get(primary).Setup(x => x.Execute()).Returns(expectedRs);
            var secondary = Mock.Of <IResultSetResolver>();

            Mock.Get(secondary).Setup(x => x.Execute()).Throws(new ResultSetUnavailableException(null));

            var args     = new IfUnavailableResultSetResolverArgs(primary, secondary);
            var resolver = new IfUnavailableResultSetResolver(args);

            var rs = resolver.Execute();

            Mock.Get(primary).Verify(x => x.Execute(), Times.Once);
            Mock.Get(secondary).Verify(x => x.Execute(), Times.Never);
            Assert.That(rs, Is.EqualTo(expectedRs));
        }
Exemple #26
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"));
        }
Exemple #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));
        }
Exemple #28
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"));
        }
Exemple #29
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)"));
        }
Exemple #30
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);
        }
        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"));
        }
        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"));
        }
Exemple #33
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));
        }
Exemple #34
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));
        }
Exemple #35
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));
        }
        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));
        }
        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);
        }
Exemple #38
0
 public virtual ResultSet Build(ResultSet resultSet)
 {
     return(resultSet);
 }
Exemple #39
0
 public virtual ResultSet Build(IList<IRow> rows)
 {
     var rs = new ResultSet();
     rs.Load(rows);
     return rs;
 }
        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);
        }
 protected abstract void OnWrite(string filename, ResultSet rs);
        protected override void OnWrite(string filename, ResultSet rs)
        {
            var table = rs.Table;

            table.WriteXml(Path.Combine(PersistencePath, filename), XmlWriteMode.WriteSchema, false);
        }
Exemple #43
0
 public static EqualToConstraint EqualTo(ResultSet resultSet)
 {
     var ctr = new EqualToConstraint(resultSet);
     return ctr;
 }
 protected virtual void FormatResultSet(NUnitCtr.MessageWriter writer, ResultSet resultSet)
 {
     var rows = resultSet.Rows.Cast<DataRow>().ToList();
     var textCreator = new ResultSetTextWriter();
     var output = textCreator.BuildContent(rows, rows.Count(), false);
     foreach (var line in output)
         writer.WriteLine(line);
 }
Exemple #45
0
 public EqualToConstraint(ResultSet value)
 {
     this.expect = value;
 }
        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);
        }
Exemple #47
0
 private void doPersist(ResultSet resultSet, string path)
 {
     var writer = new ResultSetCsvWriter(System.IO.Path.GetDirectoryName(path));
     writer.Write(System.IO.Path.GetFileName(path), resultSet);
 }
Exemple #48
0
        protected bool doMatch(ResultSet actual)
        {
            actualResultSet = actual;

            //This is needed if we don't use //ism
            if (expectedResultSet ==  null)
                expectedResultSet = GetResultSet(expect);

            result = Engine.Compare(actualResultSet, expectedResultSet);

            //  Math.Min for result.Difference limits the value to 1 if we've two non matching resultsets
            if ((int)persistanceChoice + Math.Min(1,(int)result.Difference) > 1)
            {
                if ((persistanceItems & PersistanceItems.expected) == PersistanceItems.expected)
                    doPersist(expectedResultSet, GetPersistancePath("Expect"));
                if ((persistanceItems & PersistanceItems.actual) == PersistanceItems.actual)
                    doPersist(actualResultSet, GetPersistancePath("Actual"));
            }

            return result.Difference == ResultSetDifferenceType.None;
        }
Exemple #49
0
        public ResultSet ProcessParallel(IDbCommand actual)
        {
            Trace.WriteLineIf(NBiTraceSwitch.TraceVerbose, string.Format("Queries exectued in parallel."));

            ResultSet rsActual = null;
            System.Threading.Tasks.Parallel.Invoke(
                () => {
                        rsActual = GetResultSet(actual);
                      },
                () => {
                        expectedResultSet = GetResultSet(expect);
                      }
            );

            return rsActual;
        }
Exemple #50
0
 public virtual ResultSet Build(ResultSet resultSet)
 {
     return resultSet;
 }
Exemple #51
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);
        }
 protected override void OnWrite(string filename, ResultSet rs)
 {
     throw new NotImplementedException();
 }
        protected bool doMatch(ResultSet actual)
        {
            this.actualResultSet = actual;

            var validationEngine = new RowValidator();
            evaluationResults = new List<RowEvaluationResult>();
            int rowIndex=0;
            foreach (DataRow row in actualResultSet.Rows)
            {
                var valuedVariables = new Dictionary<string, Object>();
                foreach (var v in variables)
                    valuedVariables.Add(v.Name, row[v.Column]);

                var valuedExpressions = new List<ValuedExpression>();
                foreach (var e in expressions)
                    valuedExpressions.Add(new ValuedExpression(e.Value, row[e.Column], e.Type, e.Tolerance));

                evaluationResults.Add(new RowEvaluationResult(rowIndex, valuedVariables, validationEngine.Execute(valuedVariables, valuedExpressions)));
                rowIndex += 1;
            }
            bool value = evaluationResults.Aggregate<RowEvaluationResult, bool>(true, (total, r) => total && (r.CountExpressionValidationFailed()==0));
            return value;
        }