Пример #1
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);
        }
Пример #2
0
        public void WhenConstructing()
        {
            var backingStoreMock = new Mock <IBackingStore <string, int> >();
            var cache            = new UnboundedCache <string, int>(backingStoreMock.Object);

            Assert.NotNull(cache);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        public SourceSelector(int number, Orientation orientation = Orientation.Horizontal) : this()
        {
            selectorNumber = number;

            if (ButtonCaches[selectorNumber] == null)
            {
                ButtonCaches[selectorNumber] = new UnboundedCache <ContentControl>(CreateSourceIcon);
            }

            string key = "DuplicateHider_IconStackPanelStyle".Suffix(number);

            if (DuplicateHiderPlugin.API.Resources.
                GetResource(key) is Style style && style.TargetType == typeof(StackPanel))
            {
                IconStackPanel.SetResourceReference(StackPanel.StyleProperty, key);
            }
Пример #6
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);
        }