Thread: [pgsqlclient-checkins] pgsqlclient_10/source/UnitTests AssemblyInfo.cs,NONE,1.1 PgArrayTest.cs,NONE,
Status: Inactive
Brought to you by:
carlosga_fb
From: Carlos G. Á. <car...@us...> - 2005-09-08 18:45:20
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/source/UnitTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8269 Added Files: AssemblyInfo.cs PgArrayTest.cs PgBaseTest.cs PgCommandBuilderTest.cs PgCommandTest.cs PgConnectionTest.cs PgDataAdapterTest.cs PgDatabaseSchemaTest.cs PgDataReaderTest.cs PgGeometicTypesTest.cs PgTransactionTest.cs PostgreSql.Data.PgSqlClient.UnitTests.dll.config Log Message: Started the reorganization of the CVS module --- NEW FILE: PgGeometicTypesTest.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2004 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using NUnit.Framework; using PostgreSql.Data.PgSqlClient; using PostgreSql.Data.PgTypes; namespace PostgreSql.Data.PgSqlClient.UnitTests { [TestFixture] public class PgGeometricTypesTest : PgBaseTest { [Test] public void PointTest() { PgCommand command = new PgCommand("select point_field from public.geometric_table where pk = @pk", Connection); try { command.Parameters.Add("@pk", PgDbType.Int4).Value = 50; PgPoint point = (PgPoint)command.ExecuteScalar(); Console.WriteLine("Point value: {0}", point.ToString()); Assertion.AssertEquals("Invalid X coord in point", 50, point.X); Assertion.AssertEquals("Invalid Y coord in point", 60, point.Y); } catch (Exception) { throw; } finally { command.Dispose(); } } [Test] public void BoxTest() { PgCommand command = new PgCommand("select box_field from public.geometric_table where pk = @pk", Connection); try { command.Parameters.Add("@pk", PgDbType.Int4).Value = 70; PgBox box = (PgBox)command.ExecuteScalar(); Console.WriteLine("Box value: {0}", box.ToString()); Assertion.AssertEquals("Invalid X coord in Lower Left corner", 0, box.LowerLeft.X); Assertion.AssertEquals("Invalid Y coord in Lower Left corner", 70, box.LowerLeft.Y); Assertion.AssertEquals("Invalid X coord in Upper Right corner", 70, box.UpperRight.X); Assertion.AssertEquals("Invalid Y coord in Upper Right corner", 70, box.UpperRight.Y); } catch (Exception) { throw; } finally { command.Dispose(); } } [Test] public void CircleTest() { PgCommand command = new PgCommand("select circle_field from public.geometric_table where pk = @pk", Connection); try { command.Parameters.Add("@pk", PgDbType.Int4).Value = 30; PgCircle circle = (PgCircle)command.ExecuteScalar(); Console.WriteLine("Circle value: {0}", circle.ToString()); Assertion.AssertEquals("Invalid X coord in circle", 30, circle.Center.X); Assertion.AssertEquals("Invalid Y coord in circle", 0, circle.Center.Y); Assertion.AssertEquals("Invalid RADIUS coord in circle", 30, circle.Radius); } catch (Exception) { throw; } finally { command.Dispose(); } } [Test] public void LineSegmentTest() { PgCommand command = new PgCommand("select lseg_field from public.geometric_table where pk = @pk", Connection); try { command.Parameters.Add("@pk", PgDbType.Int4).Value = 20; PgLSeg lseg = (PgLSeg)command.ExecuteScalar(); Console.WriteLine("LSeg value: {0}", lseg.ToString()); Assertion.AssertEquals("Invalid X coord in start point", -1, lseg.StartPoint.X); Assertion.AssertEquals("Invalid Y coord in start point", 0, lseg.StartPoint.Y); Assertion.AssertEquals("Invalid X coord in end point", 1, lseg.EndPoint.X); Assertion.AssertEquals("Invalid Y coord in end point", 0, lseg.EndPoint.Y); } catch (Exception) { throw; } finally { command.Dispose(); } } [Test] public void PathTest() { PgCommand command = new PgCommand("select path_field from public.geometric_table where pk = @pk", Connection); try { command.Parameters.Add("@pk", PgDbType.Int4).Value = 10; PgPath path = (PgPath)command.ExecuteScalar(); Console.WriteLine("Path value: {0}", path.ToString()); Assertion.AssertEquals("Invalid X coord in path point 0", 0, path.Points[0].X); Assertion.AssertEquals("Invalid Y coord in path point 0", 0, path.Points[0].Y); Assertion.AssertEquals("Invalid X coord in path point 1", 1, path.Points[1].X); Assertion.AssertEquals("Invalid Y coord in path point 1", 0, path.Points[1].Y); } catch (Exception) { throw; } finally { command.Dispose(); } } [Test] public void PolygonTest() { PgCommand command = new PgCommand("select polygon_field from public.geometric_table where pk = @pk", Connection); try { command.Parameters.Add("@pk", PgDbType.Int4).Value = 10; PgPolygon polygon = (PgPolygon)command.ExecuteScalar(); Console.WriteLine("Polygon value: {0}", polygon.ToString()); Assertion.AssertEquals("Invalid X coord in polygon point 0", 1, polygon.Points[0].X); Assertion.AssertEquals("Invalid Y coord in polygon point 0", 1, polygon.Points[0].Y); Assertion.AssertEquals("Invalid X coord in polygon point 1", 0, polygon.Points[1].X); Assertion.AssertEquals("Invalid Y coord in polygon point 1", 0, polygon.Points[1].Y); } catch (Exception) { throw; } finally { command.Dispose(); } } [Ignore("Test not implemented.")] public void BoxArrayTest() { } [Ignore("Test not implemented.")] public void PointArrayTest() { } [Ignore("Test not implemented.")] public void LineSegmentArrayTest() { } [Ignore("Test not implemented.")] public void PathArrayTest() { } [Ignore("Test not implemented.")] public void PolygonArrayTest() { } [Ignore("Test not implemented.")] public void CircleArrayTest() { } } } --- NEW FILE: PgDataAdapterTest.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2004 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using PostgreSql.Data.PgSqlClient; using NUnit.Framework; namespace PostgreSql.Data.PgSqlClient.UnitTests { [TestFixture] public class PgDataAdapterTest : PgBaseTest { [Test] public void FillTest() { PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE date_field = @date_field", Connection); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@date_field", PgDbType.Date, 4, "date_field").Value = DateTime.Now; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); Console.WriteLine(); Console.WriteLine("DataAdapter - Fill Method - Test"); foreach (DataTable table in ds.Tables) { foreach (DataColumn col in table.Columns) { Console.Write(col.ColumnName + "\t\t"); } Console.WriteLine(); foreach (DataRow row in table.Rows) { for (int i = 0; i < table.Columns.Count; i++) { Console.Write(row[i] + "\t\t"); } Console.WriteLine(""); } } adapter.Dispose(); builder.Dispose(); command.Dispose(); } [Test] public void FillMultipleTest() { PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE date_field = @date_field", Connection); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@date_field", PgDbType.Date, 4, "date_field").Value = DateTime.Now; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds1 = new DataSet(); DataSet ds2 = new DataSet(); adapter.Fill(ds1, "public.test_table"); adapter.Fill(ds2, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); } [Test] public void InsertTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); DataRow newRow = ds.Tables["public.test_table"].NewRow(); newRow["int4_field"] = 100; newRow["char_field"] = "PostgreSQL"; newRow["varchar_field"] = "PostgreSQL CLient"; newRow["int8_field"] = 100000; newRow["int2_field"] = 100; newRow["double_field"] = 100.01; newRow["date_field"] = DateTime.Now; newRow["time_Field"] = DateTime.Now; newRow["timestamp_field"] = DateTime.Now; ds.Tables["public.test_table"].Rows.Add(newRow); adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); } [Test] public void UpdateCharTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 1; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); ds.Tables["public.test_table"].Rows[0]["char_field"] = "PostgreSQL"; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); } [Test] public void UpdateVarCharTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 10; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); ds.Tables["public.test_table"].Rows[0]["varchar_field"] = "PostgreSQL Client"; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); } [Test] public void UpdateInt2Test() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 40; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); ds.Tables["public.test_table"].Rows[0]["int2_field"] = System.Int16.MaxValue; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); command = new PgCommand("SELECT int2_field FROM public.test_table WHERE int4_field = @int4_field", Connection); command.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 40; short val = (short)command.ExecuteScalar(); Assertion.AssertEquals("int2_field has not correct value", System.Int16.MaxValue, val); } [Test] public void UpdateInt8Test() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 20; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); ds.Tables["public.test_table"].Rows[0]["int8_field"] = System.Int32.MaxValue; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); command = new PgCommand("SELECT int8_field FROM public.test_table WHERE int4_field = @int4_field", Connection); command.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 20; long val = (long)command.ExecuteScalar(); Assertion.AssertEquals("int8_field has not correct value", System.Int32.MaxValue, val); } [Test] public void UpdateDoubleTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 50; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); ds.Tables["public.test_table"].Rows[0]["double_field"] = System.Int32.MaxValue; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); command = new PgCommand("SELECT double_field FROM public.test_table WHERE int4_field = @int4_field", Connection); command.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 50; double val = (double)command.ExecuteScalar(); Assertion.AssertEquals("double_field has not correct value", System.Int32.MaxValue, val); } [Test] public void UpdateMoneyField() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 27; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); ds.Tables["public.test_table"].Rows[0]["money_field"] = 200.20; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); command = new PgCommand("SELECT money_field FROM public.test_table WHERE int4_field = @int4_field", Connection); command.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 27; float val = (float)command.ExecuteScalar(); Assertion.AssertEquals("money_field has not correct value", 200.20, val); } [Test] public void UpdateNumericTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 60; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); ds.Tables["public.test_table"].Rows[0]["numeric_field"] = System.Int16.MaxValue; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); command = new PgCommand("SELECT numeric_field FROM public.test_table WHERE int4_field = @int4_field", Connection); command.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 60; decimal val = (decimal)command.ExecuteScalar(); if (val != (decimal)System.Int16.MaxValue) { Assertion.Fail("numeric_field has not correct value"); } } [Test] public void UpdateDateTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 70; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); DateTime dt = DateTime.Now; ds.Tables["public.test_table"].Rows[0]["date_field"] = dt; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); command = new PgCommand("SELECT date_field FROM public.test_table WHERE int4_field = @int4_field", Connection); command.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 70; DateTime val = (DateTime)command.ExecuteScalar(); Assertion.AssertEquals("date_field has not correct day", dt.Day, val.Day); Assertion.AssertEquals("date_field has not correct month", dt.Month, val.Month); Assertion.AssertEquals("date_field has not correct year", dt.Year, val.Year); } [Test] public void UpdateTimeTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 80; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); DateTime dt = DateTime.Now; ds.Tables["public.test_table"].Rows[0]["time_field"] = dt; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); command = new PgCommand("SELECT time_field FROM public.test_table WHERE int4_field = @int4_field", Connection); command.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 80; DateTime val = (DateTime)command.ExecuteScalar(); Assertion.AssertEquals("time_field has not correct hour", dt.Hour, val.Hour); Assertion.AssertEquals("time_field has not correct minute", dt.Minute, val.Minute); Assertion.AssertEquals("time_field has not correct second", dt.Second, val.Second); } [Test] public void UpdateTimeStampTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 90; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); DateTime dt = DateTime.Now; ds.Tables["public.test_table"].Rows[0]["timestamp_field"] = dt; adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); command = new PgCommand("SELECT timestamp_field FROM public.test_table WHERE int4_field = @int4_field", Connection); command.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 90; DateTime val = (DateTime)command.ExecuteScalar(); Assertion.AssertEquals("timestamp_field has not correct day", dt.Day, val.Day); Assertion.AssertEquals("timestamp_field has not correct month", dt.Month, val.Month); Assertion.AssertEquals("timestamp_field has not correct year", dt.Year, val.Year); Assertion.AssertEquals("timestamp_field has not correct hour", dt.Hour, val.Hour); Assertion.AssertEquals("timestamp_field has not correct minute", dt.Minute, val.Minute); Assertion.AssertEquals("timestamp_field has not correct second", dt.Second, val.Second); } [Test] public void DeleteTest() { PgTransaction transaction = Connection.BeginTransaction(); PgCommand command = new PgCommand("SELECT * FROM public.test_table WHERE int4_field = @int4_field", Connection, transaction); PgDataAdapter adapter = new PgDataAdapter(command); adapter.SelectCommand.Parameters.Add("@int4_field", PgDbType.Int4, 4, "int4_field").Value = 35; PgCommandBuilder builder = new PgCommandBuilder(adapter); DataSet ds = new DataSet(); adapter.Fill(ds, "public.test_table"); ds.Tables["public.test_table"].Rows[0].Delete(); adapter.Update(ds, "public.test_table"); adapter.Dispose(); builder.Dispose(); command.Dispose(); transaction.Commit(); } } } --- NEW FILE: PgCommandBuilderTest.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2004 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using PostgreSql.Data.PgSqlClient; using NUnit.Framework; namespace PostgreSql.Data.PgSqlClient.UnitTests { [TestFixture] public class PgCommandBuilderTest : PgBaseTest { [Test] public void GetInsertCommandTest() { PgCommand command = new PgCommand("select * from public.test_table where int4_field = @int4_field and varchar_field = @varchar_field", Connection); PgDataAdapter adapter = new PgDataAdapter(command); PgCommandBuilder builder = new PgCommandBuilder(adapter); Console.WriteLine(); Console.WriteLine("\r\nPgCommandBuilder - GetInsertCommand Method Test"); Console.WriteLine(builder.GetInsertCommand().CommandText); builder.Dispose(); adapter.Dispose(); command.Dispose(); } [Test] public void GetUpdateCommandTest() { PgCommand command = new PgCommand("select * from public.test_table where int4_field = @int4_field and varchar_field = @varchar_field", Connection); PgDataAdapter adapter = new PgDataAdapter(command); PgCommandBuilder builder = new PgCommandBuilder(adapter); Console.WriteLine(); Console.WriteLine("\r\nPgCommandBuilder - GetUpdateCommand Method Test"); Console.WriteLine(builder.GetUpdateCommand().CommandText); builder.Dispose(); adapter.Dispose(); command.Dispose(); } [Test] public void GetDeleteCommandTest() { PgCommand command = new PgCommand("select * from public.test_table where int4_field = @int4_field and varchar_field = @varchar_field", Connection); PgDataAdapter adapter = new PgDataAdapter(command); PgCommandBuilder builder = new PgCommandBuilder(adapter); Console.WriteLine(); Console.WriteLine("PgCommandBuilder - GetDeleteCommand Method Test"); Console.WriteLine( builder.GetDeleteCommand().CommandText ); builder.Dispose(); adapter.Dispose(); command.Dispose(); } [Test] public void RefreshSchemaTest() { PgCommand command = new PgCommand("select * from public.test_table where int4_field = @int4_field and varchar_field = @varchar_field", Connection); PgDataAdapter adapter = new PgDataAdapter(command); PgCommandBuilder builder = new PgCommandBuilder(adapter); Console.WriteLine(); Console.WriteLine("\r\nPgCommandBuilder - RefreshSchema Method Test - Commands for original SQL statement: "); Console.WriteLine(builder.GetInsertCommand().CommandText); Console.WriteLine(builder.GetUpdateCommand().CommandText); Console.WriteLine(builder.GetDeleteCommand().CommandText); adapter.SelectCommand.CommandText = "select int4_field, date_field from public.test_table where int4_field = @int4_field"; builder.RefreshSchema(); Console.WriteLine(); Console.WriteLine("\r\nPgCommandBuilder - RefreshSchema Method Test - Commands for new SQL statement: "); Console.WriteLine(builder.GetInsertCommand().CommandText); Console.WriteLine(builder.GetUpdateCommand().CommandText); Console.WriteLine(builder.GetDeleteCommand().CommandText); builder.Dispose(); adapter.Dispose(); command.Dispose(); } [Test] public void CommandBuilderWithExpressionFieldTest() { PgCommand command = new PgCommand("select public.test_table.*, 0 AS EXPR_VALUE from public.test_table where int4_field = @int4_field and varchar_field = @varchar_field", Connection); PgDataAdapter adapter = new PgDataAdapter(command); PgCommandBuilder builder = new PgCommandBuilder(adapter); Console.WriteLine(); Console.WriteLine("PgCommandBuilder - CommandBuilderWithExpressionFieldTest"); Console.WriteLine(builder.GetUpdateCommand().CommandText); builder.Dispose(); adapter.Dispose(); command.Dispose(); } [Test] public void DeriveParameters() { PgCommandBuilder builder = new PgCommandBuilder(); PgCommand command = new PgCommand("DeriveCount", Connection); command.CommandType = CommandType.StoredProcedure; PgCommandBuilder.DeriveParameters(command); Console.WriteLine("\r\nPgCommandBuilder - DeriveParameters static Method Test"); for (int i = 0; i < command.Parameters.Count; i++) { Console.WriteLine("Parameter name: {0}\tParameter Source Column:{1}\tDirection:{2}", command.Parameters[i].ParameterName, command.Parameters[i].SourceColumn, command.Parameters[i].Direction); } } [Test] public void DeriveParameters2() { PgTransaction transaction = Connection.BeginTransaction(); PgCommandBuilder builder = new PgCommandBuilder(); PgCommand command = new PgCommand("DeriveCount", Connection, transaction); command.CommandType = CommandType.StoredProcedure; PgCommandBuilder.DeriveParameters(command); Console.WriteLine("\r\nPgCommandBuilder - DeriveParameters static Method Test"); for (int i = 0; i < command.Parameters.Count; i++) { Console.WriteLine("Parameter name: {0}\tParameter Source Column:{1}\tDirection:{2}", command.Parameters[i].ParameterName, command.Parameters[i].SourceColumn, command.Parameters[i].Direction); } transaction.Commit(); } [Test] public void TestWithClosedConnection() { Connection.Close(); PgCommand command = new PgCommand("select * from public.test_table where int4_field = @int4_field and varchar_field = @varchar_field", Connection); PgDataAdapter adapter = new PgDataAdapter(command); PgCommandBuilder builder = new PgCommandBuilder(adapter); Console.WriteLine(); Console.WriteLine("\r\nPgCommandBuilder - RefreshSchema Method Test - Commands for original SQL statement: "); Console.WriteLine(builder.GetInsertCommand().CommandText); Console.WriteLine(builder.GetUpdateCommand().CommandText); Console.WriteLine(builder.GetDeleteCommand().CommandText); adapter.SelectCommand.CommandText = "select int4_field, date_field from public.test_table where int4_field = @int4_field"; builder.RefreshSchema(); Console.WriteLine(); Console.WriteLine("\r\nPgCommandBuilder - RefreshSchema Method Test - Commands for new SQL statement: "); Console.WriteLine(builder.GetInsertCommand().CommandText); Console.WriteLine(builder.GetUpdateCommand().CommandText); Console.WriteLine(builder.GetDeleteCommand().CommandText); builder.Dispose(); adapter.Dispose(); command.Dispose(); } } } --- NEW FILE: PgDatabaseSchemaTest.cs --- /* PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ * Copyright (c) 2003-2004 Carlos Guzman Alvarez * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using System; using System.Data; using PostgreSql.Data.PgSqlClient; using NUnit.Framework; namespace PostgreSql.Data.PgSqlClien... [truncated message content] |