Author: gbayon
Date: Fri Dec  2 12:26:26 2005
New Revision: 351830

URL: http://svn.apache.org/viewcvs?rev=351830&view=rev
Log:
IBATISNET-119
IBATISNET-118
Added nunit test for cache

Added:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/NewFolder1/
Modified:
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
    
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj?rev=351830&r1=351829&r2=351830&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.csproj
 Fri Dec  2 12:26:26 2005
@@ -796,6 +796,7 @@
                     SubType = "Code"
                     BuildAction = "Compile"
                 />
+                <Folder RelPath = "NUnit\SqlMapTests\NewFolder1\" />
                 <File
                     RelPath = "NUnit\SqlMapTests\Oracle\ProcedureTest.cs"
                     SubType = "Code"

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs?rev=351830&r1=351829&r2=351830&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheKeyTest.cs
 Fri Dec  2 12:26:26 2005
@@ -1,8 +1,6 @@
 
-using Cache = IBatisNet.DataMapper.Configuration.Cache;
-using IBatisNet.DataMapper.TypeHandlers;
-using NUnit.Framework;
 
+using NUnit.Framework;
 
 namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests
 {
@@ -28,36 +26,45 @@
 
                private static void DoTestClassEquals(long firstLong, long 
secondLong)
                {
-                       TypeHandlerFactory factory = new TypeHandlerFactory();
-
                        // Two cache keys are equal except for the parameter.
-                       Cache.CacheKey key = new Cache.CacheKey();
-                       TestClass clazz = new TestClass(firstLong);
+                       Configuration.Cache.CacheKey key = new 
Configuration.Cache.CacheKey();
 
-                       key.Update(clazz.AProperty);
+                       key.Update(firstLong);
 
-                       Cache.CacheKey aDifferentKey = new Cache.CacheKey();
-                       clazz = new TestClass(secondLong);
+                       Configuration.Cache.CacheKey aDifferentKey = new 
Configuration.Cache.CacheKey();
 
-                       key.Update(clazz.AProperty);
+                       key.Update(secondLong);
 
                        Assert.IsFalse(aDifferentKey.Equals(key)); // should 
not be equal.
                }
 
-               private class TestClass
+               [Test]
+               public void CacheKeyWithSameHashcode() 
+               {
+                       Configuration.Cache.CacheKey key1 = new 
Configuration.Cache.CacheKey();
+                       Configuration.Cache.CacheKey key2 = new 
Configuration.Cache.CacheKey();
+
+                       key1.Update("HS1CS001");
+                       key2.Update("HS1D4001");
+
+                       Assert.AreEqual( key1.GetHashCode(), 
key2.GetHashCode(), "Expect same hashcode.");
+                       Assert.IsFalse( key1.Equals(key2),"Expect not equal");
+               }
+
+               [Test]
+               public void CacheKeyWithTwoParamsSameHashcode() 
                {
-                       private long _property = long.MinValue;
+                       Configuration.Cache.CacheKey key1 = new 
Configuration.Cache.CacheKey();
+                       Configuration.Cache.CacheKey key2 = new 
Configuration.Cache.CacheKey();
+
+                       key1.Update("HS1CS001");
+                       key1.Update("HS1D4001");
+
+                       key2.Update("HS1D4001");
+                       key2.Update("HS1CS001");
 
-                       public TestClass(long aProperty)
-                       {
-                               _property = aProperty;
-                       }
-
-                       public long AProperty
-                       {
-                               get { return _property; }
-                               set { _property = value; }
-                       }
+                       Assert.AreEqual(key1.GetHashCode(), key2.GetHashCode(), 
"Expect same hashcode.");
+                       Assert.IsFalse(key1.Equals(key2), "Expect not equal");
                }
 
        }

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs?rev=351830&r1=351829&r2=351830&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs 
(original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/CacheTest.cs 
Fri Dec  2 12:26:26 2005
@@ -112,6 +112,19 @@
                        Assert.IsTrue(firstId != thirdId);
                }
 
+               [Test]
+               public void TestFlushDataCacheOnExecute()
+               {
+                       IList list = 
sqlMap.QueryForList("GetCachedAccountsViaResultMap", null);
+                       int firstId = 
HashCodeProvider.GetIdentityHashCode(list);
+                       list = 
sqlMap.QueryForList("GetCachedAccountsViaResultMap", null);
+                       int secondId = 
HashCodeProvider.GetIdentityHashCode(list);
+                       Assert.AreEqual(firstId, secondId);
+                       sqlMap.Update("UpdateAccountViaInlineParameters", 
list[0]);
+                       list = 
sqlMap.QueryForList("GetCachedAccountsViaResultMap", null);
+                       int thirdId = 
HashCodeProvider.GetIdentityHashCode(list);
+                       Assert.IsTrue(firstId != thirdId);
+               }
 
                /// <summary>
                /// Test MappedStatement Query With Threaded Cache
@@ -141,7 +154,6 @@
                        int thirdId = 
HashCodeProvider.GetIdentityHashCode(list);
 
                        Assert.IsTrue(firstId != thirdId);
-
                }
 
 

Modified: 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
URL: 
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs?rev=351830&r1=351829&r2=351830&view=diff
==============================================================================
--- 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
 (original)
+++ 
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/MappedStatements/CachingStatement.cs
 Fri Dec  2 12:26:26 2005
@@ -26,6 +26,7 @@
 #region Using
 
 using System.Collections;
+using System.Data;
 using IBatisNet.Common;
 using IBatisNet.DataMapper.Commands;
 using IBatisNet.DataMapper.Configuration.Cache;
@@ -330,7 +331,7 @@
                        {
                                if (request.IDbCommand.Parameters[i] != null) 
                                {
-                                       
cacheKey.Update(request.IDbCommand.Parameters[i]);
+                                       cacheKey.Update( 
((IDataParameter)request.IDbCommand.Parameters[i]).Value );
                                }
                        }
                        


Reply via email to