예제 #1
0
        public void PqsqlConnectionTest4()
        {
            PqsqlConnection connection = new PqsqlConnection(connectionString);

            connection.Open();
            Assert.AreEqual(ConnectionState.Open, connection.State, "wrong connection state");

            IntPtr conn_attempt1 = connection.PGConnection;

            int sock1 = PqsqlWrapper.PQsocket(conn_attempt1);

            Assert.AreNotEqual(-1, sock1, "wrong socket");

            // close the underlying socket without letting Pqsql and libpq know
            int closed = CloseSocket(sock1);

            Assert.AreEqual(0, closed, "closesocket failed");

            connection.Close();
            Assert.AreEqual(ConnectionState.Closed, connection.State, "wrong connection state");

            connection.Open();
            IntPtr conn_attempt2 = connection.PGConnection;

            ConnStatusType status = PqsqlWrapper.PQstatus(conn_attempt2);

            Assert.AreEqual(ConnStatusType.CONNECTION_OK, status, "connection broken");
            Assert.AreEqual(ConnectionState.Open, connection.State, "wrong connection state");

            int sock2 = PqsqlWrapper.PQsocket(conn_attempt2);

            // close the underlying socket without letting Pqsql and libpq know
            closed = CloseSocket(sock2);
            Assert.AreEqual(0, closed, "closesocket failed");
        }