public void TestTransform() { ExtractorEventTransformer transformer = new ExtractorEventTransformer(null, IdentityExtractor.Instance); LocalCache cache = new LocalCache(); CacheEventArgs evt = new CacheEventArgs(cache, CacheEventType.Inserted, "inserted", "old value", "new value", false); CacheEventArgs evtNew = transformer.Transform(evt); Assert.IsNotNull(evtNew); Assert.AreEqual(evt.Cache, evtNew.Cache); Assert.AreEqual(evt.EventType, evtNew.EventType); Assert.AreEqual(evt.Key, evtNew.Key); Assert.AreNotEqual(evt.OldValue, evtNew.OldValue); Assert.IsNotNull(evt.OldValue); Assert.IsNull(evtNew.OldValue); Assert.AreEqual(evt.NewValue, evtNew.NewValue); Assert.AreEqual(evt.IsSynthetic, evtNew.IsSynthetic); evt = ConverterCollections.GetCacheEventArgs(cache, evt, NullImplementation.GetConverter(), NullImplementation.GetConverter()); Assert.IsNotNull(evt); Assert.IsInstanceOf(typeof(ConverterCollections.ConverterCacheEventArgs), evt); ConverterCollections.ConverterCacheEventArgs convEvt = evt as ConverterCollections.ConverterCacheEventArgs; Assert.IsNotNull(convEvt); evtNew = transformer.Transform(convEvt); Assert.IsNotNull(evtNew); }
public void ConverterCacheEventArgsTests() { IObservableCache cache = InstantiateCache(); IObservableCache newCache = InstantiateCache(); IConverter cDown = new ConvertDown(); IConverter cUp = new ConvertUp(); CacheEventArgs evt = new CacheEventArgs(cache, CacheEventType.Inserted, cDown.Convert("key"), cDown.Convert("valueOld"), cDown.Convert("valueNew"), false); CacheEventArgs convEvt = ConverterCollections.GetCacheEventArgs(newCache, evt, cUp, cUp); Assert.IsNotNull(convEvt); Assert.AreEqual(convEvt.Cache, newCache); Assert.IsFalse(convEvt.Cache.Equals(evt.Cache)); Assert.AreEqual(convEvt.EventType, evt.EventType); Assert.AreEqual(convEvt.IsSynthetic, evt.IsSynthetic); Assert.AreEqual(convEvt.OldValue, cUp.Convert(evt.OldValue)); Assert.AreEqual(convEvt.NewValue, cUp.Convert(evt.NewValue)); Assert.AreEqual(convEvt.Key, cUp.Convert(evt.Key)); Assert.IsInstanceOf(typeof(ConverterCollections.ConverterCacheEventArgs), convEvt); ConverterCollections.ConverterCacheEventArgs ccea = convEvt as ConverterCollections.ConverterCacheEventArgs; Assert.IsNotNull(ccea); Assert.AreEqual(ccea.CacheEvent, evt); Assert.AreEqual(ccea.ConverterKeyUp, cUp); Assert.AreEqual(ccea.ConverterValueUp, cUp); }
/// <summary> /// Transform the specified <see cref="CacheEventArgs"/>. /// </summary> /// <remarks> /// The values contained by the returned <b>CacheEventArgs</b> object /// will be the ones given (sent) to the corresponding listener. /// </remarks> /// <param name="evt"> /// The original <b>CacheEventArgs</b> object. /// </param> /// <returns> /// Modified <b>CacheEventArgs</b> object or <c>null</c> to discard /// the event. /// </returns> public virtual CacheEventArgs Transform(CacheEventArgs evt) { if (evt is ConverterCollections.ConverterCacheEventArgs) { ConverterCollections.ConverterCacheEventArgs evtConv = (ConverterCollections.ConverterCacheEventArgs)evt; CacheEventArgs evtOrig = evtConv.CacheEvent; return(ConverterCollections.GetCacheEventArgs(evtConv.Cache, new CacheEventArgs(evtOrig.Cache, evtOrig.EventType, evtOrig.Key, null, evtOrig.NewValue, evt.IsSynthetic, evt.IsPriming), evtConv.ConverterKeyUp, evtConv.ConverterValueUp)); } else { return(new CacheEventArgs(evt.Cache, evt.EventType, evt.Key, null, evt.NewValue, evt.IsSynthetic, evt.IsPriming)); } }
public void ConverterCacheListenerTests() { TestCacheListener listener = new TestCacheListener(); IObservableCache cache = InstantiateCache(); IConverter cUp = new ConvertUp(); CacheEventArgs evt = new CacheEventArgs(cache, CacheEventType.Inserted, "key", "oldvalue", "newvalue", false); ConverterCollections.ConverterCacheEventArgs convEvt = (ConverterCollections.ConverterCacheEventArgs)ConverterCollections.GetCacheEventArgs(cache, evt, cUp, cUp); ICacheListener convListener = new ConverterCollections.ConverterCacheListener(cache, listener, cUp, cUp); Assert.IsNotNull(convListener); Assert.AreEqual(listener.inserted, 0); convListener.EntryInserted(evt); Assert.AreEqual(listener.inserted, 1); Assert.IsNotNull(listener.evt); CacheEventArgs listenerEvt = listener.evt; Assert.AreEqual(listenerEvt.Cache, convEvt.Cache); Assert.AreEqual(listenerEvt.EventType, convEvt.EventType); Assert.AreEqual(listenerEvt.IsSynthetic, convEvt.IsSynthetic); Assert.AreEqual(listenerEvt.Key, convEvt.Key); Assert.AreEqual(listenerEvt.NewValue, convEvt.NewValue); Assert.AreEqual(listenerEvt.OldValue, convEvt.OldValue); Assert.AreEqual(listener.updated, 0); convListener.EntryUpdated(evt); Assert.AreEqual(listener.updated, 1); Assert.AreEqual(listener.deleted, 0); convListener.EntryDeleted(evt); Assert.AreEqual(listener.deleted, 1); Assert.IsInstanceOf(typeof(ConverterCollections.ConverterCacheListener), convListener); ConverterCollections.ConverterCacheListener ccl = convListener as ConverterCollections.ConverterCacheListener; Assert.IsNotNull(ccl); Assert.AreEqual(ccl.CacheListener, listener); Assert.AreEqual(ccl.ConverterKeyUp, cUp); Assert.AreEqual(ccl.ConverterValueUp, cUp); Assert.AreEqual(ccl.ObservableCache, cache); }