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); }
public void WhenConstructing() { var backingStoreMock = new Mock <IBackingStore <string, int> >(); var cache = new UnboundedCache <string, int>(backingStoreMock.Object); Assert.NotNull(cache); }
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); }
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); }
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); }
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); }