Author: gbayon
Date: Sat Sep 20 08:37:58 2008
New Revision: 697381

URL: http://svn.apache.org/viewvc?rev=697381&view=rev
Log:
Add tests for stored procedure with multiple output parameters with/without 
null values

Added:
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/ps_SelectAccountViaOuputParam.sql
Modified:
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/MSSQL/ProcedureTest.cs
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/account-init.sql
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ParameterMapping/InlineParameterMapParser.cs

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj?rev=697381&r1=697380&r2=697381&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj
 Sat Sep 20 08:37:58 2008
@@ -223,6 +223,7 @@
     <Content Include="Scripts\petstore-schema.sql" />
     <Content Include="Scripts\ps_InsertAccountWithDefault.sql" />
     <Content Include="Scripts\ps_SelectAccount.sql" />
+    <Content Include="Scripts\ps_SelectAccountViaOuputParam.sql" />
     <Content Include="Scripts\ps_SelectAccountWithOutPutParam.sql" />
     <Content Include="Scripts\ps_SelectAllAccount.sql" />
     <None Include="App.config" />

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/MSSQL/ProcedureTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/MSSQL/ProcedureTest.cs?rev=697381&r1=697380&r2=697381&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/MSSQL/ProcedureTest.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/MSSQL/ProcedureTest.cs
 Sat Sep 20 08:37:58 2008
@@ -35,6 +35,8 @@
             InitScript(sessionFactory.DataSource, scriptDirectory + 
"swap-procedure.sql");
             InitScript(sessionFactory.DataSource, scriptDirectory + 
"ps_SelectAccountWithOutPutParam.sql");
             InitScript(sessionFactory.DataSource, scriptDirectory + 
"ps_InsertAccountWithDefault.sql");
+            InitScript(sessionFactory.DataSource, scriptDirectory + 
"ps_SelectAccountViaOuputParam.sql");
+
         }
 
         /// <summary>
@@ -157,6 +159,68 @@
         }
 
         /// <summary>
+        /// ResultClass via Output param should be returned.
+        /// </summary>
+        [Test]
+        public void ResultClass_via_output_param_should_be_returned()
+        {
+            Account account = new Account();
+            account.Id = 1;
+
+            
dataMapper.QueryForObject<Account>("SelectAccountViaOutputParameter", account);
+
+            AssertAccount1(account);
+        }
+
+        /// <summary>
+        /// ResultClass via Output param should be returned.
+        /// </summary>
+        [Test]
+        public void ResultClass_via_inline_output_param_should_be_returned()
+        {
+            Account account = new Account();
+            account.Id = 1;
+
+            
dataMapper.QueryForObject<Account>("SelectAccountViaOutputParameterInlineParameter",
 account);
+
+            AssertAccount1(account);
+        }
+
+        /// <summary>
+        /// ResultClass via Output param should be returned even when
+        /// the output is null
+        /// </summary>
+        [Test]
+        public void ResultClass_via_output_param_and_null_should_be_returned()
+        {
+            Account account = new Account();
+            account.Id = 99;
+
+            
dataMapper.QueryForObject<Account>("SelectAccountViaOutputParameter", account);
+
+            Assert.That(account.EmailAddress, Is.EqualTo("[EMAIL PROTECTED]"));
+            Assert.That(account.FirstName, Is.Null);
+            Assert.That(account.LastName, Is.Null);
+        }
+
+        /// <summary>
+        /// ResultClass via Output param should be returned even when
+        /// the output is null
+        /// </summary>
+        [Test]
+        public void 
ResultClass_via_inline_output_param_and_null_should_be_returned()
+        {
+            Account account = new Account();
+            account.Id = 99;
+
+            
dataMapper.QueryForObject<Account>("SelectAccountViaOutputParameterInlineParameter",
 account);
+
+            Assert.That(account.EmailAddress, Is.EqualTo("[EMAIL PROTECTED]"));
+            Assert.That(account.FirstName, Is.Null);
+            Assert.That(account.LastName, Is.Null);
+        }
+
+        /// <summary>
         /// Test an insert with via a store procedure and getting the 
generatedKey from a t-sql return statement
         /// </summary>
         [Test]

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml?rev=697381&r1=697380&r2=697381&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
 Sat Sep 20 08:37:58 2008
@@ -811,6 +811,18 @@
     <procedure id="SelectAccountWithOutPutParam" parameterMap="select-params3" 
