ln.collections/ln.collections.test/CacheTests.cs

46 lines
1.0 KiB
C#

using System;
using System.Threading;
using NUnit.Framework;
namespace ln.collections.test
{
[TestFixture]
public class CacheTests
{
[Test]
public void Test_Cache_1()
{
Cache<int, string> cache = new Cache<int, string>(TimeSpan.FromSeconds(1));
for (int n = 0; n < 10; n++)
cache.Add(n, n.ToString());
cache.Cleanup();
Assert.AreEqual(10, cache.Count);
Thread.Sleep(1000);
cache.Cleanup();
Assert.AreEqual(0, cache.Count);
for (int n = 0; n < 10; n++)
{
cache.Add(n, n.ToString());
Thread.Sleep(90);
}
Thread.Sleep(10);
for (int n = 10; n > 0; n--)
{
cache.Cleanup();
Assert.AreEqual(n, cache.Count);
Thread.Sleep(90);
}
Assert.Pass();
}
}
}