public void UpdateCacheEntryOptions_DefaultsTo30SecondsSliding_IfNoEvictionCriteriaIsProvided() { // Arrange var slidingExpiresIn = TimeSpan.FromSeconds(30); var cache = new MemoryCache(new MemoryCacheOptions()); var cacheTagHelper = new CacheTagHelper(new CacheTagHelperMemoryCacheFactory(cache), new HtmlTestEncoder()); // Act var cacheEntryOptions = cacheTagHelper.GetMemoryCacheEntryOptions(); // Assert Assert.Equal(slidingExpiresIn, cacheEntryOptions.SlidingExpiration); }
public void UpdateCacheEntryOptions_SetsCachePreservationPriority() { // Arrange var priority = CacheItemPriority.High; var cache = new MemoryCache(new MemoryCacheOptions()); var cacheTagHelper = new CacheTagHelper(new CacheTagHelperMemoryCacheFactory(cache), new HtmlTestEncoder()) { Priority = priority }; // Act var cacheEntryOptions = cacheTagHelper.GetMemoryCacheEntryOptions(); // Assert Assert.Equal(priority, cacheEntryOptions.Priority); }
public void UpdateCacheEntryOptions_SetsSlidingExpiration_IfExpiresSlidingIsSet() { // Arrange var expiresSliding = TimeSpan.FromSeconds(37); var cache = new MemoryCache(new MemoryCacheOptions()); var cacheTagHelper = new CacheTagHelper(new CacheTagHelperMemoryCacheFactory(cache), new HtmlTestEncoder()) { ExpiresSliding = expiresSliding }; // Act var cacheEntryOptions = cacheTagHelper.GetMemoryCacheEntryOptions(); // Assert Assert.Equal(expiresSliding, cacheEntryOptions.SlidingExpiration); }
public void UpdateCacheEntryOptions_SetsAbsoluteExpiration_IfExpiresAfterIsSet() { // Arrange var expiresAfter = TimeSpan.FromSeconds(42); var cache = new MemoryCache(new MemoryCacheOptions()); var cacheTagHelper = new CacheTagHelper(new CacheTagHelperMemoryCacheFactory(cache), new HtmlTestEncoder()) { ExpiresAfter = expiresAfter }; // Act var cacheEntryOptions = cacheTagHelper.GetMemoryCacheEntryOptions(); // Assert Assert.Equal(expiresAfter, cacheEntryOptions.AbsoluteExpirationRelativeToNow); }
public void UpdateCacheEntryOptions_SetsAbsoluteExpiration_IfExpiresOnIsSet() { // Arrange var expiresOn = DateTimeOffset.UtcNow.AddMinutes(4); var cache = new MemoryCache(new MemoryCacheOptions()); var cacheTagHelper = new CacheTagHelper(new CacheTagHelperMemoryCacheFactory(cache), new HtmlTestEncoder()) { ExpiresOn = expiresOn }; // Act var cacheEntryOptions = cacheTagHelper.GetMemoryCacheEntryOptions(); // Assert Assert.Equal(expiresOn, cacheEntryOptions.AbsoluteExpiration); }