示例#1
0
        public void BuildMdx_WithUselessParameter_CorrectResultSet()
        {
            var commandBuilder = new CommandBuilder();
            var cmd = commandBuilder.Build(
                ConnectionStringReader.GetAdomd(),
                "select " +
                    "[Measures].[Order Count] on 0, " +
                    "strToMember(@Param) on 1 "+
                "from "+
                    "[Adventure Works]",

                new List<QueryParameterXml>()
                {
                    new QueryParameterXml()
                    {
                        Name="@Param",
                        StringValue = "[Product].[Model Name].[Bike Wash]"
                    },
                    new QueryParameterXml()
                    {
                        Name="UnusedParam",
                        StringValue = "Useless"
                    }
                }
                );

            cmd.Connection.Open();
            var dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            Assert.That(dr.Read(), Is.True);
            Assert.That(dr.GetValue(0), Is.EqualTo("Bike Wash"));
            Assert.That(dr.Read(), Is.False);
        }
        protected override IDbCommand InstantiateSystemUnderTest(ExecutionXml xml)
        {
            if (xml.Item is QueryableXml)
            {
                var commandText = (xml.Item as QueryableXml).GetQuery();
                var connectionString = xml.Item.GetConnectionString();
                var parameters = (xml.Item as QueryableXml).GetParameters();
                var variables = (xml.Item as QueryableXml).GetVariables();

                var commandBuilder = new CommandBuilder();
                var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables);
                return cmd;
            }
            throw new ArgumentException();
        }
        protected virtual IDbCommand InstantiateSystemUnderTest(ExecutionXml executionXml)
        {
            var commandBuilder = new CommandBuilder();

            var connectionString = executionXml.Item.GetConnectionString();
            var commandText = (executionXml.Item as QueryableXml).GetQuery();

            IEnumerable<IQueryParameter> parameters=null;
            IEnumerable<IQueryTemplateVariable> variables = null;
            if (executionXml.BaseItem is QueryXml)
            {
                parameters = ((QueryXml)executionXml.BaseItem).GetParameters();
                variables = ((QueryXml)executionXml.BaseItem).GetVariables();
            }
            if (executionXml.BaseItem is ReportXml)
            {
                parameters = ((ReportXml)executionXml.BaseItem).GetParameters();
            }
            var cmd = commandBuilder.Build(connectionString, commandText, parameters, variables);

            return cmd;
        }
示例#4
0
        public void Build_OneParameterWithoutTypeInt_CorrectResultSet()
        {
            var commandBuilder = new CommandBuilder();
            var cmd = commandBuilder.Build(
                ConnectionStringReader.GetSqlClient(),
                "select * from [Sales].[Customer] where CustomerID=@Param",

                new List<QueryParameterXml>()
                {
                    new QueryParameterXml()
                    {
                        Name="Param",
                        StringValue = "2"
                    }
                }
                );

            cmd.Connection.Open();
            var dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            Assert.That(dr.Read(), Is.True);
            Assert.That(dr.GetValue(0), Is.EqualTo(2));
            Assert.That(dr.Read(), Is.False);
        }
示例#5
0
        protected global::NUnit.Framework.Constraints.Constraint InstantiateConstraint()
        {
            EqualToConstraint ctr = null;

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

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

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

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

            ctr.Using(settings);

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

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

            return ctr;
        }
        protected NBiConstraint InstantiateConstraint()
        {
            EqualToConstraint ctr = null;

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

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

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

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

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

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

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

            ctr.Using(settings);

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

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

            return ctr;
        }
示例#7
0
        public void Build_WithUselessParameter_CorrectResultSet()
        {
            var commandBuilder = new CommandBuilder();
            var cmd = commandBuilder.Build(
                ConnectionStringReader.GetSqlClient(),
                "select * from [Sales].[SalesTerritory] where Name=@Param",

                new List<QueryParameterXml>()
                {
                    new QueryParameterXml()
                    {
                        Name="@Param",
                        StringValue = "Canada"
                    },
                    new QueryParameterXml()
                    {
                        Name="@UnusedParam",
                        StringValue = "Useless"
                    }
                }
                );

            cmd.Connection.Open();
            var dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            Assert.That(dr.Read(), Is.True);
            Assert.That(dr.GetValue(1), Is.EqualTo("Canada"));
            Assert.That(dr.Read(), Is.False);
        }