예제 #1
0
        public void TestLeaveConnectionOpenWithSqlTask()
        {
            //Arrange
            SqlConnectionManager con = new SqlConnectionManager(ConnectionStringParameter)
            {
                LeaveOpen = true
            };

            //Act
            AssertOpenConnectionCount(0, ConnectionStringParameter);
            Assert.True(con.State == null);
            SqlTask.ExecuteNonQuery(con, "Dummy", "SELECT 1");
            Assert.True(con.State == System.Data.ConnectionState.Open);
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            SqlTask.ExecuteNonQuery(con, "Dummy", "SELECT 1");
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            Assert.True(con.State == System.Data.ConnectionState.Open);
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            SqlConnection.ClearAllPools();

            //Assert
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            con.Close();
            SqlConnection.ClearAllPools();
            AssertOpenConnectionCount(0, ConnectionStringParameter);
        }
예제 #2
0
        public void TestLeaveConnectionOpen()
        {
            //Arrange
            SqlConnectionManager con = new SqlConnectionManager(ConnectionStringParameter)
            {
                LeaveOpen = true
            };

            //Act
            AssertOpenConnectionCount(0, ConnectionStringParameter);
            Assert.True(con.State == null);
            con.Open();
            Assert.True(con.State == System.Data.ConnectionState.Open);
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            con.Open();
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            Assert.True(con.State == System.Data.ConnectionState.Open);
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            SqlConnection.ClearAllPools();

            //Assert
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            con.Close();
            SqlConnection.ClearAllPools();
            AssertOpenConnectionCount(0, ConnectionStringParameter);
        }
예제 #3
0
        public void TestLeaveConnectionOpenInParallel()
        {
            //Arrange
            SqlConnectionManager con = new SqlConnectionManager(ConnectionStringParameter)
            {
                LeaveOpen        = true,
                MaxLoginAttempts = 1
            };

            //Act
            Assert.Throws <InvalidOperationException>(() =>
            {
                try
                {
                    Parallel.Invoke(
                        () => SqlTask.ExecuteNonQuery(con, "Dummy", "WAITFOR DELAY '0:00:01.000'")
                        , () => SqlTask.ExecuteNonQuery(con, "Dummy", "WAITFOR DELAY '0:00:01.000'")
                        );;
                }
                catch (AggregateException e)
                {
                    throw e.InnerException;
                }
            });

            con.Close();
            SqlConnection.ClearAllPools();
        }
예제 #4
0
        public void TestLeaveConnectionOpenInParallel()
        {
            //Arrange
            SqlConnectionManager con = new SqlConnectionManager(ConnectionStringParameter)
            {
                LeaveOpen        = true,
                MaxLoginAttempts = 1
            };

            //Act
            Assert.Throws <InvalidOperationException>(() =>
            {
                try
                {
                    Task t1 = Task.Factory.StartNew(() => SqlTask.ExecuteNonQuery(con, "Dummy", "WAITFOR DELAY '0:00:01.000'"));
                    Task t2 = Task.Factory.StartNew(() => SqlTask.ExecuteNonQuery(con, "Dummy", "WAITFOR DELAY '0:00:01.000'"));
                    t1.Start();
                    t2.Start();
                    Task.WaitAll(t1, t2);
                    //Parallel.Invoke(new ParallelOptions() { TaskScheduler = TaskScheduler.Default },
                    //           () => SqlTask.ExecuteNonQuery(con, "Dummy", "WAITFOR DELAY '0:00:01.000'"),
                    //           () => SqlTask.ExecuteNonQuery(con, "Dummy", "WAITFOR DELAY '0:00:01.000'")
                    //        ); ;
                }
                catch (AggregateException e)
                {
                    throw e.InnerException;
                }
            });

            con.Close();
            SqlConnection.ClearAllPools();
        }
예제 #5
0
        public void TestOpeningConnectionTwice()
        {
            SqlConnectionManager con = new SqlConnectionManager(new ConnectionString(ConnectionStringParameter));

            AssertOpenConnectionCount(0, ConnectionStringParameter);
            con.Open();
            con.Open();
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            con.Close();
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            SqlConnection.ClearAllPools();
            AssertOpenConnectionCount(0, ConnectionStringParameter);
        }
예제 #6
0
        public void TestOpeningCloseConnection()
        {
            //Arrange
            SqlConnectionManager con = new SqlConnectionManager(new ConnectionString(ConnectionStringParameter));

            //Act
            AssertOpenConnectionCount(0, ConnectionStringParameter);
            con.Open();
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            con.Close(); //won't close any connection - ado.net will keep the connection open in it's pool in case it's needed again
            AssertOpenConnectionCount(1, ConnectionStringParameter);
            SqlConnection.ClearAllPools();

            //Assert
            AssertOpenConnectionCount(0, ConnectionStringParameter);
        }
예제 #7
0
        public void TestOpeningCloseConnection()
        {
            /*User calls Open()
             * This first call creates a SqlConnection() object
             * It then checks to ensure that it's not open and attempts to open a connection
             * User calls Open() again
             * This second call creates a new SqlConnection() object
             * It then checks to ensure that it's not open, which it is not because its a new one...
             */
            SqlConnectionManager con = new SqlConnectionManager(new ConnectionString(ConnectionStringParameter));

            ConnectionManagerHelper.AssertOpenConnectionCount(0, ConnectionStringParameter);
            con.Open();
            ConnectionManagerHelper.AssertOpenConnectionCount(1, ConnectionStringParameter);
            con.Close(); //won't close any connection - ado.net will keep the connection open in it's pool in case it's needed again
            ConnectionManagerHelper.AssertOpenConnectionCount(1, ConnectionStringParameter);
            SqlConnection.ClearAllPools();
            ConnectionManagerHelper.AssertOpenConnectionCount(0, ConnectionStringParameter);
        }