Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }