[Adapdev-commits] Adapdev/src/Adapdev.Cache.Tests AbstractICacheTest.cs,1.5,1.6 Adapdev.Cache.Tests.
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 07:01:56
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Cache.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.Cache.Tests Added Files: AbstractICacheTest.cs Adapdev.Cache.Tests.csproj CacheManagerTest.cs CacheStatsTest.cs CacheUtilTest.cs FileCacheTest.cs ImmutableInMemoryCache.cs MutableInMemoryCacheTest.cs Log Message: --- 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 virtual 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: 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: 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."); } } } --- 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."); } [Test] public void SetCache() { Assert.AreEqual(typeof(ImmutableInMemoryCache), CacheManager.Cache.GetType()); CacheManager.Cache.Add(1, new SuppliersEntity()); Assert.AreEqual(1, CacheManager.Cache.Count); CacheManager.SetCache(CacheType.MutableInMemory); Assert.AreEqual(1, CacheManager.Cache.Count, "Cache has switched BUT should have been copied, so count should be 1."); CacheManager.SetCache(CacheType.ImmutableInMemory, false); Assert.AreEqual(0, CacheManager.Cache.Count, "Cache has switched BUT should not have been copied, so count should be 0."); } } } --- NEW FILE: CacheStatsTest.cs --- using System; namespace Adapdev.Cache.Tests { using Adapdev.Mock; using Adapdev.Tests.Cache; using NUnit.Framework; /// <summary> /// Summary description for CacheStatsTest. /// </summary> /// [TestFixture] public class CacheStatsTest : AbstractICacheTest { public override ICache GetCache() { return new CacheStats(new ImmutableInMemoryCache()); } [Test] public void Stats() { this.cache.Add(1, new SuppliersEntity()); object o = this.cache.Get(typeof(SuppliersEntity), 1); Assert.IsNotNull(o, "Object came back as null"); CacheStats stats = this.cache as CacheStats; Assert.AreEqual(1, stats.HitCount, "HitCount is incorrect."); Assert.AreEqual(0, stats.MissCount, "MissCount is incorrect"); Assert.IsTrue(stats.InsertTime > 0, "InsertTime is incorrect."); Assert.IsTrue(stats.RetrieveTime > 0, "RetrieveTime is incorrect."); Console.WriteLine(stats); } } } --- 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."); } } } --- NEW FILE: Adapdev.Cache.Tests.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{D2D00D68-57F1-4CEA-B9E6-4E7FD7CE4E43}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "Adapdev.Cache.Tests" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "Adapdev.Cache.Tests" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "nunit.framework" AssemblyName = "nunit.framework" HintPath = "..\..\lib\nunit.framework.dll" /> <Reference Name = "Adapdev.Cache" Project = "{84F894AC-EFD7-4342-B2A5-CF3EF80E0B1C}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "log4net" AssemblyName = "log4net" HintPath = "..\..\lib\log4net.dll" /> <Reference Name = "Adapdev" Project = "{CC30A321-2569-4B1F-8E1A-781B5509B56D}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> </References> </Build> <Files> <Include> <File RelPath = "AbstractICacheTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "AdapdevAssemblyInfo.cs" Link = "..\AdapdevAssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CacheManagerTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CacheStatsTest.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> </CSHARP> </VisualStudioProject> --- 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."); } } } |