Exemple #1
0
        public void Parse_DontExecuteEffectivelyQuery()
        {
            var OdbcCount = @"SELECT COUNT(*) from [HumanResources].[Department]";
            var Odbc      = @"DELETE from [HumanResources].[Department]";

            var countBefore = ExecuteCount(OdbcCount);

            if (countBefore == 0) //If nothing was present we cannot assert
            {
                Assert.Inconclusive();
            }

            var cmd = new Queryable.Query(Odbc, ConnectionStringReader.GetOdbcSql());
            var qp  = new ValidationEngineFactory().Instantiate(cmd);

            var res = qp.Parse();

            if (!res.IsSuccesful)//If syntax is incorrect we cannot assert
            {
                Assert.Inconclusive();
            }

            var countAfter = ExecuteCount(OdbcCount);

            Assert.That(countAfter, Is.EqualTo(countBefore));
        }
Exemple #2
0
        public void GetExecutor_OdbcConnectionString_OdbcEngine()
        {
            var factory  = new QueryEngineFactory();
            var cmd      = new OdbcCommand("select @@version;", new OdbcConnection(ConnectionStringReader.GetOdbcSql()));
            var executor = factory.GetExecutor(cmd);

            Assert.IsInstanceOf <QueryOdbcEngine>(executor);
        }
Exemple #3
0
        public void Parse_CorrectFields_Success()
        {
            var Odbc = "select [DepartmentID], Name from [HumanResources].[Department];";
            var cmd  = new Queryable.Query(Odbc, ConnectionStringReader.GetOdbcSql());
            var qp   = new ValidationEngineFactory().Instantiate(cmd);

            var res = qp.Parse();

            Assert.That(res.IsSuccesful, Is.True);
        }
Exemple #4
0
        public void Execute_OneQueryHavingTimeout_ReturnTimeoutInfo()
        {
            var query = "WAITFOR DELAY '00:00:03';";
            var cmd   = new OdbcCommand(query, new OdbcConnection(ConnectionStringReader.GetOdbcSql()));

            var qp  = new OdbcPerformanceEngine(cmd.Connection, cmd);
            var res = qp.Execute(new TimeSpan(0, 0, 1));

            Assert.That(res.TimeOut.TotalMilliseconds, Is.EqualTo(1000));
            Assert.That(res.IsTimeOut, Is.True);
        }
Exemple #5
0
        public void CheckPerformance_OneQuery_ReturnElapsedTime()
        {
            var sql = "WAITFOR DELAY '00:00:00';";
            var cmd = new OdbcCommand(sql, new OdbcConnection(ConnectionStringReader.GetOdbcSql()));

            var qp  = new OdbcPerformanceEngine(cmd.Connection, cmd);
            var res = qp.Execute(new TimeSpan(0, 1, 0));

            Assert.That(res.TimeElapsed.TotalMilliseconds, Is.GreaterThanOrEqualTo(0).And.LessThan(5000));
            Assert.That(res.IsTimeOut, Is.False);
        }
        public void Execute_WaitFor3SecondsTimeoutSetTo0_NoTimeOut()
        {
            var query = "WAITFOR DELAY '00:00:03';";
            var cmd   = new OdbcCommand(query, new OdbcConnection(ConnectionStringReader.GetOdbcSql()));

            cmd.CommandTimeout = 0;

            var qe = new QueryOdbcEngine(cmd);

            Assert.DoesNotThrow(delegate { qe.Execute(); });
        }
        public void Execute_WaitFor3SecondsTimeoutSetTo1_Timeout()
        {
            var query = "WAITFOR DELAY '00:00:10';";
            var cmd   = new OdbcCommand(query, new OdbcConnection(ConnectionStringReader.GetOdbcSql()));

            cmd.CommandTimeout = 1;

            var qe = new QueryOdbcEngine(cmd);

            Assert.Throws <CommandTimeoutException>(delegate { qe.Execute(); });
        }
Exemple #8
0
        public void Parse_WrongSyntax_Failed()
        {
            var Odbc = "SELECTION [DepartmentID], Name, WrongField1, WrongField2 from [HumanResources].[Department];";
            var cmd  = new Queryable.Query(Odbc, ConnectionStringReader.GetOdbcSql());
            var qp   = new ValidationEngineFactory().Instantiate(cmd);

            var res = qp.Parse();

            Assert.That(res.IsSuccesful, Is.False);
            Assert.That(res.Errors, Has.Member("Incorrect syntax near 'SELECTION'."));
        }