resultClass="Account">
       ps_SelectAccountWithOutPutParam
     </procedure>
+
+    <procedure id="SelectAccountViaOutputParameter" 
parameterMap="account-via-output" resultClass="Account">
+      ps_SelectAccountViaOuputParam
+    </procedure>
+
+    <procedure id="SelectAccountViaOutputParameterInlineParameter" 
parameterClass="Account" resultClass="Account">
+      ps_SelectAccountViaOuputParam
+      @{Id,column=Account_ID,direction=InputOutput},
+      @{FirstName,column=Account_FirstName,direction=Output},
+      @{LastName,column=Account_LastName,direction=Output},
+      @{EmailAddress,column=Account_Email,nullValue="[EMAIL PROTECTED]"}
+    </procedure>
     
     <procedure id="SPWithInlineParameter" parameterClass="int" 
resultClass="Account">
       ps_SelectAccount @{Account_ID,column=Account_ID}
@@ -853,7 +865,14 @@
        </statements>
 
        <parameterMaps>
-
+     
+    <parameterMap id="account-via-output" class ="Account">
+      <parameter property="Id" column="Account_ID" direction="InputOutput" />
+      <parameter property="FirstName" column="Account_FirstName" />
+      <parameter property="LastName" column="Account_LastName" />
+      <parameter property="EmailAddress" column="Account_Email" 
nullValue="[EMAIL PROTECTED]"/>
+    </parameterMap>
+    
     <parameterMap id="XML-params" class="string" >
       <parameter property="AccountIds" /> <!-- we don't need dbType="NText" 
but you can specify it --> 
     </parameterMap>

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/account-init.sql
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/account-init.sql?rev=697381&r1=697380&r2=697381&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/account-init.sql
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/account-init.sql
 Sat Sep 20 08:37:58 2008
@@ -57,4 +57,7 @@
 drop procedure [dbo].[ps_SelectAccountWithOutPutParam]
 
 if exists (select * from dbo.sysobjects where id = 
object_id(N'[dbo].[ps_InsertAccountWithDefault]') and OBJECTPROPERTY(id, 
N'IsProcedure') = 1)
-drop procedure [dbo].[ps_InsertAccountWithDefault]
\ No newline at end of file
+drop procedure [dbo].[ps_InsertAccountWithDefault]
+
+if exists (select * from dbo.sysobjects where id = 
object_id(N'[dbo].[ps_SelectAccountViaOuputParam]') and OBJECTPROPERTY(id, 
N'IsProcedure') = 1)
+drop procedure [dbo].[ps_SelectAccountViaOuputParam]
\ No newline at end of file

Added: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/ps_SelectAccountViaOuputParam.sql
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/ps_SelectAccountViaOuputParam.sql?rev=697381&view=auto
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/ps_SelectAccountViaOuputParam.sql
 (added)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Scripts/ps_SelectAccountViaOuputParam.sql
 Sat Sep 20 08:37:58 2008
@@ -0,0 +1,13 @@
+CREATE PROCEDURE dbo.[ps_SelectAccountViaOuputParam]
[EMAIL PROTECTED]  [int] OUTPUT,
[EMAIL PROTECTED] varchar(32) OUTPUT, 
[EMAIL PROTECTED]  varchar(32) OUTPUT, 
[EMAIL PROTECTED]  varchar(128) OUTPUT 
+AS
+select
+       @Account_ID = Account_ID,
+       @Account_FirstName = Account_FirstName,
+       @Account_LastName = Account_LastName,
+       @Account_Email = Account_Email
+from Accounts
+where Account_ID = @Account_ID
\ No newline at end of file

Modified: 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ParameterMapping/InlineParameterMapParser.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ParameterMapping/InlineParameterMapParser.cs?rev=697381&r1=697380&r2=697381&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ParameterMapping/InlineParameterMapParser.cs
 (original)
+++ 
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/ParameterMapping/InlineParameterMapParser.cs
 Sat Sep 20 08:37:58 2008
@@ -221,7 +221,14 @@
                                        } 
                                        else if ("nullValue".Equals(field)) 
                                        {
-                        nullValue = value;
+                        if (value.StartsWith("\"") && value.EndsWith("\""))
+                        {
+                            nullValue = value.Substring(1, value.Length-2);
+                        }
+                        else
+                        {
+                            nullValue = value;
+                        }
                                        } 
                                        else if ("handler".Equals(field)) 
                                        {


Reply via email to