public void Test_OnRelationshipChange() { CacheInvalidator <int, string> cacheInvalidator; ICache <int, string> cache; EntityRef[] testRelationshipTypes; const int numRelationshipTypes = 10; Func <long, bool> relationshipTypesToRemove; cache = new DictionaryCache <int, string>(); for (int i = 0; i < numRelationshipTypes; i++) { cache.Add(i, i.ToString()); } relationshipTypesToRemove = e => e % 2 == 0; // All even numbered relationship types. testRelationshipTypes = Enumerable.Range(0, numRelationshipTypes) .Where(i => relationshipTypesToRemove(i)) .Select(i => new EntityRef(i)).ToArray(); cacheInvalidator = new CacheInvalidator <int, string>(cache, "a"); for (int i = 0; i < numRelationshipTypes; i++) { using (CacheContext cacheContext = new CacheContext()) { cacheContext.RelationshipTypes.Add(i); cacheInvalidator.AddInvalidations(cacheContext, i); } } cacheInvalidator.OnRelationshipChange(testRelationshipTypes); Assert.That(cache.Where(ce => relationshipTypesToRemove(ce.Key)), Is.Empty); }
public void Test_OnRelationshipChange_RelationshipTypesContainsNull() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnRelationshipChange(new EntityRef[] { null }), Throws.ArgumentException.And.Property("ParamName").EqualTo("relationshipTypes")); }
public void Test_OnRelationshipChange_NullRelationshipTypes() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnRelationshipChange(null), Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("relationshipTypes")); }