Exemple #9
0
        public void Parse_WrongField_Failed()
        {
            var Odbc = "select [DepartmentID], Name, WrongField from [HumanResources].[Department];";
            var cmd  = new Queryable.Query(Odbc, ConnectionStringReader.GetOdbcSql());
            var qp   = new ValidationEngineFactory().Instantiate(cmd);

            var res = qp.Parse();

            Assert.That(res.IsSuccesful, Is.False);
            Assert.That(res.Errors, Has.Member("Invalid column name 'WrongField'."));
        }
Exemple #10
0
        public void Parse_WrongTableName_Failed()
        {
            var Odbc = "SELECT * FROM WrongTableName;";
            var cmd  = new Queryable.Query(Odbc, ConnectionStringReader.GetOdbcSql());
            var qp   = new ValidationEngineFactory().Instantiate(cmd);

            var res = qp.Parse();

            Assert.That(res.IsSuccesful, Is.False);
            Assert.That(res.Errors, Has.Member("Invalid object name 'WrongTableName'."));
        }
Exemple #11
0
        public void Instantiate_Odbc_OdbcExecutionEngine()
        {
            var query = Mock.Of <IQuery>(
                x => x.ConnectionString == ConnectionStringReader.GetOdbcSql() &&
                x.Statement == "select 1"
                );

            var factory = serviceLocator.GetExecutionEngineFactory();
            var engine  = factory.Instantiate(query);

            Assert.IsInstanceOf <OdbcExecutionEngine>(engine);
        }
Exemple #12
0
        public void ExecuteScalar_ValidQuery_DataSetFilled()
        {
            var query = "select top(1) CurrencyCode from [Sales].[Currency] where Name like '%Canad%'";
            var cmd   = new OdbcCommand(query, new OdbcConnection(ConnectionStringReader.GetOdbcSql()))
            {
                CommandTimeout = 0
            };

            var qe    = new OdbcExecutionEngine(cmd.Connection, cmd);
            var value = qe.ExecuteScalar();

            Assert.That(value, Is.EqualTo("CAD"));
        }
Exemple #13
0
        public void ExecuteList_ValidQuery_DataSetFilled()
        {
            var query = "select top(10) CurrencyCode from [Sales].[Currency] where CurrencyCode like '%D' order by 1 asc";
            var cmd   = new OdbcCommand(query, new OdbcConnection(ConnectionStringReader.GetOdbcSql()))
            {
                CommandTimeout = 0
            };

            var qe     = new OdbcExecutionEngine(cmd.Connection, cmd);
            var values = qe.ExecuteList <string>();

            Assert.That(values, Has.Count.EqualTo(10));
            Assert.That(values, Has.Member("CAD"));
        }
Exemple #14
0
        public void Execute_ValidQuery_DataSetFilled()
        {
            var query = "select * from [Sales].[Currency];";
            var cmd   = new OdbcCommand(query, new OdbcConnection(ConnectionStringReader.GetOdbcSql()))
            {
                CommandTimeout = 0
            };

            var qe = new OdbcExecutionEngine(cmd.Connection, cmd);
            var ds = qe.Execute();

            Assert.That(ds.Tables, Has.Count.EqualTo(1));
            Assert.That(ds.Tables[0].Columns, Has.Count.EqualTo(3));
            Assert.That(ds.Tables[0].Rows, Has.Count.EqualTo(105));
        }
Exemple #15
0
        private IDbCommand BuildCommand(string sql, EngineType engineType)
        {
            switch (engineType)
            {
            case EngineType.SqlNative:
                return(new SqlCommand(sql, new SqlConnection(ConnectionStringReader.GetSqlClient())));

            case EngineType.OleDb:
                return(new OleDbCommand(sql, new OleDbConnection(ConnectionStringReader.GetOleDbSql())));

            case EngineType.Odbc:
                return(new OdbcCommand(sql, new OdbcConnection(ConnectionStringReader.GetOdbcSql())));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #16
0
        private int ExecuteCount(string OdbcCount)
        {
            int count;

            using (OdbcConnection conn = new OdbcConnection(ConnectionStringReader.GetOdbcSql()))
            {
                conn.Open();

                using (OdbcCommand cmd = new OdbcCommand(OdbcCount, conn))
                {
                    count = (int)cmd.ExecuteScalar();
                }

                if (conn.State != System.Data.ConnectionState.Closed)
                {
                    conn.Close();
                }
            }

            return(count);
        }