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

            var countBefore = ExecuteCount(OleDbCount);

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

            var cmd = new Queryable.Query(OleDb, ConnectionStringReader.GetOleDbSql());
            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(OleDbCount);

            Assert.That(countAfter, Is.EqualTo(countBefore));
        }
Example #2
0
        public void GetExecutor_OleDbConnectionString_OleDbEngine()
        {
            var factory  = new QueryEngineFactory();
            var cmd      = new OleDbCommand("select @@version;", new OleDbConnection(ConnectionStringReader.GetOleDbSql()));
            var executor = factory.GetExecutor(cmd);

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

            var res = qp.Parse();

            Assert.That(res.IsSuccesful, Is.True);
        }
Example #4
0
        public void Execute_WaitFor3SecondsTimeoutSetTo1_Timeout()
        {
            var query = "WAITFOR DELAY '00:00:10';";
            var cmd   = new OleDbCommand(query, new OleDbConnection(ConnectionStringReader.GetOleDbSql()));

            cmd.CommandTimeout = 1;

            var qe = new QueryOleDbEngine(cmd);

            Assert.Throws <CommandTimeoutException>(delegate { qe.Execute(); });
        }
Example #5
0
        public void CheckPerformance_OneQuery_ReturnElapsedTime()
        {
            var sql = "WAITFOR DELAY '00:00:00';";
            var cmd = new OleDbCommand(sql, new OleDbConnection(ConnectionStringReader.GetOleDbSql()));

            var qp  = new OleDbPerformanceEngine(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);
        }
Example #6
0
        public void Execute_OneQueryHavingTimeout_ReturnTimeoutInfo()
        {
            var query = "WAITFOR DELAY '00:00:03';";
            var cmd   = new OleDbCommand(query, new OleDbConnection(ConnectionStringReader.GetOleDbSql()));

            var qp  = new OleDbPerformanceEngine(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);
        }
Example #7
0
        public void Execute_WaitFor3SecondsTimeoutSetTo0_NoTimeOut()
        {
            var query = "WAITFOR DELAY '00:00:03';";
            var cmd   = new OleDbCommand(query, new OleDbConnection(ConnectionStringReader.GetOleDbSql()));

            cmd.CommandTimeout = 0;

            var qe = new QueryOleDbEngine(cmd);

            Assert.DoesNotThrow(delegate { qe.Execute(); });
        }
Example #8
0
        public void Parse_WrongSyntax_Failed()
        {
            var OleDb = "SELECTION [DepartmentID], Name, WrongField1, WrongField2 from [HumanResources].[Department];";
            var cmd   = new Queryable.Query(OleDb, ConnectionStringReader.GetOleDbSql());
            var qp    = new ValidationEngineFactory().Instantiate(cmd);

            var res = qp.Parse();

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

            var res = qp.Parse();

            Assert.That(res.IsSuccesful, Is.False);
            Assert.That(res.Errors[0], Is.EqualTo("Invalid column name 'WrongField'."));
        }
Example #10
0
        public void Parse_WrongTableName_Failed()
        {
            var OleDb = "SELECT * FROM WrongTableName;";
            var cmd   = new Queryable.Query(OleDb, ConnectionStringReader.GetOleDbSql());
            var qp    = new ValidationEngineFactory().Instantiate(cmd);

            var res = qp.Parse();

            Assert.That(res.IsSuccesful, Is.False);
            Assert.That(res.Errors[0], Is.EqualTo("Invalid object name 'WrongTableName'."));
        }
Example #11
0
        public void Instantiate_OleDb_OleDbExecutionEngine()
        {
            var query = Mock.Of <IQuery>(
                x => x.ConnectionString == ConnectionStringReader.GetOleDbSql() &&
                x.Statement == "select 1"
                );

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

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

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

            Assert.That(value, Is.EqualTo("CAD"));
        }
Example #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 OleDbCommand(query, new OleDbConnection(ConnectionStringReader.GetOleDbSql()))
            {
                CommandTimeout = 0
            };

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

            Assert.That(values, Has.Count.EqualTo(10));
            Assert.That(values, Has.Member("CAD"));
        }
Example #14
0
        public void Build_CommandTypeSetToStoredProcedure_CommandTypeSetStoredProcedure()
        {
            var conn  = new DbClient(DbProviderFactories.GetFactory("System.Data.OleDb"), typeof(OleDbConnection), ConnectionStringReader.GetOleDbSql());
            var query = Mock.Of <IQuery>(
                x => x.ConnectionString == ConnectionStringReader.GetOleDbSql() &&
                x.CommandType == System.Data.CommandType.StoredProcedure
                );

            var factory = new OleDbCommandFactory();
            var cmd     = factory.Instantiate(conn, query, null);

            Assert.IsInstanceOf <OleDbCommand>(cmd.Implementation);
            Assert.That((cmd.Implementation as OleDbCommand).CommandType, Is.EqualTo(System.Data.CommandType.StoredProcedure));
        }
Example #15
0
        public void Execute_ValidQuery_DataSetFilled()
        {
            var query = "select * from [Sales].[Currency];";
            var cmd   = new OleDbCommand(query, new OleDbConnection(ConnectionStringReader.GetOleDbSql()))
            {
                CommandTimeout = 0
            };

            var qe = new OleDbExecutionEngine(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));
        }
Example #16
0
        public void Build_TimeoutSetTo30_TimeoutSet30Seconds()
        {
            var conn  = new DbClient(DbProviderFactories.GetFactory("System.Data.OleDb"), typeof(OleDbConnection), ConnectionStringReader.GetOleDbSql());
            var query = Mock.Of <IQuery>(
                x => x.ConnectionString == ConnectionStringReader.GetOleDbSql() &&
                x.Statement == "WAITFOR DELAY '00:00:15'" &&
                x.Timeout == new TimeSpan(0, 0, 30)
                );

            var factory = new OleDbCommandFactory();
            var cmd     = factory.Instantiate(conn, query, null);

            Assert.IsInstanceOf <OleDbCommand>(cmd.Implementation);
            Assert.That((cmd.Implementation as OleDbCommand).CommandTimeout, Is.EqualTo(30));
        }
Example #17
0
        public void Get_OleDbConnection_Exception()
        {
            var mock = new Mock <IBatchRunCommand>();

            mock.SetupGet(x => x.FullPath).Returns("C:\foo.sql");
            var cmd = mock.Object;

            IDbConnection conn = new OleDbConnection();

            conn.ConnectionString = ConnectionStringReader.GetOleDbSql();
            var factory = new SmoBatchRunnerFactory();
            var ex      = Assert.Throws <ArgumentException>(() => factory.Get(cmd, conn));

            Assert.That(ex.Message, Is.StringContaining("SqlConnection"));
            Assert.That(ex.Message, Is.StringContaining("OleDbConnection"));
        }
Example #18
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();
            }
        }
Example #19
0
        private int ExecuteCount(string OleDbCount)
        {
            int count;

            using (OleDbConnection conn = new OleDbConnection(ConnectionStringReader.GetOleDbSql()))
            {
                conn.Open();

                using (OleDbCommand cmd = new OleDbCommand(OleDbCount, conn))
                {
                    count = (int)cmd.ExecuteScalar();
                }

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

            return(count);
        }