ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robe...@apache.org
Subject svn commit: r170503 - in /incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test: IBatisNet.DataMapper.Test.csproj Maps/PostgreSQL/Npgsql/Category.xml NUnit/SqlMapTests/PostgreSQL/ NUnit/SqlMapTests/PostgreSQL/StatementGenerate.cs NUnit/SqlMapTests/PostgreSQL/StatementTest.cs
Date Tue, 17 May 2005 02:45:36 GMT
Author: roberto
Date: Mon May 16 19:45:34 2005
New Revision: 170503

URL: http://svn.apache.org/viewcvs?rev=170503&view=rev
Log:
+Adding C# DataMapper PostgreSQL NUnit-specific tests 
Generated SelectByPK is only issue (comments made in Category.xml about issue)
(still need to add PostgreSQL-specific "stored function" tests)

Added:
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementGenerate.cs
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementTest.cs
Modified:
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
    incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/PostgreSQL/Npgsql/Category.xml

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj?rev=170503&r1=170502&r2=170503&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
(original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
Mon May 16 19:45:34 2005
@@ -766,6 +766,16 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "NUnit\SqlMapTests\PostgreSQL\StatementGenerate.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "NUnit\SqlMapTests\PostgreSQL\StatementTest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "Scripts\Access\account-init.sql"
                     BuildAction = "Content"
                 />

Modified: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/PostgreSQL/Npgsql/Category.xml
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/PostgreSQL/Npgsql/Category.xml?rev=170503&r1=170502&r2=170503&view=diff
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/PostgreSQL/Npgsql/Category.xml
(original)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/Maps/PostgreSQL/Npgsql/Category.xml
Mon May 16 19:45:34 2005
@@ -12,7 +12,7 @@
 			select
 			Category_ID as Id,
 			Category_Name as Name,
-			Category_Guid as Guid
+			Category_Guid as GuidString
 			from Categories  
 			where Category_ID = #value# 
 		</select>
@@ -98,6 +98,19 @@
 			<generate table="Categories" by="Category_Id, Category_Name"/>
 		</delete>
 		
+		<!--
+		Using a parameterMap with more parameters than the SQL statement needs as parameters 
+		will throw an error with Npgsql 0.7.  This is like Oracle with MS OracleClient or ODP.NET
10g.
+		
+		Removing the parameters doesn't help though, unlike Oracle since it only selects the columns
+		listed in the parameterMap!
+		
+		MSSQL and MySQL databases and providers seem to allow unneeded parameters.
+		-->		
+		<!--
+		This creates an invalid SQL statement (ends with ? instead of :param0) :
+		<select id="SelectByPKCategoryGenerate" resultClass="Category" parameterMap="select-generate-params">
+		-->
 		<select id="SelectByPKCategoryGenerate" resultClass="Category" parameterClass="Category"
parameterMap="select-generate-params">
 			<generate table="Categories" by="Category_Id"/> 
 		</select>
@@ -158,7 +171,12 @@
 			<parameter property="Id" column="Category_Id" />
 			<parameter property="Name" column="Category_Name"/>
 		</parameterMap>
-		
+
+		<!--
+		<parameterMap id="select-generate-params">
+			<parameter property="Id" column="Category_Id" />
+		</parameterMap>
+		-->
 		<parameterMap id="select-generate-params">
 			<parameter property="Id" column="Category_Id" />
 			<parameter property="Name" column="Category_Name"/>

Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementGenerate.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementGenerate.cs?rev=170503&view=auto
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementGenerate.cs
(added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementGenerate.cs
Mon May 16 19:45:34 2005
@@ -0,0 +1,148 @@
+using System;
+using System.Collections;
+
+using NUnit.Framework;
+
+using IBatisNet.DataMapper.Test.NUnit;
+using IBatisNet.DataMapper.Test.Domain;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.PostgreSQL
+{
+	/// <summary>
+	/// Summary description for StatementGenerate.
+	/// </summary>
+	[TestFixture] 
+	[Category("PostgreSQL")]
+	public class StatementGenerate : BaseTest
+	{
+		#region SetUp & TearDown
+		/// <summary>
+		/// SetUp
+		/// </summary>
+		[SetUp] 
+		public void Init() 
+		{
+			InitSqlMap();
+			InitScript( sqlMap.DataSource, ScriptDirectory + "category-init.sql" );
+		}
+
+		/// <summary>
+		/// TearDown
+		/// </summary>
+		[TearDown] 
+		public void Dispose()
+		{ /* ... */ } 
+
+		#endregion
+
+		#region Specific statement test for PostgreSQL
+
+		/// <summary>
+		/// Test an select by key via generate statement.
+		/// </summary>
+		[Test] 
+		public void TestSelectByPK()
+		{
+			Category category = new Category();
+			category.Name = "toto";
+			category.Guid = Guid.NewGuid();
+
+			category.Id = (int)sqlMap.Insert("InsertCategoryGenerate", category);
+			Assert.AreEqual(1, category.Id);
+
+			Category categoryRead = null;
+			categoryRead = (Category) sqlMap.QueryForObject("SelectByPKCategoryGenerate", category);
+
+			Assert.AreEqual(category.Id, categoryRead.Id);
+			Assert.AreEqual(category.Name, categoryRead.Name);
+			Assert.AreEqual(category.Guid.ToString(), categoryRead.Guid.ToString());
+		}
+
+		/// <summary>
+		/// Test an select all via generate statement.
+		/// </summary>
+		[Test] 
+		public void TestSelectAll()
+		{
+			Category category = new Category();
+			category.Name = "toto";
+			category.Guid = Guid.NewGuid();
+
+			int key = (int)sqlMap.Insert("InsertCategoryGenerate", category);
+			Assert.AreEqual(1, key);
+
+			category.Name = "toto";
+			category.Guid = Guid.NewGuid();
+
+			key = (int)sqlMap.Insert("InsertCategoryGenerate", category);
+			Assert.AreEqual(2, key);
+
+			IList categorieList = sqlMap.QueryForList("SelectAllCategoryGenerate",null) as IList;
+			Assert.AreEqual(2, categorieList.Count);
+
+		}
+
+		/// <summary>
+		/// Test an insert via generate statement.
+		/// </summary>
+		[Test] 
+		public void TestInsert()
+		{
+			Category category = new Category();
+			category.Name = "toto";
+			category.Guid = Guid.Empty;
+
+			int key = (int)sqlMap.Insert("InsertCategoryGenerate", category);
+			Assert.AreEqual(1, key);
+		}
+
+		/// <summary>
+		/// Test Update Category with Extended ParameterMap
+		/// </summary>
+		[Test] 
+		public void TestUpdate()
+		{
+			Category category = new Category();
+			category.Name = "Cat";
+			category.Guid = Guid.NewGuid();
+
+			int key = (int)sqlMap.Insert("InsertCategoryGenerate", category);
+			category.Id = key;
+
+			category.Name = "Dog";
+			category.Guid = Guid.NewGuid();
+
+			sqlMap.Update("UpdateCategoryGenerate", category);
+
+			Category categoryRead = null;
+			categoryRead = (Category) sqlMap.QueryForObject("GetCategory", key);
+
+			Assert.AreEqual(category.Id, categoryRead.Id);
+			Assert.AreEqual(category.Name, categoryRead.Name);
+			Assert.AreEqual(category.Guid.ToString(), categoryRead.Guid.ToString());
+		}
+		
+		/// <summary>
+		/// Test an insert via generate statement.
+		/// </summary>
+		[Test] 
+		public void TestDelete()
+		{
+			Category category = new Category();
+			category.Name = "toto";
+			category.Guid = Guid.NewGuid();
+
+			int key = (int)sqlMap.Insert("InsertCategoryGenerate", category);
+			category.Id = key;
+			Assert.AreEqual(1, category.Id);
+			
+			sqlMap.Delete("DeleteCategoryGenerate", category);
+
+			Category categoryRead = null;
+			categoryRead = sqlMap.QueryForObject("GetCategory", key) as Category;
+
+			Assert.IsNull(categoryRead);
+		}
+		#endregion
+	}
+}

Added: incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementTest.cs
URL: http://svn.apache.org/viewcvs/incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementTest.cs?rev=170503&view=auto
==============================================================================
--- incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementTest.cs
(added)
+++ incubator/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/PostgreSQL/StatementTest.cs
Mon May 16 19:45:34 2005
@@ -0,0 +1,130 @@
+using System;
+using System.Collections;
+
+using NUnit.Framework;
+
+using IBatisNet.DataMapper.Test.NUnit;
+using IBatisNet.DataMapper.Test.Domain;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.PostgreSQL
+{
+	/// <summary>
+	/// Summary description for StatementTest.
+	/// </summary>
+	[TestFixture] 
+	[Category("PostgreSQL")]
+	public class StatementTest : BaseTest
+	{
+		
+		#region SetUp & TearDown
+		/// <summary>
+		/// SetUp
+		/// </summary>
+		[SetUp] 
+		public void Init() 
+		{
+			InitSqlMap();
+			InitScript( sqlMap.DataSource, ScriptDirectory + "category-init.sql" );
+		}
+
+		/// <summary>
+		/// TearDown
+		/// </summary>
+		[TearDown] 
+		public void Dispose()
+		{ /* ... */ } 
+
+		#endregion
+
+		#region Specific tests for PostgreSQL
+
+		/// <summary>
+		/// Test an insert with an autonumber key.
+		/// </summary>
+		[Test] 
+		public void TestInsertAutonumberViaInsertQuery()
+		{
+			Category category = new Category();
+			category.Name = "toto";
+			category.Guid = Guid.NewGuid();
+
+			int key = (int)sqlMap.Insert("InsertCategory", category);
+			Assert.AreEqual(1, key);
+		}
+
+		/// <summary>
+		/// Test Insert Via Insert Statement.
+		/// </summary>
+		[Test] 
+		public void TestInsertViaInsertStatement()
+		{
+			Category category = new Category();
+			category.Name = "toto";
+			category.Guid = Guid.NewGuid();
+
+			int key = (int)sqlMap.Insert("InsertCategoryViaInsertStatement", category);
+			Assert.AreEqual(1, key);
+		}
+
+		/// <summary>
+		/// Test guid column/field.
+		/// </summary>
+		[Test] 
+		public void TestGuidColumn()
+		{
+			Category category = new Category();
+			category.Name = "toto";
+			category.Guid = Guid.NewGuid();
+
+			int key = (int)sqlMap.Insert("InsertCategoryViaInsertStatement", category);
+
+			Category categoryTest = (Category)sqlMap.QueryForObject("GetCategory", key);
+			Assert.AreEqual(key, categoryTest.Id);
+			Assert.AreEqual(category.Name, categoryTest.Name);
+			Assert.AreEqual(category.Guid, categoryTest.Guid);
+		}
+
+		/// <summary>
+		/// Test Insert Category Via ParameterMap.
+		/// </summary>
+		[Test] 
+		public void TestInsertCategoryViaParameterMap()
+		{
+			Category category = new Category();
+			category.Name = "Cat";
+			category.Guid = Guid.NewGuid();
+
+			int key = (int)sqlMap.Insert("InsertCategoryViaParameterMap", category);
+			Assert.AreEqual(1, key);
+		}
+
+		/// <summary>
+		/// Test Update Category with Extended ParameterMap
+		/// </summary>
+		[Test] 
+		public void TestUpdateCategoryWithExtendParameterMap()
+		{
+			Category category = new Category();
+			category.Name = "Cat";
+			category.Guid = Guid.NewGuid();
+
+			int key = (int)sqlMap.Insert("InsertCategoryViaParameterMap", category);
+			category.Id = key;
+
+			category.Name = "Dog";
+			category.Guid = Guid.NewGuid();
+
+			sqlMap.Update("UpdateCategoryViaParameterMap", category);
+
+			Category categoryRead = null;
+			categoryRead = (Category) sqlMap.QueryForObject("GetCategory", key);
+
+			Assert.AreEqual(category.Id, categoryRead.Id);
+			Assert.AreEqual(category.Name, categoryRead.Name);
+			Assert.AreEqual(category.Guid.ToString(), categoryRead.Guid.ToString());
+		}
+		#endregion
+
+
+	}
+}



Mime
View raw message