Beispiel #1
0
        public void CleanupConnectionsTest()
        {
            using (var pool = DbManagerTestSettings.CreateConnectionPool())
            {
                var manager = new DbManager(pool);
                var stack   = new Stack <IPoolableDbConnection>();

                Assert.AreEqual(0, manager.ConnectionPool.LiveObjects);
                for (var i = 1; i < 20; i++)
                {
                    var item = manager.GetConnection();
                    stack.Push(item);
                    Assert.AreEqual(i, manager.ConnectionPool.LiveObjects, string.Format("Iteration {0}", i));
                }

                while (stack.Count > 0)
                {
                    var item  = stack.Pop();
                    var start = manager.ConnectionPool.LiveObjects;
                    item.Dispose();
                    Assert.AreEqual(start - 1, manager.ConnectionPool.LiveObjects);
                }

                Assert.AreEqual(0, manager.ConnectionPool.LiveObjects);
            }
        }
Beispiel #2
0
 public void MultiplePoolItemsTest()
 {
     using (var pool = DbManagerTestSettings.CreateConnectionPool())
     {
         Assert.AreEqual(0, pool.LiveObjects);
         using (var a = pool.Acquire())
         {
             Assert.AreEqual(1, pool.LiveObjects);
             using (var b = pool.Acquire())
             {
                 Assert.AreEqual(2, pool.LiveObjects);
                 using (var c = pool.Acquire())
                 {
                     Assert.AreEqual(3, pool.LiveObjects);
                     Assert.IsNotNull(a);
                     Assert.IsNotNull(b);
                     Assert.IsNotNull(c);
                 }
                 Assert.AreEqual(2, pool.LiveObjects);
             }
             Assert.AreEqual(1, pool.LiveObjects);
         }
         Assert.AreEqual(0, pool.LiveObjects);
     }
 }
Beispiel #3
0
 public void ConnectionOpenTest()
 {
     using (var pool = DbManagerTestSettings.CreateConnectionPool())
     {
         using (var connPool = pool.Acquire())
         {
             var conn = connPool.Connection;
             Assert.IsNotNull(conn);
             Assert.AreEqual(ConnectionState.Open, conn.State);
         }
     }
 }
Beispiel #4
0
 public void ExecuteNonQueryTest()
 {
     using (var pool = DbManagerTestSettings.CreateConnectionPool())
     {
         var manager = new DbManager(pool);
         for (var i = 0; i < 10; i++)
         {
             var ret = manager.ExecuteNonQuery("SELECT 500 + 100");
             Assert.AreEqual(-1, ret);
         }
     }
 }
Beispiel #5
0
 public void ConnectionCloseTest()
 {
     using (var pool = DbManagerTestSettings.CreateConnectionPool())
     {
         IDbConnection conn;
         using (var connPool = pool.Acquire())
         {
             conn = connPool.Connection;
             connPool.QueryRunner.Flush();
         }
         Assert.AreEqual(ConnectionState.Closed, conn.State);
     }
 }
Beispiel #6
0
        public void SelectTest()
        {
            using (var pool = DbManagerTestSettings.CreateConnectionPool())
            {
                using (var nonReader = new MyNonReader(pool))
                {
                    for (var i = 0; i < 10; i++)
                    {
                        nonReader.Execute(new QueryTestValues(5, 10, 15));
                    }

                    nonReader.ConnectionPool.QueryRunner.Flush();
                }
            }
        }
Beispiel #7
0
 public void ExecuteReaderTest()
 {
     using (var pool = DbManagerTestSettings.CreateConnectionPool())
     {
         var manager = new DbManager(pool);
         for (var i = 0; i < 10; i++)
         {
             using (var r = manager.ExecuteReader("SELECT 500 + 100"))
             {
                 Assert.IsFalse(r.IsClosed);
                 r.Read();
                 Assert.AreEqual("600", r[0].ToString());
             }
         }
     }
 }
Beispiel #8
0
 public void SelectQueryTest()
 {
     using (var pool = DbManagerTestSettings.CreateConnectionPool())
     {
         using (var connPool = pool.Acquire())
         {
             using (var cmd = connPool.Connection.CreateCommand())
             {
                 cmd.CommandText = "SELECT 100 + 500";
                 using (var r = cmd.ExecuteReader())
                 {
                     r.Read();
                     Assert.AreEqual(600, r[0]);
                 }
             }
         }
     }
 }
Beispiel #9
0
 public void ConnectionTest()
 {
     using (var pool = DbManagerTestSettings.CreateConnectionPool())
     {
         var manager = new DbManager(pool);
         for (var i = 0; i < 10; i++)
         {
             Assert.AreEqual(0, manager.ConnectionPool.LiveObjects, string.Format("Iteration {0}", i));
             IPoolableDbConnection pConn;
             IDbConnection         conn;
             using (pConn = manager.GetConnection())
             {
                 Assert.AreEqual(1, manager.ConnectionPool.LiveObjects, string.Format("Iteration {0}", i));
                 conn = pConn.Connection;
                 Assert.IsNotNull(conn);
                 Assert.AreEqual(ConnectionState.Open, conn.State);
             }
             Assert.AreEqual(ConnectionState.Closed, conn.State);
         }
     }
 }
Beispiel #10
0
        public void CommandParametersTest()
        {
            using (var pool = DbManagerTestSettings.CreateConnectionPool())
            {
                var manager = new DbManager(pool);
                for (var i = 0; i < 10; i++)
                {
                    Assert.AreEqual(0, manager.ConnectionPool.LiveObjects, string.Format("Iteration {0}", i));

                    IDbCommand cmd;
                    using (cmd = manager.GetCommand())
                    {
                        Assert.AreEqual(1, manager.ConnectionPool.LiveObjects, string.Format("Iteration {0}", i));
                        Assert.IsNotNull(cmd);

                        cmd.CommandText = "SELECT @left + @right";

                        var left = new MySqlParameter("@left", null)
                        {
                            Value = 500
                        };
                        var right = new MySqlParameter("@right", null)
                        {
                            Value = 100
                        };
                        cmd.Parameters.Add(left);
                        cmd.Parameters.Add(right);

                        using (var r = cmd.ExecuteReader())
                        {
                            r.Read();
                            Assert.AreEqual("600", r[0].ToString());
                        }

                        Assert.AreNotEqual(0, cmd.Parameters.Count);
                        Assert.IsFalse(string.IsNullOrEmpty(cmd.CommandText));
                    }
                }
            }
        }
Beispiel #11
0
 public void CommandStringTest()
 {
     using (var pool = DbManagerTestSettings.CreateConnectionPool())
     {
         var manager = new DbManager(pool);
         for (var i = 0; i < 10; i++)
         {
             Assert.AreEqual(0, manager.ConnectionPool.LiveObjects, string.Format("Iteration {0}", i));
             using (var cmd = manager.GetCommand("SELECT 500 + 100"))
             {
                 Assert.AreEqual(1, manager.ConnectionPool.LiveObjects, string.Format("Iteration {0}", i));
                 Assert.IsNotNull(cmd);
                 Assert.AreEqual("SELECT 500 + 100", cmd.CommandText);
                 using (var r = cmd.ExecuteReader())
                 {
                     r.Read();
                     Assert.AreEqual("600", r[0].ToString());
                 }
             }
         }
     }
 }