public void AppFabricCacheProviderGetOrCreateCacheWithExpirationTest() { AppFabricCacheProvider.AppFabricCacheProvider target = AppFabricCacheProvider.AppFabricCacheProvider.GetInstance(); IQueryable <Product> query = null; using (ProductContext context = new ProductContext()) { query = context.Products.OrderBy(one => one.ProductNumber).Where(one => one.IsActive); target.RemoveFromCache <Product>(query); TimeSpan cacheDuration = TimeSpan.FromSeconds(3); var actual = target.GetOrCreateCache <Product>(query, cacheDuration); Assert.AreEqual(2, actual.Count(), "Should have 2 rows"); SQLCommandHelper.ExecuteNonQuery("Update Products Set IsActive = 0"); actual = target.GetOrCreateCache <Product>(query, cacheDuration); Assert.AreEqual(2, actual.Count(), "Should have 2 rows"); Thread.Sleep(4000); actual = target.GetOrCreateCache <Product>(query, cacheDuration); Assert.AreEqual(0, actual.Count(), "Should have 0 rows"); target.RemoveFromCache <Product>(query); } }