Beispiel #1
0
        public void WhenEvictKeyAsync()
        {
            var backingStoreMock = new Mock <IBackingStore <string, int> >();
            var cache            = new UnboundedCache <string, int>(backingStoreMock.Object, new CurrentThreadTaskScheduler());
            var evicted          = false;

            cache.KeyEvicted += (s, a) => evicted = a.Key == Key;
            cache.SetValueAsync(Key, 3);
            Assert.True(cache.ContainsKeyInCacheAsync(Key).Result);

            var task = cache.EvictKeyAsync(Key);

            Assert.False(task.IsFaulted);
            Assert.False(cache.ContainsKeyInCacheAsync(Key).Result);
            Assert.True(evicted);
        }
Beispiel #2
0
        public void WhenContainsKeyInCacheAsyncMissingKey()
        {
            var backingStoreMock = new Mock <IBackingStore <string, int> >();
            var cache            = new UnboundedCache <string, int>(backingStoreMock.Object, new CurrentThreadTaskScheduler());

            Assert.False(cache.ContainsKeyInCacheAsync(Key).Result);
        }
Beispiel #3
0
        public void WhenRemoveKeyAsyncNotInCache()
        {
            var backingStoreMock = new Mock <IBackingStore <string, int> >();
            var cache            = new UnboundedCache <string, int>(backingStoreMock.Object, new CurrentThreadTaskScheduler());
            var evicted          = false;

            cache.KeyEvicted += (s, a) => evicted = a.Key == Key;
            Assert.False(cache.ContainsKeyInCacheAsync(Key).Result);

            var task = cache.RemoveKeyAsync(Key);

            backingStoreMock.Verify(f => f.RemoveKey(Key), Times.Once);
            Assert.False(task.IsFaulted);
            Assert.False(cache.ContainsKeyInCacheAsync(Key).Result);
            Assert.False(cache.ContainsKeyAsync(Key).Result);
            Assert.False(evicted);
        }
Beispiel #4
0
        public void WhenSetValueAsync()
        {
            var backingStoreMock = new Mock <IBackingStore <string, int> >();
            var cache            = new UnboundedCache <string, int>(backingStoreMock.Object, new CurrentThreadTaskScheduler());

            cache.SetValueAsync(Key, 3);
            Assert.True(cache.ContainsKeyInCacheAsync(Key).Result);
            backingStoreMock.Verify(f => f.SetValue(Key, 3), Times.Once);
        }