/// <summary> /// Removes the specified <paramref name="key"/> from the <paramref name="cache" />. /// </summary> /// <param name="cache">The cache to use.</param> /// <param name="key">The key to remove.</param> /// <param name="scheduler">Scheduler to perform the remove action on.</param> /// <returns> /// An observable stream that indicates whether the <paramref name="key"/> was removed successfully. /// </returns> /// <remarks> /// The returned observable stream of [true] or [false] indicates whether the <paramref name="key"/> was removed successfully. /// </remarks> public static IObservable <bool> Remove <TKey, TValue>(this IObservableCache <TKey, TValue> cache, TKey key, IScheduler scheduler = null) { if (cache == null) { throw new ArgumentNullException(nameof(cache)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } return(cache.Remove(Observable.Return(key), scheduler)); }
public void ConverterObservableCacheTests() { IObservableCache cache = InstantiateCache(); IConverter cDown = new ConvertDown(); IConverter cUp = new ConvertUp(); TestCacheListener listener = new TestCacheListener(); IObservableCache convCache = ConverterCollections.GetObservableCache(cache, cUp, cDown, cUp, cDown); Assert.IsNotNull(convCache); //AddCacheListener(listener) convCache.AddCacheListener(listener); Assert.AreEqual(listener.inserted, 0); convCache.Add(1, 1); Assert.AreEqual(listener.inserted, 1); Assert.AreEqual(listener.updated, 0); convCache[1] = 2; Assert.AreEqual(listener.updated, 1); Assert.AreEqual(listener.deleted, 0); convCache.Remove(1); Assert.AreEqual(listener.deleted, 1); //RemoveCacheListener(listener) convCache.RemoveCacheListener(listener); Assert.AreEqual(listener.inserted, 1); convCache.Add(1, 1); Assert.AreEqual(listener.inserted, 1); listener.inserted = listener.updated = listener.deleted = 0; convCache.Clear(); //AddCacheListener(listener, key, isLite); convCache.AddCacheListener(listener, "1", true); for (int i = 0; i < 3; i++) { convCache.Add(i, i); } Assert.AreEqual(listener.inserted, 1); Assert.AreEqual(listener.updated, 0); Assert.AreEqual(listener.deleted, 0); for (int i = 0; i < 3; i++) { convCache[i] = i + 1; } Assert.AreEqual(listener.inserted, 1); Assert.AreEqual(listener.updated, 1); Assert.AreEqual(listener.deleted, 0); convCache.Clear(); Assert.AreEqual(listener.inserted, 1); Assert.AreEqual(listener.updated, 1); Assert.AreEqual(listener.deleted, 1); //RemoveCacheListener(listener, key) convCache.RemoveCacheListener(listener, "1"); convCache.Add(1, 1); Assert.AreEqual(listener.inserted, 1); listener.inserted = listener.updated = listener.deleted = 0; convCache.Clear(); IFilter filter = AlwaysFilter.Instance; //AddCacheListener(listener, filter, isLite) convCache.AddCacheListener(listener, filter, true); for (int i = 0; i < 3; i++) { convCache.Add(i, i); } Assert.AreEqual(listener.inserted, 3); Assert.AreEqual(listener.updated, 0); Assert.AreEqual(listener.deleted, 0); for (int i = 0; i < 3; i++) { convCache[i] = i + 1; } Assert.AreEqual(listener.inserted, 3); Assert.AreEqual(listener.updated, 3); Assert.AreEqual(listener.deleted, 0); convCache.Clear(); Assert.AreEqual(listener.inserted, 3); Assert.AreEqual(listener.updated, 3); Assert.AreEqual(listener.deleted, 3); //RemoveCacheListener(listener, filter) convCache.RemoveCacheListener(listener, filter); convCache.Add(1, 1); Assert.AreEqual(listener.inserted, 3); Assert.IsInstanceOf(typeof(ConverterCollections.ConverterObservableCache), convCache); ConverterCollections.ConverterObservableCache coc = convCache as ConverterCollections.ConverterObservableCache; Assert.IsNotNull(coc); Assert.AreEqual(coc.ObservableCache, cache); }