Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
    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);
    }
Ejemplo n.º 5
0
    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);
    }