public async Task ReadAllUpdatesIndividualItems() { AutoCacheOptions.SaveCollections = true; AutoCacheOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(10); _autoCache = new CrudAutoCache <string, Guid>(_storage, item => ToGuid(item, 1), Cache, null, AutoCacheOptions); var id1 = ToGuid("A1", 1); await PrepareStorageAndCacheAsync(id1, "A1", null); var id2 = ToGuid("B1", 1); await PrepareStorageAndCacheAsync(id2, "B1", null); var result = await _autoCache.ReadAllAsync(); Assert.IsNotNull(result); await _autoCache.DelayUntilNoOperationActiveAsync(); await VerifyAsync(id1, "A1"); await VerifyAsync(id2, "B1"); }
public async Task ReadAll() { AutoCacheOptions.SaveCollections = true; AutoCacheOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(10); _autoCache = new CrudAutoCache <string, Guid>(_storage, item => ToGuid(item, 1), Cache, null, AutoCacheOptions); var id1 = ToGuid("A1", 1); await PrepareStorageAndCacheAsync(id1, "A1", null); var id2 = ToGuid("B1", 1); await PrepareStorageAndCacheAsync(id2, "B1", null); var result = await _autoCache.ReadAllAsync(); Assert.IsNotNull(result); var enumerable = result as string[] ?? result.ToArray(); Assert.AreEqual(2, enumerable.Length); Assert.IsTrue(enumerable.Contains("A1")); Assert.IsTrue(enumerable.Contains("B1")); await _autoCache.DelayUntilNoOperationActiveAsync(); await _storage.UpdateAsync(id1, "A2"); await _storage.UpdateAsync(id2, "B2"); // Even though the items have been updated, the result will be fetched from the cache. result = await _autoCache.ReadAllAsync(); Assert.IsNotNull(result); enumerable = result as string[] ?? result.ToArray(); Assert.AreEqual(2, enumerable.Length); Assert.IsTrue(enumerable.Contains("A1"), "Missing A1 in " + string.Join(", ", enumerable)); Assert.IsTrue(enumerable.Contains("B1"), "Missing B1 in " + string.Join(", ", enumerable)); }