示例#1
0
        public void CachingReloadableEntry_Expiring_CallsCallbacks()
        {
            var config = InitConfig();

            config.ExpirationTime = TimeSpan.FromMilliseconds(0);
            var _cache = new InMemoryCache(config);

            var key             = "test_value";
            var key2            = "test_value2";
            var value           = new CachedModel();
            var reloadableEntry = new ReloadableCacheEntry(key, () => value);

            _cache.Set(reloadableEntry);

            _cache.OnExpire(entry =>
            {
                Assert.NotNull(entry);
                Assert.Equal(value, entry.Value);
            });

            _cache.OnExpire(key, entry =>
            {
                Assert.NotNull(entry);
                Assert.Equal(value, entry.Value);
            });

            // this @key2 does not exist so the callback should never be fired
            // Assert.True(false) is force failing the test
            _cache.OnExpire(key2, entry =>
            {
                Assert.True(false);
            });
        }