[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient.UnitTests/source PgBaseTest.cs,1.6
Status: Inactive
Brought to you by:
carlosga_fb
|
From: <car...@us...> - 2003-11-13 09:19:43
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient.UnitTests/source
In directory sc8-pr-cvs1:/tmp/cvs-serv653
Modified Files:
PgBaseTest.cs PgGeometicTypesTest.cs
Log Message:
Added NUnit test for LSeg, Path and Polygon Geometry types
Index: PgBaseTest.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient.UnitTests/source/PgBaseTest.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** PgBaseTest.cs 25 Oct 2003 20:57:49 -0000 1.6
--- PgBaseTest.cs 13 Nov 2003 09:19:40 -0000 1.7
***************
*** 23,26 ****
--- 23,29 ----
using NUnit.Framework;
+ using PostgreSql.Data.PgSqlClient;
+ using PostgreSql.Data.PgTypes;
+
namespace PostgreSql.Data.PgSqlClient.UnitTests
{
***************
*** 167,187 ****
// Table for Geometric types tests
!
! commandText.Append("CREATE TABLE public.gemetric_test(");
commandText.Append("pk int4 NOT NULL,");
commandText.Append("point_field point,");
! commandText.Append("point_array point[][],");
! commandText.Append("box_field box,");
! commandText.Append("box_array box[],");
! commandText.Append("line_field line,");
! commandText.Append("line_array line[],");
commandText.Append("circle_field circle,");
! commandText.Append("circle_array circle[],");
commandText.Append("polygon_field polygon,");
! commandText.Append("polygon_array polygon[],");
! commandText.Append("lseg_field lseg,");
commandText.Append("lseg_array lseg[],");
- commandText.Append("path_field path,");
commandText.Append("path_array path[],");
commandText.Append("CONSTRAINT geometric_test_pkey PRIMARY KEY (pk)");
commandText.Append(") WITH OIDS;");
--- 170,189 ----
// Table for Geometric types tests
! commandText.Append("CREATE TABLE public.geometric_table(");
commandText.Append("pk int4 NOT NULL,");
commandText.Append("point_field point,");
! commandText.Append("box_field box,");
commandText.Append("circle_field circle,");
! commandText.Append("lseg_field lseg,");
! commandText.Append("path_field path,");
commandText.Append("polygon_field polygon,");
! commandText.Append("point_array point[],");
! commandText.Append("box_array box[],");
! commandText.Append("circle_array circle[],");
commandText.Append("lseg_array lseg[],");
commandText.Append("path_array path[],");
+ commandText.Append("polygon_array polygon[],");
+ commandText.Append("line_field line,");
+ commandText.Append("line_array line[],");
commandText.Append("CONSTRAINT geometric_test_pkey PRIMARY KEY (pk)");
commandText.Append(") WITH OIDS;");
***************
*** 192,195 ****
--- 194,198 ----
insertTestData();
+ insertGeometricTestData();
}
***************
*** 283,287 ****
command.Parameters.Add("@date_field", PgDbType.Date);
command.Parameters.Add("@time_field", PgDbType.Time);
! command.Parameters.Add("@timestamp_field", PgDbType.TimeStamp);
for (int i = 0; i < 100; i++)
--- 286,290 ----
command.Parameters.Add("@date_field", PgDbType.Date);
command.Parameters.Add("@time_field", PgDbType.Time);
! command.Parameters.Add("@timestamp_field", PgDbType.Timestamp);
for (int i = 0; i < 100; i++)
***************
*** 295,298 ****
--- 298,346 ----
command.Parameters["@time_field"].Value = DateTime.Now;
command.Parameters["@timestamp_field"].Value = DateTime.Now;
+
+ command.ExecuteNonQuery();
+ }
+
+ // Commit transaction
+ transaction.Commit();
+ }
+ catch (PgException ex)
+ {
+ transaction.Rollback();
+ throw ex;
+ }
+ finally
+ {
+ command.Dispose();
+ }
+ }
+
+ private void insertGeometricTestData()
+ {
+ string commandText = "insert into public.geometric_table values(@pk, @point, @box, @circle, @lseg, @path, @polygon)";
+
+ PgTransaction transaction = connection.BeginTransaction();
+ PgCommand command = new PgCommand(commandText, connection, transaction);
+
+ try
+ {
+ // Add command parameters
+ command.Parameters.Add("@pk", PgDbType.Int4);
+ command.Parameters.Add("@point", PgDbType.Point);
+ command.Parameters.Add("@box", PgDbType.Box);
+ command.Parameters.Add("@circle", PgDbType.Circle);
+ command.Parameters.Add("@lseg", PgDbType.LSeg);
+ command.Parameters.Add("@path", PgDbType.Path);
+ command.Parameters.Add("@polygon", PgDbType.Polygon);
+
+ for (int i = 0; i < 100; i++)
+ {
+ command.Parameters["@pk"].Value = i;
+ command.Parameters["@point"].Value = new PgPoint(i, i + 10);
+ command.Parameters["@box"].Value = new PgBox(new PgPoint(0,i), new PgPoint(i, i));
+ command.Parameters["@circle"].Value = new PgCircle(new PgPoint(i, 0), i);
+ command.Parameters["@lseg"].Value = new PgLSeg(new PgPoint(-1,0), new PgPoint(1,0));
+ command.Parameters["@path"].Value = new PgPath(false, new PgPoint[]{new PgPoint(0,0), new PgPoint(1,0)});
+ command.Parameters["@polygon"].Value= new PgPolygon(new PgPoint[]{new PgPoint(1,1), new PgPoint(0,0)});
command.ExecuteNonQuery();
Index: PgGeometicTypesTest.cs
===================================================================
RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient.UnitTests/source/PgGeometicTypesTest.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PgGeometicTypesTest.cs 25 Oct 2003 21:59:33 -0000 1.2
--- PgGeometicTypesTest.cs 13 Nov 2003 09:19:40 -0000 1.3
***************
*** 32,74 ****
public void PointTest()
{
}
[Test]
! public void LineSegmentTest()
{
}
[Test]
! public void BoxTest()
{
}
[Test]
! public void PathTest()
{
}
[Test]
! public void PolygonTest()
{
}
[Test]
! public void CircleTest()
{
}
[Test]
! public void PointArrayTest()
{
}
[Test]
! public void LineSegmentArrayTest()
{
}
[Test]
! public void BoxArrayTest()
{
}
--- 32,207 ----
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 ex)
+ {
+ throw ex;
+ }
+ 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 ex)
+ {
+ throw ex;
+ }
+ 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 ex)
+ {
+ throw ex;
+ }
+ 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 ex)
+ {
+ throw ex;
+ }
+ 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 ex)
+ {
+ throw ex;
+ }
+ 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 ex)
+ {
+ throw ex;
+ }
+ finally
+ {
+ command.Dispose();
+ }
}
[Test]
! public void BoxArrayTest()
{
}
[Test]
! public void PointArrayTest()
{
}
[Test]
! public void LineSegmentArrayTest()
{
}
|