public void Remove() { int LCacheSize = 5; FTestCache = new FixedSizeCache <string, string>(LCacheSize); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); } int LTestKey = 3; FTestCache.Remove(GetKey(LTestKey)); Assert.False(FTestCache.ContainsKey(GetValue(LTestKey))); Assert.AreEqual(LCacheSize - 1, FTestCache.Count); LTestKey = 1; FTestCache.Remove(GetKey(LTestKey)); Assert.False(FTestCache.ContainsKey(GetValue(LTestKey))); Assert.AreEqual(LCacheSize - 2, FTestCache.Count); LTestKey = 5; FTestCache.Remove(GetKey(LTestKey)); Assert.False(FTestCache.ContainsKey(GetValue(LTestKey))); Assert.AreEqual(LCacheSize - 3, FTestCache.Count); Assert.True(ValidateList()); }
public void ContainsKey() { int LCacheSize = 5; int LTestCacheItem = 3; FTestCache = new FixedSizeCache <string, string>(LCacheSize); Assert.False(FTestCache.ContainsKey(GetKey(LTestCacheItem))); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); } Assert.True(FTestCache.ContainsKey(GetKey(LTestCacheItem))); FTestCache.Clear(); Assert.False(FTestCache.ContainsKey(GetKey(LTestCacheItem))); Assert.True(ValidateList()); }
public void Add() { int LCacheSize = 5; FTestCache = new FixedSizeCache <string, string>(LCacheSize); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); Assert.AreEqual(i, FTestCache.Count); Assert.AreEqual(FTestCache[GetKey(i)], GetValue(i)); Assert.True(FTestCache.ContainsKey(GetKey(i))); Assert.True(ValidateCutoff()); } Assert.AreEqual(5, FTestCache.Count); FTestCache.Add(GetKey(FTestCache.Size + 1), GetValue(FTestCache.Size + 1)); Assert.AreEqual(LCacheSize, FTestCache.Count); Assert.True(ValidateCutoff()); Assert.True(ValidateList()); }
public void Reference() { string LReference = null; int LCacheSize = 2; FTestCache = new FixedSizeCache <string, string>(LCacheSize); for (int i = 1; i <= FTestCache.Size; i++) { LReference = FTestCache.Reference(GetKey(i), GetValue(i)); Assert.AreEqual(i, FTestCache.Count); Assert.True(FTestCache.ContainsKey(GetKey(i))); Assert.AreEqual(FTestCache[GetKey(i)], GetValue(i)); Assert.IsNull(LReference); } Assert.AreEqual(LCacheSize, FTestCache.Count); LReference = FTestCache.Reference(GetKey(1), GetValue(1)); Assert.IsNull(LReference); LReference = null; LCacheSize = 5; FTestCache = new FixedSizeCache <string, string>(LCacheSize); for (int i = 1; i <= FTestCache.Size; i++) { LReference = FTestCache.Reference(GetKey(i), GetValue(i)); Assert.AreEqual(i, FTestCache.Count); Assert.True(FTestCache.ContainsKey(GetKey(i))); Assert.AreEqual(FTestCache[GetKey(i)], GetValue(i)); Assert.IsNull(LReference); } Assert.AreEqual(LCacheSize, FTestCache.Count); LReference = FTestCache.Reference(GetKey(FTestCache.Size + 1), GetValue(FTestCache.Size + 1)); Assert.AreEqual(LCacheSize, FTestCache.Count); Assert.IsNotNull(LReference); Assert.True(ValidateList()); }