public async Task StoreManyTest() { string category = "Test category"; var cacheItems = new[] { new CacheItem <int>(category, "test", 42, DateTime.Now.AddMinutes(30)), new CacheItem <int>(category, "test2", 84, DateTime.Now.AddMinutes(30)), new CacheItem <int>(category, "test3", 168, DateTime.Now.AddMinutes(30)) }; await this.cacheMethod.SetManyAsync(cacheItems); await AssertAsync.All(cacheItems.Select(async i => await this.cacheMethod.TryGetAsync <int>(i.Category, i.Id) != null), Assert.True); Assert.Equal(cacheItems, (await this.cacheMethod.GetManyAsync <int>(category, cacheItems.Select(x => x.Id))).Select(x => x.Value)); }
public async Task GetManyWithoutExpiredTest() { string category = "Test category"; var cacheItems = new[] { new CacheItem <int>(category, "test", 42, DateTime.Now.AddMinutes(30)), new CacheItem <int>(category, "test2", 84, DateTime.Now.AddMilliseconds(1750)) }; await this.cacheMethod.SetManyAsync(cacheItems); await AssertAsync.All(cacheItems.Select(async i => await this.cacheMethod.TryGetAsync <int>(i.Category, i.Id) != null), Assert.True); await Task.Delay(2000); Assert.Equal(cacheItems.Where(i => i.ExpiryTime > DateTime.Now), (await this.cacheMethod.GetManyAsync <int>(category, cacheItems.Select(x => x.Id))).Select(x => x.Value)); }
public async Task GetOrUpdateManyTest() { string category = "Test category"; var date = DateTime.Now.AddMinutes(30); var cacheItems = new[] { new CacheItem <int>(category, "test", 42, date), new CacheItem <int>(category, "test2", 84, date), new CacheItem <int>(category, "test3", 168, date) }; await this.cacheMethod.GetOrUpdateManyAsync(category, cacheItems.Select(x => x.Id), date, missingIds => { Assert.Equal(cacheItems.Select(x => x.Id), missingIds); return(Task.FromResult <IDictionary <string, int> >(cacheItems.ToDictionary(x => x.Id, x => x.Item))); }); await AssertAsync.All(cacheItems.Select(async i => await this.cacheMethod.TryGetAsync <int>(i.Category, i.Id) != null), Assert.True); Assert.Equal(cacheItems, (await this.cacheMethod.GetManyAsync <int>(category, cacheItems.Select(x => x.Id))).Select(x => x.Value)); }