public async Task GetAllFromHash() { var key = "allhash"; var cache = new SystemCache(); cache.UpdateInHash <DummyObject>(key, "item1", new DummyObject() { Id = 1, Name = "test1" }); cache.UpdateInHash <DummyObject>(key, "item2", new DummyObject() { Id = 2, Name = "test2" }); var list = await cache.GetAllFromHash <DummyObject>(key); Assert.True(list.Count == 2); }
public void SystemCache_HashUpdate() { var key = "myhash"; var cache = new SystemCache(); cache.Clear(); Random rnd = new Random(DateTime.Now.Millisecond); var dict = new Dictionary <string, DummyObject>(); for (int i = 1; i <= 1000; i++) { var dummy = new DummyObject() { Id = i, Name = "for test" }; if (!dict.ContainsKey(dummy.Id.ToString())) { dict.Add(dummy.Id.ToString(), dummy); } } cache.AddToHash <DummyObject>(key, dict); var count = cache.HashCount(key); // get random List <string> keys = new List <string>(dict.Keys); var k = keys[rnd.Next(keys.Count)]; var obj = dict[k]; Assert.True(cache.ExistsInHash <DummyObject>(key, obj.Id.ToString())); var cachedObj = cache.GetFromHash <DummyObject>(key, obj.Id.ToString()); // update cachedObj.Name = "update"; // create change set dict // update cache.UpdateInHash <DummyObject>(key, cachedObj.Id.ToString(), cachedObj); var updatedObj = cache.GetFromHash <DummyObject>(key, obj.Id.ToString()); Assert.True(updatedObj.Name == "update"); var newcount = cache.HashCount(key); Assert.Equal(count, newcount); cache.Clear(); }