(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Npgsql / Test / DataAdapterTests.cs
blobb11f7365fb94aad2ebe5968ce2ba5aaf8a00b4ba
1 // created on 3/5/2003 at 14:29
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
25 using System;
26 using System.Data;
27 using System.Web.UI.WebControls;
28 using Npgsql;
30 using NpgsqlTypes;
32 using NUnit.Framework;
33 using NUnit.Core;
35 namespace NpgsqlTests
38 [TestFixture]
39 public class DataAdapterTests
42 private NpgsqlConnection _conn = null;
43 private String _connString = "Server=localhost;User ID=npgsql_tests;Password=npgsql_tests;Database=npgsql_tests;maxpoolsize=2;";
45 [SetUp]
46 protected void SetUp()
48 //NpgsqlEventLog.Level = LogLevel.None;
49 //NpgsqlEventLog.Level = LogLevel.Debug;
50 //NpgsqlEventLog.LogName = "NpgsqlTests.LogFile";
51 _conn = new NpgsqlConnection(_connString);
54 [TearDown]
55 protected void TearDown()
57 if (_conn.State != ConnectionState.Closed)
58 _conn.Close();
61 [Test]
62 public void InsertWithDataSet()
65 _conn.Open();
67 DataSet ds = new DataSet();
69 NpgsqlDataAdapter da = new NpgsqlDataAdapter("select * from tableb", _conn);
71 da.InsertCommand = new NpgsqlCommand("insert into tableb(field_int2, field_timestamp, field_numeric) values (:a, :b, :c)", _conn);
73 da.InsertCommand.Parameters.Add(new NpgsqlParameter("a", DbType.Int16));
75 da.InsertCommand.Parameters.Add(new NpgsqlParameter("b", DbType.DateTime));
77 da.InsertCommand.Parameters.Add(new NpgsqlParameter("c", DbType.Decimal));
79 da.InsertCommand.Parameters[0].Direction = ParameterDirection.Input;
80 da.InsertCommand.Parameters[1].Direction = ParameterDirection.Input;
81 da.InsertCommand.Parameters[2].Direction = ParameterDirection.Input;
83 da.InsertCommand.Parameters[0].SourceColumn = "field_int2";
84 da.InsertCommand.Parameters[1].SourceColumn = "field_timestamp";
85 da.InsertCommand.Parameters[2].SourceColumn = "field_numeric";
88 da.Fill(ds);
91 DataTable dt = ds.Tables[0];
93 DataRow dr = dt.NewRow();
94 dr["field_int2"] = 4;
95 dr["field_timestamp"] = new DateTime(2003, 03, 03, 14, 0, 0);
96 dr["field_numeric"] = 7.3M;
98 dt.Rows.Add(dr);
101 DataSet ds2 = ds.GetChanges();
103 da.Update(ds2);
105 ds.Merge(ds2);
106 ds.AcceptChanges();
109 NpgsqlDataReader dr2 = new NpgsqlCommand("select * from tableb where field_serial > 4", _conn).ExecuteReader();
110 dr2.Read();
113 Assert.AreEqual(4, dr2[1]);
114 Assert.AreEqual(7.3000000M, dr2[3]);
116 new NpgsqlCommand("delete from tableb where field_serial > 4", _conn).ExecuteNonQuery();
122 [Test]
123 public void FillWithEmptyResultset()
126 _conn.Open();
128 DataSet ds = new DataSet();
130 NpgsqlDataAdapter da = new NpgsqlDataAdapter("select * from tableb where field_serial = -1", _conn);
133 da.Fill(ds);
135 Assert.AreEqual(1, ds.Tables.Count);
136 Assert.AreEqual(4, ds.Tables[0].Columns.Count);
137 Assert.AreEqual("field_serial", ds.Tables[0].Columns[0].ColumnName);
138 Assert.AreEqual("field_int2", ds.Tables[0].Columns[1].ColumnName);
139 Assert.AreEqual("field_timestamp", ds.Tables[0].Columns[2].ColumnName);
140 Assert.AreEqual("field_numeric", ds.Tables[0].Columns[3].ColumnName);
144 [Test]
145 public void FillWithDuplicateColumnName()
147 _conn.Open();
148 DataSet ds = new DataSet();
150 NpgsqlDataAdapter da = new NpgsqlDataAdapter("select field_serial, field_serial from tableb", _conn);
152 da.Fill(ds);