Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Caching
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15042
Modified Files:
AspNetCacheTests.cs
Log Message:
added test for AbstractCache and AspNetCache
Index: AspNetCacheTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Web.Tests/Caching/AspNetCacheTests.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AspNetCacheTests.cs 24 Aug 2007 22:44:35 -0000 1.1
--- AspNetCacheTests.cs 25 Aug 2007 10:22:13 -0000 1.2
***************
*** 34,38 ****
{
/// <summary>
! ///
/// </summary>
/// <author>Erich Eichinger</author>
--- 34,38 ----
{
/// <summary>
! /// Test AspNetCache behaviour.
/// </summary>
/// <author>Erich Eichinger</author>
***************
*** 46,49 ****
--- 46,53 ----
private readonly TimeSpan ttl10Seconds = new TimeSpan(0, 0, 10);
+ MockRepository mocks;
+ AspNetCache.IRuntimeCache mockedRuntimeCache;
+ AspNetCache mockedCache;
+
[SetUp]
public void SetUp()
***************
*** 57,60 ****
--- 61,129 ----
thisCache = new AspNetCache();
otherCache = new AspNetCache();
+
+ mocks = new MockRepository();
+ mockedRuntimeCache = (AspNetCache.IRuntimeCache)mocks.CreateMock(typeof(AspNetCache.IRuntimeCache));
+ mockedCache = new AspNetCache(mockedRuntimeCache);
+ }
+
+ [Test]
+ public void Get()
+ {
+ // set expectations
+ Expect.Call(mockedRuntimeCache.Get(mockedCache.GenerateKey("key"))).Return(null);
+ mocks.ReplayAll();
+ // verify
+ mockedCache.Get("key");
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void Remove()
+ {
+ // set expectations
+ Expect.Call(mockedRuntimeCache.Remove(mockedCache.GenerateKey("key"))).Return(null);
+ mocks.ReplayAll();
+ // verify
+ mockedCache.Remove("key");
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void DoesNotAcceptNullKeysOnInsert()
+ {
+ thisCache.Insert(null, "value", TimeSpan.Zero, true);
+ }
+
+ [Test]
+ public void GetNullKeysReturnsNull()
+ {
+ Assert.IsNull(thisCache.Get(null));
+ }
+
+ [Test]
+ public void IgnoreNullKeysOnRemove()
+ {
+ thisCache.Remove(null);
+ }
+
+ [Test]
+ public void ReturnsOnlyKeysOwnedByCache()
+ {
+ DictionaryEntry[] mockedRuntimeCacheEntries =
+ {
+ new DictionaryEntry(mockedCache.GenerateKey("keyA"), null)
+ , new DictionaryEntry(mockedCache.GenerateKey("keyB"), null)
+ , new DictionaryEntry(thisCache.GenerateKey("keyC"), null)
+ , new DictionaryEntry(otherCache.GenerateKey("keyD"), null)
+ };
+
+ // set expectations
+ Expect.Call(mockedRuntimeCache.GetEnumerator()).Return(mockedRuntimeCacheEntries.GetEnumerator());
+ mocks.ReplayAll();
+ // verify
+ ICollection keys = mockedCache.Keys;
+ Assert.AreEqual( new string[] { "keyA", "keyB" }, new ArrayList(keys).ToArray(typeof(string)) );
+ mocks.VerifyAll();
}
***************
*** 103,116 ****
[Test]
! public void HandlesTTLAndSlidingExpiration()
{
MockRepository mocks = new MockRepository();
! AspNetCache.IRuntimeCache runtimeCache = (AspNetCache.IRuntimeCache) mocks.CreateMock(typeof(AspNetCache.IRuntimeCache));
! AspNetCache cache = new AspNetCache(runtimeCache);
- runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
mocks.ReplayAll();
! cache.Insert( "key", "value" );
mocks.VerifyAll();
--- 172,213 ----
[Test]
! public void PassesParametersToRuntimeCache()
{
MockRepository mocks = new MockRepository();
! AspNetCache.IRuntimeCache runtimeCache = (AspNetCache.IRuntimeCache) mocks.CreateMock(typeof(AspNetCache.IRuntimeCache));
! AspNetCache cache = new AspNetCache(runtimeCache);
!
! DateTime expectedAbsoluteExpiration = DateTime.Now;
! TimeSpan expectedSlidingExpiration = ttl10Seconds;
! CacheItemPriority expectedPriority = CacheItemPriority.Low;
!
! // TODO: find way to test non-sliding expiration case
! // runtimeCache.Insert(cache.GenerateKey("key"), "value", null, DateTime.Now.Add(ttl10Seconds), Cache.NoSlidingExpiration, expectedPriority, null);
! runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, ttl10Seconds, expectedPriority, null);
mocks.ReplayAll();
! // cache.Insert( "key", "value", ttl10Seconds, false, expectedPriority );
! cache.Insert("key", "value", ttl10Seconds, true, expectedPriority);
!
! mocks.VerifyAll();
! }
!
! [Test]
! public void ZeroTTLCausesNoExpiration()
! {
! MockRepository mocks = new MockRepository();
! AspNetCache.IRuntimeCache runtimeCache = (AspNetCache.IRuntimeCache)mocks.CreateMock(typeof(AspNetCache.IRuntimeCache));
! AspNetCache cache = new AspNetCache(runtimeCache);
!
! CacheItemPriority expectedPriority = CacheItemPriority.Low;
!
! runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, expectedPriority, null);
! runtimeCache.Insert(cache.GenerateKey("key"), "value", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, expectedPriority, null);
!
! mocks.ReplayAll();
!
! cache.Insert("key", "value", TimeSpan.Zero, true, expectedPriority);
! cache.Insert("key", "value", TimeSpan.Zero, false, expectedPriority);
mocks.VerifyAll();
|