[Adapdev-commits] Adapdev/src/Adapdev.Cache.Tests AbstractICacheTest.cs,NONE,1.1 CacheManagerTest.cs
Status: Beta
Brought to you by:
intesar66
|
From: Sean M. <int...@us...> - 2005-05-25 05:18:26
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Cache.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10621/src/Adapdev.Cache.Tests Modified Files: Adapdev.Cache.Tests.csproj Added Files: AbstractICacheTest.cs CacheManagerTest.cs CacheUtilTest.cs FileCacheTest.cs ImmutableInMemoryCache.cs MutableInMemoryCacheTest.cs Log Message: MIgrated reusable Perseus components Added SmartTreeView Added new caching framework Several Sql fixes Added business rule validation classes Added FieldAccessor for IL generation --- NEW FILE: AbstractICacheTest.cs --- using System; using NUnit.Framework; using Adapdev.Cache; using Adapdev.Mock; namespace Adapdev.Tests.Cache { /// <summary> /// Summary description for MutableInMemoryCache. /// </summary> /// public abstract class AbstractICacheTest { protected ICache cache = null; public abstract ICache GetCache(); [SetUp] public void Setup() { this.cache = this.GetCache(); } [TearDown] public void TearDown() { cache.Clear(); cache = null; } [Test] public void Add() { SuppliersEntity e = new SuppliersEntity(); e.SupplierID = 12; cache.Add(12, e); Assert.IsTrue(cache.Count == 1, "Cache count should be 1."); } [Test] public void Get() { SuppliersEntity e = new SuppliersEntity(); e.SupplierID = 12; e.ContactName = "Joe Schmoe"; cache.Add(12, e); Assert.IsTrue(cache.Count == 1, "Cache count should be 1."); Assert.AreEqual(e.ContactName, (cache.Get(typeof(SuppliersEntity), 12) as SuppliersEntity).ContactName); } [Test] public void Clear() { SuppliersEntity e = new SuppliersEntity(); e.SupplierID = 12; cache.Add(12, e); Assert.IsTrue(cache.Count == 1, "Cache count should be 1."); cache.Clear(); Assert.IsTrue(cache.Count == 0, "Cache count should be 0."); } [Test] public void Remove() { SuppliersEntity e = new SuppliersEntity(); e.SupplierID = 12; cache.Add(12, e); Assert.IsTrue(cache.Count == 1, "Cache count should be 1."); cache.Remove(e.GetType(), e.SupplierID); Assert.IsTrue(cache.Count == 0, "Cache count should be 0."); } [Test] public void Entries() { SuppliersEntity e1 = new SuppliersEntity(); e1.SupplierID = 12; SuppliersEntity e2 = new SuppliersEntity(); e2.SupplierID = 13; cache.Add(e1.SupplierID, e1); cache.Add(e2.SupplierID, e2); Assert.IsTrue(cache.Count == 2, "Cache count should be 2."); int i = 0; foreach(CacheItem c in cache.Entries) { i++; Assert.IsNotNull(c.Object); } Assert.AreEqual(cache.Count, i); } [Test] public void Ordinal() { SuppliersEntity e1 = new SuppliersEntity(); e1.SupplierID = 12; SuppliersEntity e2 = new SuppliersEntity(); e2.SupplierID = 13; cache.Add(e1.SupplierID, e1); cache.Add(e2.SupplierID, e2); Assert.IsTrue(cache.Count == 2, "Cache count should be 2."); CacheItem c1 = cache.GetCacheItem(typeof(SuppliersEntity), e1.SupplierID); CacheItem c2 = cache.GetCacheItem(typeof(SuppliersEntity), e2.SupplierID); Assert.IsTrue(c1.Ordinal != c2.Ordinal, "Ordinals should be different."); Assert.IsTrue(c2.Ordinal == c1.Ordinal + 1, "Ordinals should only be 1 number apart."); } [Test] public void Contains() { SuppliersEntity e1 = new SuppliersEntity(); e1.SupplierID = 12; cache.Add(e1.SupplierID, e1); Assert.IsTrue(cache.Contains(e1.GetType(), e1.SupplierID), "Cache should return true for .Contains"); } [Test] public void CacheItem() { SuppliersEntity e1 = new SuppliersEntity(); e1.SupplierID = 12; cache.Add(e1.SupplierID, e1); CacheItem c = cache.GetCacheItem(e1.GetType(), e1.SupplierID); Assert.AreEqual(e1.GetType(), c.ObjectType, "Object Types aren't equal."); Assert.AreEqual(1, c.Ordinal, "Ordinal should be 1"); Assert.AreEqual(e1.SupplierID.ToString(), c.Key, "Keys are not equal."); Console.WriteLine(c); } [Test] public void Copy() { ICache source = this.GetCache(); this.cache.Add(1, new SuppliersEntity()); source.Add(2, new SuppliersEntity()); Assert.AreEqual(1, this.cache.Count); Assert.AreEqual(1, source.Count); this.cache.Copy(source); Assert.AreEqual(2, this.cache.Count); } } } --- NEW FILE: CacheManagerTest.cs --- using System; using NUnit.Framework; using Adapdev.Cache; using Adapdev.Mock; namespace Adapdev.Tests.Cache { /// <summary> /// Summary description for CacheManagerTest. /// </summary> /// [TestFixture] public class CacheManagerTest { [Test] public void Cache() { Assert.AreEqual(typeof(ImmutableInMemoryCache), CacheManager.Cache.GetType()); CacheManager.Cache.Add(1, new SuppliersEntity()); Assert.AreEqual(1, CacheManager.Cache.Count); CacheManager.Cache = new MutableInMemoryCache(); Assert.AreEqual(0, CacheManager.Cache.Count, "Cache has switched, so count should be 0."); } } } --- NEW FILE: MutableInMemoryCacheTest.cs --- using System; using NUnit.Framework; using Adapdev.Cache; using Adapdev.Mock; namespace Adapdev.Tests.Cache { /// <summary> /// Summary description for MutableInMemoryCache. /// </summary> /// [TestFixture] public class MutableInMemoryCacheTest : AbstractICacheTest { public override ICache GetCache() { return new MutableInMemoryCache(); } [Test] public void Mutable() { SuppliersEntity e1 = new SuppliersEntity(); e1.SupplierID = 12; cache.Add(e1.SupplierID, e1); SuppliersEntity e2 = cache.Get(typeof(SuppliersEntity), 12) as SuppliersEntity; e2.SupplierID = 13; Assert.IsTrue(cache.Contains(e1.GetType(), 12), "Cache key should not change."); SuppliersEntity e3 = cache.Get(typeof(SuppliersEntity), 12) as SuppliersEntity; Assert.AreEqual(13, e3.SupplierID, "Object in cache should have been updated."); } } } Index: Adapdev.Cache.Tests.csproj =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Cache.Tests/Adapdev.Cache.Tests.csproj,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Adapdev.Cache.Tests.csproj 14 Apr 2005 03:32:02 -0000 1.3 --- Adapdev.Cache.Tests.csproj 25 May 2005 05:17:46 -0000 1.4 *************** *** 95,98 **** --- 95,103 ---- HintPath = "..\..\lib\log4net.dll" /> + <Reference + Name = "Adapdev" + Project = "{CC30A321-2569-4B1F-8E1A-781B5509B56D}" + Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" + /> </References> </Build> *************** *** 100,103 **** --- 105,113 ---- <Include> <File + RelPath = "AbstractICacheTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "AdapdevAssemblyInfo.cs" Link = "..\AdapdevAssemblyInfo.cs" *************** *** 105,108 **** --- 115,163 ---- BuildAction = "Compile" /> + <File + RelPath = "CacheManagerTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CacheUtilTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "FileCacheTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "ImmutableInMemoryCache.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "MutableInMemoryCacheTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Scavengers\AbsoluteExpirationScavengerTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Scavengers\BaseScavengerTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Scavengers\GreaterThanOrdinalScavengerTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Scavengers\SlidingExpirationScavengerTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> --- NEW FILE: FileCacheTest.cs --- using System; using NUnit.Framework; using Adapdev.Cache; using Adapdev.Mock; namespace Adapdev.Tests.Cache { /// <summary> /// Summary description for MutableInMemoryCache. /// </summary> /// [TestFixture] public class FileCacheTest : AbstractICacheTest { public override ICache GetCache() { return new FileCache(); } [Test] public void Immutable() { SuppliersEntity e1 = new SuppliersEntity(); e1.SupplierID = 12; cache.Add(e1.SupplierID, e1); SuppliersEntity e2 = cache.Get(typeof(SuppliersEntity), 12) as SuppliersEntity; e2.SupplierID = 13; Assert.IsTrue(cache.Contains(e1.GetType(), 12), "Cache key should not change."); SuppliersEntity e3 = cache.Get(typeof(SuppliersEntity), 12) as SuppliersEntity; Assert.IsFalse(13 == e3.SupplierID, "Object in cache should NOT have been updated."); } } } --- NEW FILE: ImmutableInMemoryCache.cs --- using System; using NUnit.Framework; using Adapdev.Cache; using Adapdev.Mock; namespace Adapdev.Tests.Cache { /// <summary> /// Summary description for MutableInMemoryCache. /// </summary> /// [TestFixture] public class ImmutableInMemoryCacheTest : AbstractICacheTest { public override ICache GetCache() { return new ImmutableInMemoryCache(); } [Test] public void Immutable() { SuppliersEntity e1 = new SuppliersEntity(); e1.SupplierID = 12; cache.Add(e1.SupplierID, e1); SuppliersEntity e2 = cache.Get(typeof(SuppliersEntity), 12) as SuppliersEntity; e2.SupplierID = 13; Assert.IsTrue(cache.Contains(e1.GetType(), 12), "Cache key should not change."); SuppliersEntity e3 = cache.Get(typeof(SuppliersEntity), 12) as SuppliersEntity; Assert.IsFalse(13 == e3.SupplierID, "Object in cache should NOT have been updated."); } } } --- NEW FILE: CacheUtilTest.cs --- using System; using NUnit.Framework; using Adapdev.Cache; using Adapdev.Mock; namespace Adapdev.Tests.Cache { /// <summary> /// Summary description for CacheManagerTest. /// </summary> /// [TestFixture] public class CacheUtilTest { [Test] public void Copy() { ICache source = new MutableInMemoryCache(); ICache target = new FileCache(); for(int i = 0; i < 100; i++) { source.Add(i, new SuppliersEntity()); } CacheUtil.Copy(source, target); Assert.AreEqual(100, source.Count); Assert.AreEqual(100, target.Count, "Cache items were not copied over."); } } } |