public void AttemptedRemovalOfANonExistentKeyWillBeIgnored() { const string key = "Adult1"; _updater.Remove(key); IChangeSet <Person, string> updates = _updater.AsChangeSet(); Assert.AreEqual(0, _cache.Count); Assert.AreEqual(0, updates.Count, "Should be 0 updates"); }
private IChangeSet <TObject, TKey> UpdateCombined(IChangeSet <TObject, TKey> updates) { //child caches have been updated before we reached this point. var updater = new IntermediateUpdater <TObject, TKey>(_combinedCache); foreach (var update in updates) { TKey key = update.Key; switch (update.Reason) { case ChangeReason.Add: case ChangeReason.Update: { // get the current key. //check whether the item should belong to the cache Optional <TObject> cached = updater.Lookup(key); bool contained = cached.HasValue; bool match = MatchesConstraint(key); if (match) { if (contained) { if (!ReferenceEquals(update.Current, cached.Value)) { updater.AddOrUpdate(update.Current, key); } } else { updater.AddOrUpdate(update.Current, key); } } else { if (contained) { updater.Remove(key); } } } break; case ChangeReason.Remove: { var cached = updater.Lookup(key); var contained = cached.HasValue; bool shouldBeIncluded = MatchesConstraint(key); if (shouldBeIncluded) { var firstOne = _sourceCaches.Select(s => s.Lookup(key)) .SelectValues() .First(); if (!cached.HasValue) { updater.AddOrUpdate(firstOne, key); } else if (!ReferenceEquals(firstOne, cached.Value)) { updater.AddOrUpdate(firstOne, key); } } else { if (contained) { updater.Remove(key); } } } break; case ChangeReason.Evaluate: { updater.Evaluate(key); } break; } } return(updater.AsChangeSet()); // } // return up }