2003-06-01 Francisco Figueiredo Jr. <fxjrlists@yahoo.com.br>
[mono.git] / mcs / class / Npgsql / Test / ConnectionTests.cs
1 // project created on 30/11/2002 at 22:00
2 using System;
3 using Npgsql;
4 using System.Data;
5
6 using NUnit.Framework;
7
8 namespace NpgsqlTests
9 {
10         
11         
12                 
13         [TestFixture]
14         public class ConnectionTests
15         {
16                 private NpgsqlConnection        _conn = null;
17                 private String                                          _connString = "Server=localhost;User ID=npgsql_tests;Password=npgsql_tests;Database=npgsql_tests";
18                 
19                 [SetUp]
20                 protected void SetUp()
21                 {
22                         NpgsqlEventLog.Level = LogLevel.None;
23                         //NpgsqlEventLog.LogName = "NpgsqlTests.LogFile";
24                         _conn = new NpgsqlConnection(_connString);
25                 }
26                 
27                 [TearDown]
28                 protected void TearDown()
29                 {
30                         _conn.Close();
31                 }
32                 
33                 
34                 [Test]
35                 public void Open()
36                 {
37                         try{
38                                 _conn.Open();
39                                 //Assertion.AssertEquals("ConnectionOpen", ConnectionState.Open, _conn.State);
40                         } catch (Exception e)
41                         {
42                                 Console.WriteLine(e.ToString());
43                         }
44                         
45                         
46                 }
47                 
48                 [Test]
49                 public void ChangeDatabase()
50                 {
51                         _conn.Open();
52                         
53                         _conn.ChangeDatabase("template1");
54                         
55                         NpgsqlCommand command = new NpgsqlCommand("select current_database()", _conn);
56                         
57                         String result = (String)command.ExecuteScalar();
58                         
59                         Assertion.AssertEquals("template1", result);
60                                 
61                 }
62                 
63                 [Test]
64                 [ExpectedException(typeof(InvalidOperationException))]
65                 public void NestedTransaction()
66                 {
67                         _conn.Open();
68                         
69                         NpgsqlTransaction t = _conn.BeginTransaction();
70                         
71                         t = _conn.BeginTransaction();
72                         
73                 }
74                 
75                 [Test]
76                 public void SequencialTransaction()
77                 {
78                         _conn.Open();
79                         
80                         NpgsqlTransaction t = _conn.BeginTransaction();
81                         
82                         t.Rollback();
83                         
84                         t = _conn.BeginTransaction();
85                         
86                         t.Rollback();
87                         
88                         
89                 }
90                 
91         }
92 }