public void SystemCache_Clear() { var key = "absCacheKey"; var cache = new SystemCache(); long count = cache.Count; Random rnd = new Random(DateTime.Now.Millisecond); for (int i = 1; i <= 1000; i++) { var dummy = new DummyObject() { Id = rnd.Next(10001, 99999), Name = "for test" }; cache.Add($"item-{i}", dummy); } var newCount = cache.Count; Assert.True(newCount - 1000 == count); cache.Clear(); Assert.True(cache.Count == 0); }
public void SystemCache_TestExpirationDate() { var key = "absCacheKey"; var cache = new SystemCache(); var dummy = new DummyObject() { Id = 2 }; cache.Add(key, dummy, DateTime.Now.AddSeconds(5)); Thread.Sleep(2000); var o = cache.GetData <DummyObject>(key); Assert.True(o != null); Assert.IsType(typeof(DummyObject), o); Thread.Sleep(3001); o = cache.GetData <DummyObject>(key); Assert.True(o == null); }
public void SystemCache_TestSelfReferenceObject() { var key = "selfrefCacheKey"; var cache = new SystemCache(); var datString = new DATString() { DATStringId = 1, Name = "test", Source = "DAT", Type = "SA" }; datString.Equipments = new List <Equipment>(); datString.Equipments.Add(new Equipment() { DATStrings = new HashSet <DATString>() { datString } }); cache.Add(key, datString); var ob = cache.GetData <DATString>(key); Assert.NotNull(ob); }
public void SystemCache_TestSliding() { var key = "slidingCacheKey"; var cache = new SystemCache(); var dummy = new DummyObject() { Id = 1 }; cache.Add(key, dummy, TimeSpan.FromSeconds(2)); Thread.Sleep(500); for (int i = 0; i < 3; i++) { var o = cache.GetData <DummyObject>(key); Assert.True(o != null, string.Format("failed on {0} iteration", i)); Thread.Sleep(500); } Thread.Sleep(2001); var ob = cache.GetData(key); Assert.True(ob == null); }
public void SystemCache_StringValueTest() { var key = "test-string"; var cache = new SystemCache(); // var dummy = new DummyObject() { Id = 1 }; cache.Add(key, "La la la"); Thread.Sleep(500); var o = cache.GetData(key); Assert.True(o != null, "failed on {0} iteration"); Assert.Equal(o, "La la la"); string str = cache.GetData <string>(key); Assert.True(str != null, "failed on {0} iteration"); Assert.Equal(str, "La la la"); }
void VmRecievedSystemMessage(object sender, SystemMessageArgs e) { _systemCache.Add(e.Message); }