Author: gbayon
Date: Sat Oct 11 14:26:43 2008
New Revision: 703735

URL: http://svn.apache.org/viewvc?rev=703735&view=rev
Log:
Fix IBATISNET-283

Modified:
    ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/Account.cs
    
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
    
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs
    
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/DataExchange/DotNetObjectDataExchange.cs

Modified: ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/Account.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/Account.cs?rev=703735&r1=703734&r2=703735&view=diff
==============================================================================
--- ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/Account.cs 
(original)
+++ ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Domain/Account.cs Sat Oct 
11 14:26:43 2008
@@ -6,6 +6,50 @@
 
 namespace IBatisNet.DataMapper.Test.Domain
 {
+    public interface IAccount
+    {
+        int Id { get; set; }
+        string FirstName { get; set; }
+        string LastName { get; set; }
+        string EmailAddress { get; set; }
+    }
+
+    public class BaseAccount : IAccount
+    {
+        private int id;
+        private string firstName;
+        private string lastName;
+        private string emailAddress;
+
+        #region IAccount Members
+
+        public int Id
+        {
+            get { return id; }
+            set { id = value; }
+        }
+
+        public string FirstName
+        {
+            get { return firstName; }
+            set { firstName = value; }
+        }
+
+        public string LastName
+        {
+            get { return lastName; }
+            set { lastName = value; }
+        }
+
+        public string EmailAddress
+        {
+            get { return emailAddress; }
+            set { emailAddress = value; }
+        }
+
+        #endregion
+    }
+
        /// <summary>
        /// Description résumée de Account.
        /// </summary>

Modified: 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml?rev=703735&r1=703734&r2=703735&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
 (original)
+++ 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/Maps/MSSQL/SqlClient/Account.xml
 Sat Oct 11 14:26:43 2008
@@ -49,6 +49,8 @@
        <alias>
                <typeAlias alias="HundredsBool" 
type="IBatisNet.DataMapper.Test.Domain.HundredsTypeHandlerCallback, 
IBatisNet.DataMapper.Test"/>
     <typeAlias alias="Category2" 
type="IBatisNet.DataMapper.Test.Domain.Category, IBatisNet.DataMapper.Test"/>
+    <typeAlias alias="IAccount" 
type="IBatisNet.DataMapper.Test.Domain.IAccount, IBatisNet.DataMapper.Test"/>
+
   </alias>       
   
   <cacheModels>
@@ -175,6 +177,16 @@
     -->
   <statements>
 
+    <select id="GetInterfaceAccount" resultClass="IAccount">
+                                       select
+                                       Account_ID as Id,
+                                       Account_FirstName as FirstName,
+                                       Account_LastName as LastName,
+                                       Account_Email as EmailAddress
+                                       from Accounts
+                                       where Account_ID = #value#
+    </select>
+    
     <select id="GetLruCachedAccountsViaResultMap"
       resultMap="account-result"
       cacheModel="lru-account-cache" >

Modified: 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs?rev=703735&r1=703734&r2=703735&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs
 (original)
+++ 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/StatementTest.cs
 Sat Oct 11 14:26:43 2008
@@ -44,6 +44,24 @@
         #region Object Query tests
 
         /// <summary>
+        /// Interface mapping
+        /// </summary>
+        [Test]
+        [Category("JIRA")]
+        [Description("JIRA-283")]
+        public void TestInterface()
+        {
+            BaseAccount account = new BaseAccount();
+
+            sqlMap.QueryForObject<IAccount>("GetInterfaceAccount", 1, account);
+
+            Assert.AreEqual(1, account.Id, "account.Id");
+            Assert.AreEqual("Joe", account.FirstName, "account.FirstName");
+            Assert.AreEqual("Dalton", account.LastName, "account.LastName");
+            Assert.AreEqual("[EMAIL PROTECTED]", account.EmailAddress, 
"account.EmailAddress");
+        }
+
+        /// <summary>
         /// Test Open connection with a connection string
         /// </summary>
         [Test]

Modified: 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/DataExchange/DotNetObjectDataExchange.cs
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/DataExchange/DotNetObjectDataExchange.cs?rev=703735&r1=703734&r2=703735&view=diff
==============================================================================
--- 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/DataExchange/DotNetObjectDataExchange.cs
 (original)
+++ 
ibatis/trunk/cs/V1/src/IBatisNet.DataMapper/DataExchange/DotNetObjectDataExchange.cs
 Sat Oct 11 14:26:43 2008
@@ -78,12 +78,13 @@
                /// <param name="dataBaseValue"></param>
                public override void SetData(ref object target, ResultProperty 
mapping, object dataBaseValue)
                {
-                   Type targetType = target.GetType();
+            Type targetType = target.GetType();
             if ((targetType != _parameterClass)
-                && !targetType.IsSubclassOf(_parameterClass)) 
-                       {
-                throw new ArgumentException("Could not set value of type '" + 
target.GetType() + "' in property '" + mapping.PropertyName + "' of type '" + 
_parameterClass + "'");
-                       }
+                && !targetType.IsSubclassOf(_parameterClass)
+                && !_parameterClass.IsAssignableFrom(targetType))
+            {
+                throw new ArgumentException("Could not set value in class '" + 
target.GetType() + "' for property '" + mapping.PropertyName + "' of type '" + 
mapping.MemberType + "'");
+            }
                        if ( mapping.IsComplexMemberName)
                        {
                                ObjectProbe.SetMemberValue(target, 
mapping.PropertyName, dataBaseValue, 


Reply via email to