flush
[mcs.git] / class / Npgsql / Test / ConnectionTests.cs
blobeff6537baf9fc4fd4624e2e3ef33ccf2f01b719b
1 // project created on 30/11/2002 at 22:00
2 //
3 // Author:
4 // Francisco Figueiredo Jr. <fxjrlists@yahoo.com>
5 //
6 // Copyright (C) 2002 The Npgsql Development Team
7 // npgsql-general@gborg.postgresql.org
8 // http://gborg.postgresql.org/project/npgsql/projdisplay.php
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 using System;
25 using Npgsql;
26 using System.Data;
28 using NUnit.Framework;
30 namespace NpgsqlTests
35 [TestFixture]
36 public class ConnectionTests
38 NpgsqlConnection _conn;
40 [SetUp]
41 protected void SetUp()
43 //NpgsqlEventLog.Level = LogLevel.None;
44 //NpgsqlEventLog.Level = LogLevel.Debug;
45 //NpgsqlEventLog.LogName = "NpgsqlTests.LogFile";
46 _conn = new NpgsqlConnection (TestConfiguration.NpgsqlConnectionString);
49 [TearDown]
50 protected void TearDown()
52 if (_conn != null)
53 _conn.Close();
57 [Test]
58 public void Open()
60 try{
61 _conn.Open();
62 //Assert.AreEqual("ConnectionOpen", ConnectionState.Open, _conn.State);
63 } catch (Exception e)
65 Console.WriteLine(e.ToString());
71 [Test]
72 public void ChangeDatabase()
74 _conn.Open();
76 _conn.ChangeDatabase("template1");
78 NpgsqlCommand command = new NpgsqlCommand("select current_database()", _conn);
80 String result = (String)command.ExecuteScalar();
82 Assert.AreEqual("template1", result);
86 [Test]
87 [ExpectedException(typeof(InvalidOperationException))]
88 public void NestedTransaction()
90 _conn.Open();
92 NpgsqlTransaction t = null;
93 try
95 t = _conn.BeginTransaction();
97 t = _conn.BeginTransaction();
99 catch(Exception e)
101 // Catch exception so we call rollback the transaction initiated.
102 // This way, the connection pool doesn't get a connection with a transaction
103 // started.
104 t.Rollback();
105 throw e;
110 [Test]
111 public void SequencialTransaction()
113 _conn.Open();
115 NpgsqlTransaction t = _conn.BeginTransaction();
117 t.Rollback();
119 t = _conn.BeginTransaction();
121 t.Rollback();